1 /* $NetBSD: bn.h,v 1.2 2017/01/28 21:31:47 christos Exp $ */ 2 3 /* 4 * Copyright (c) 2006-2016 Kungliga Tekniska Högskolan 5 * (Royal Institute of Technology, Stockholm, Sweden). 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * 3. Neither the name of the Institute nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 /* 37 * Id 38 */ 39 40 #ifndef _HEIM_BN_H 41 #define _HEIM_BN_H 1 42 43 /* symbol renaming */ 44 #define BN_GENCB_call hc_BN_GENCB_call 45 #define BN_GENCB_set hc_BN_GENCB_set 46 #define BN_bin2bn hc_BN_bin2bn 47 #define BN_bn2bin hc_BN_bn2bin 48 #define BN_bn2hex hc_BN_bn2hex 49 #define BN_clear hc_BN_clear 50 #define BN_clear_bit hc_BN_clear_bit 51 #define BN_clear_free hc_BN_clear_free 52 #define BN_cmp hc_BN_cmp 53 #define BN_dup hc_BN_dup 54 #define BN_free hc_BN_free 55 #define BN_is_negative hc_BN_is_negative 56 #define BN_get_word hc_BN_get_word 57 #define BN_hex2bn hc_BN_hex2bn 58 #define BN_is_bit_set hc_BN_is_bit_set 59 #define BN_new hc_BN_new 60 #define BN_num_bits hc_BN_num_bits 61 #define BN_num_bytes hc_BN_num_bytes 62 #define BN_rand hc_BN_rand 63 #define BN_set_bit hc_BN_set_bit 64 #define BN_set_negative hc_BN_set_negative 65 #define BN_set_word hc_BN_set_word 66 #define BN_uadd hc_BN_uadd 67 #define BN_CTX_new hc_BN_CTX_new 68 #define BN_CTX_free hc_BN_CTX_free 69 #define BN_CTX_get hc_BN_CTX_get 70 #define BN_CTX_start hc_BN_CTX_start 71 #define BN_CTX_end hc_BN_CTX_end 72 73 #define BIGNUM hc_BIGNUM 74 #define BN_GENCB hc_BN_GENCB 75 #define BN_CTX hc_BN_CTX 76 #define BN_BLINDING hc_BN_BLINDING 77 #define BN_MONT_CTX hc_BN_MONT_CTX 78 79 80 /* 81 * 82 */ 83 84 typedef struct BIGNUM BIGNUM; 85 typedef struct BN_GENCB BN_GENCB; 86 typedef struct BN_CTX BN_CTX; 87 typedef struct BN_MONT_CTX BN_MONT_CTX; 88 typedef struct BN_BLINDING BN_BLINDING; 89 90 struct BN_GENCB { 91 unsigned int ver; 92 void *arg; 93 union { 94 int (*cb_2)(int, int, BN_GENCB *); 95 } cb; 96 }; 97 98 /* 99 * 100 */ 101 102 BIGNUM *BN_new(void); 103 void BN_free(BIGNUM *); 104 void BN_clear_free(BIGNUM *); 105 void BN_clear(BIGNUM *); 106 BIGNUM *BN_dup(const BIGNUM *); 107 108 int BN_num_bits(const BIGNUM *); 109 int BN_num_bytes(const BIGNUM *); 110 111 int BN_cmp(const BIGNUM *, const BIGNUM *); 112 113 void BN_set_negative(BIGNUM *, int); 114 int BN_is_negative(const BIGNUM *); 115 116 int BN_is_bit_set(const BIGNUM *, int); 117 int BN_set_bit(BIGNUM *, int); 118 int BN_clear_bit(BIGNUM *, int); 119 120 int BN_set_word(BIGNUM *, unsigned long); 121 unsigned long BN_get_word(const BIGNUM *); 122 123 BIGNUM *BN_bin2bn(const void *,int len,BIGNUM *); 124 int BN_bn2bin(const BIGNUM *, void *); 125 int BN_hex2bn(BIGNUM **, const char *); 126 char * BN_bn2hex(const BIGNUM *); 127 128 int BN_uadd(BIGNUM *, const BIGNUM *, const BIGNUM *); 129 130 int BN_rand(BIGNUM *, int, int, int); 131 132 void BN_GENCB_set(BN_GENCB *, int (*)(int, int, BN_GENCB *), void *); 133 int BN_GENCB_call(BN_GENCB *, int, int); 134 135 BN_CTX *BN_CTX_new(void); 136 void BN_CTX_free(BN_CTX *); 137 BIGNUM *BN_CTX_get(BN_CTX *); 138 void BN_CTX_start(BN_CTX *); 139 void BN_CTX_end(BN_CTX *); 140 141 #endif 142