1 /* $OpenBSD: bn.h,v 1.78 2024/04/10 14:58:06 beck Exp $ */ 2 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * 9 * This library is free for commercial and non-commercial use as long as 10 * the following conditions are aheared to. The following conditions 11 * apply to all code found in this distribution, be it the RC4, RSA, 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 * included with this distribution is covered by the same copyright terms 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 * 16 * Copyright remains Eric Young's, and as such any Copyright notices in 17 * the code are not to be removed. 18 * If this package is used in a product, Eric Young should be given attribution 19 * as the author of the parts of the library used. 20 * This can be in the form of a textual message at program startup or 21 * in documentation (online or textual) provided with the package. 22 * 23 * Redistribution and use in source and binary forms, with or without 24 * modification, are permitted provided that the following conditions 25 * are met: 26 * 1. Redistributions of source code must retain the copyright 27 * notice, this list of conditions and the following disclaimer. 28 * 2. Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in the 30 * documentation and/or other materials provided with the distribution. 31 * 3. All advertising materials mentioning features or use of this software 32 * must display the following acknowledgement: 33 * "This product includes cryptographic software written by 34 * Eric Young (eay@cryptsoft.com)" 35 * The word 'cryptographic' can be left out if the rouines from the library 36 * being used are not cryptographic related :-). 37 * 4. If you include any Windows specific code (or a derivative thereof) from 38 * the apps directory (application code) you must include an acknowledgement: 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 * 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * 53 * The licence and distribution terms for any publically available version or 54 * derivative of this code cannot be changed. i.e. this code cannot simply be 55 * copied and put under another distribution licence 56 * [including the GNU Public Licence.] 57 */ 58 /* ==================================================================== 59 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. 60 * 61 * Redistribution and use in source and binary forms, with or without 62 * modification, are permitted provided that the following conditions 63 * are met: 64 * 65 * 1. Redistributions of source code must retain the above copyright 66 * notice, this list of conditions and the following disclaimer. 67 * 68 * 2. Redistributions in binary form must reproduce the above copyright 69 * notice, this list of conditions and the following disclaimer in 70 * the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3. All advertising materials mentioning features or use of this 74 * software must display the following acknowledgment: 75 * "This product includes software developed by the OpenSSL Project 76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 77 * 78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 79 * endorse or promote products derived from this software without 80 * prior written permission. For written permission, please contact 81 * openssl-core@openssl.org. 82 * 83 * 5. Products derived from this software may not be called "OpenSSL" 84 * nor may "OpenSSL" appear in their names without prior written 85 * permission of the OpenSSL Project. 86 * 87 * 6. Redistributions of any form whatsoever must retain the following 88 * acknowledgment: 89 * "This product includes software developed by the OpenSSL Project 90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 91 * 92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 103 * OF THE POSSIBILITY OF SUCH DAMAGE. 104 * ==================================================================== 105 * 106 * This product includes cryptographic software written by Eric Young 107 * (eay@cryptsoft.com). This product includes software written by Tim 108 * Hudson (tjh@cryptsoft.com). 109 * 110 */ 111 /* ==================================================================== 112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 113 * 114 * Portions of the attached software ("Contribution") are developed by 115 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. 116 * 117 * The Contribution is licensed pursuant to the Eric Young open source 118 * license provided above. 119 * 120 * The binary polynomial arithmetic software is originally written by 121 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. 122 * 123 */ 124 125 #ifndef HEADER_BN_H 126 #define HEADER_BN_H 127 128 #include <stdio.h> 129 #include <stdlib.h> 130 131 #include <openssl/opensslconf.h> 132 133 #include <openssl/ossl_typ.h> 134 #include <openssl/crypto.h> 135 #include <openssl/bio.h> 136 137 #ifdef __cplusplus 138 extern "C" { 139 #endif 140 141 /* This next option uses the C libraries (2 word)/(1 word) function. 142 * If it is not defined, I use my C version (which is slower). 143 * The reason for this flag is that when the particular C compiler 144 * library routine is used, and the library is linked with a different 145 * compiler, the library is missing. This mostly happens when the 146 * library is built with gcc and then linked using normal cc. This would 147 * be a common occurrence because gcc normally produces code that is 148 * 2 times faster than system compilers for the big number stuff. 149 * For machines with only one compiler (or shared libraries), this should 150 * be on. Again this in only really a problem on machines 151 * using "long long's", are 32bit, and are not using my assembler code. */ 152 /* #define BN_DIV2W */ 153 154 #ifdef _LP64 155 #undef BN_LLONG 156 #define BN_ULONG unsigned long 157 #define BN_LONG long 158 #define BN_BITS 128 159 #define BN_BYTES 8 160 #define BN_BITS2 64 161 #define BN_BITS4 32 162 #define BN_MASK2 (0xffffffffffffffffL) 163 #define BN_MASK2l (0xffffffffL) 164 #define BN_MASK2h (0xffffffff00000000L) 165 #define BN_MASK2h1 (0xffffffff80000000L) 166 #define BN_TBIT (0x8000000000000000L) 167 #define BN_DEC_CONV (10000000000000000000UL) 168 #define BN_DEC_FMT1 "%lu" 169 #define BN_DEC_FMT2 "%019lu" 170 #define BN_DEC_NUM 19 171 #define BN_HEX_FMT1 "%lX" 172 #define BN_HEX_FMT2 "%016lX" 173 #else 174 #define BN_ULLONG unsigned long long 175 #define BN_LLONG 176 #define BN_ULONG unsigned int 177 #define BN_LONG int 178 #define BN_BITS 64 179 #define BN_BYTES 4 180 #define BN_BITS2 32 181 #define BN_BITS4 16 182 #define BN_MASK (0xffffffffffffffffLL) 183 #define BN_MASK2 (0xffffffffL) 184 #define BN_MASK2l (0xffff) 185 #define BN_MASK2h1 (0xffff8000L) 186 #define BN_MASK2h (0xffff0000L) 187 #define BN_TBIT (0x80000000L) 188 #define BN_DEC_CONV (1000000000L) 189 #define BN_DEC_FMT1 "%u" 190 #define BN_DEC_FMT2 "%09u" 191 #define BN_DEC_NUM 9 192 #define BN_HEX_FMT1 "%X" 193 #define BN_HEX_FMT2 "%08X" 194 #endif 195 196 #define BN_FLG_MALLOCED 0x01 197 #define BN_FLG_STATIC_DATA 0x02 198 #define BN_FLG_CONSTTIME 0x04 /* avoid leaking exponent information through timing, 199 * BN_mod_exp_mont() will call BN_mod_exp_mont_consttime, 200 * BN_div() will call BN_div_no_branch, 201 * BN_mod_inverse() will call BN_mod_inverse_no_branch. 202 */ 203 204 void BN_set_flags(BIGNUM *b, int n); 205 int BN_get_flags(const BIGNUM *b, int n); 206 void BN_with_flags(BIGNUM *dest, const BIGNUM *src, int flags); 207 208 /* Values for |top| in BN_rand() */ 209 #define BN_RAND_TOP_ANY -1 210 #define BN_RAND_TOP_ONE 0 211 #define BN_RAND_TOP_TWO 1 212 213 /* Values for |bottom| in BN_rand() */ 214 #define BN_RAND_BOTTOM_ANY 0 215 #define BN_RAND_BOTTOM_ODD 1 216 217 BN_GENCB *BN_GENCB_new(void); 218 void BN_GENCB_free(BN_GENCB *cb); 219 220 /* Wrapper function to make using BN_GENCB easier, */ 221 int BN_GENCB_call(BN_GENCB *cb, int a, int b); 222 223 /* Populate a BN_GENCB structure with an "old"-style callback */ 224 void BN_GENCB_set_old(BN_GENCB *gencb, void (*callback)(int, int, void *), 225 void *cb_arg); 226 227 /* Populate a BN_GENCB structure with a "new"-style callback */ 228 void BN_GENCB_set(BN_GENCB *gencb, int (*callback)(int, int, BN_GENCB *), 229 void *cb_arg); 230 231 void *BN_GENCB_get_arg(BN_GENCB *cb); 232 233 #define BN_prime_checks 0 /* default: select number of iterations 234 based on the size of the number */ 235 236 /* 237 * BN_prime_checks_for_size() returns the number of Miller-Rabin 238 * iterations that will be done for checking that a random number 239 * is probably prime. The error rate for accepting a composite 240 * number as prime depends on the size of the prime |b|. The error 241 * rates used are for calculating an RSA key with 2 primes, and so 242 * the level is what you would expect for a key of double the size 243 * of the prime. 244 * 245 * This table is generated using the algorithm of FIPS PUB 186-4 246 * Digital Signature Standard (DSS), section F.1, page 117. 247 * (https://dx.doi.org/10.6028/NIST.FIPS.186-4) 248 * 249 * The following magma script was used to generate the output: 250 * securitybits:=125; 251 * k:=1024; 252 * for t:=1 to 65 do 253 * for M:=3 to Floor(2*Sqrt(k-1)-1) do 254 * S:=0; 255 * // Sum over m 256 * for m:=3 to M do 257 * s:=0; 258 * // Sum over j 259 * for j:=2 to m do 260 * s+:=(RealField(32)!2)^-(j+(k-1)/j); 261 * end for; 262 * S+:=2^(m-(m-1)*t)*s; 263 * end for; 264 * A:=2^(k-2-M*t); 265 * B:=8*(Pi(RealField(32))^2-6)/3*2^(k-2)*S; 266 * pkt:=2.00743*Log(2)*k*2^-k*(A+B); 267 * seclevel:=Floor(-Log(2,pkt)); 268 * if seclevel ge securitybits then 269 * printf "k: %5o, security: %o bits (t: %o, M: %o)\n",k,seclevel,t,M; 270 * break; 271 * end if; 272 * end for; 273 * if seclevel ge securitybits then break; end if; 274 * end for; 275 * 276 * It can be run online at: 277 * http://magma.maths.usyd.edu.au/calc 278 * 279 * And will output: 280 * k: 1024, security: 129 bits (t: 6, M: 23) 281 * 282 * k is the number of bits of the prime, securitybits is the level 283 * we want to reach. 284 * 285 * prime length | RSA key size | # MR tests | security level 286 * -------------+--------------|------------+--------------- 287 * (b) >= 6394 | >= 12788 | 3 | 256 bit 288 * (b) >= 3747 | >= 7494 | 3 | 192 bit 289 * (b) >= 1345 | >= 2690 | 4 | 128 bit 290 * (b) >= 1080 | >= 2160 | 5 | 128 bit 291 * (b) >= 852 | >= 1704 | 5 | 112 bit 292 * (b) >= 476 | >= 952 | 5 | 80 bit 293 * (b) >= 400 | >= 800 | 6 | 80 bit 294 * (b) >= 347 | >= 694 | 7 | 80 bit 295 * (b) >= 308 | >= 616 | 8 | 80 bit 296 * (b) >= 55 | >= 110 | 27 | 64 bit 297 * (b) >= 6 | >= 12 | 34 | 64 bit 298 */ 299 300 #define BN_prime_checks_for_size(b) ((b) >= 3747 ? 3 : \ 301 (b) >= 1345 ? 4 : \ 302 (b) >= 476 ? 5 : \ 303 (b) >= 400 ? 6 : \ 304 (b) >= 347 ? 7 : \ 305 (b) >= 308 ? 8 : \ 306 (b) >= 55 ? 27 : \ 307 /* b >= 6 */ 34) 308 309 #define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) 310 311 int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w); 312 int BN_is_zero(const BIGNUM *a); 313 int BN_is_one(const BIGNUM *a); 314 int BN_is_word(const BIGNUM *a, const BN_ULONG w); 315 int BN_is_odd(const BIGNUM *a); 316 317 void BN_zero(BIGNUM *a); 318 int BN_one(BIGNUM *a); 319 320 const BIGNUM *BN_value_one(void); 321 BN_CTX *BN_CTX_new(void); 322 void BN_CTX_free(BN_CTX *c); 323 void BN_CTX_start(BN_CTX *ctx); 324 BIGNUM *BN_CTX_get(BN_CTX *ctx); 325 void BN_CTX_end(BN_CTX *ctx); 326 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom); 327 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom); 328 int BN_rand_range(BIGNUM *rnd, const BIGNUM *range); 329 int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range); 330 int BN_num_bits(const BIGNUM *a); 331 int BN_num_bits_word(BN_ULONG); 332 BIGNUM *BN_new(void); 333 void BN_clear_free(BIGNUM *a); 334 BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); 335 void BN_swap(BIGNUM *a, BIGNUM *b); 336 BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret); 337 int BN_bn2bin(const BIGNUM *a, unsigned char *to); 338 int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen); 339 BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret); 340 int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen); 341 BIGNUM *BN_mpi2bn(const unsigned char *s, int len, BIGNUM *ret); 342 int BN_bn2mpi(const BIGNUM *a, unsigned char *to); 343 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 344 int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 345 int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 346 int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 347 int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 348 int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx); 349 void BN_set_negative(BIGNUM *b, int n); 350 351 int BN_is_negative(const BIGNUM *b); 352 353 int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, 354 BN_CTX *ctx); 355 #define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx)) 356 357 int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); 358 int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); 359 int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m); 360 int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); 361 int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m); 362 int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 363 const BIGNUM *m, BN_CTX *ctx); 364 int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); 365 int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); 366 int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m); 367 int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx); 368 int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m); 369 370 BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w); 371 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); 372 int BN_mul_word(BIGNUM *a, BN_ULONG w); 373 int BN_add_word(BIGNUM *a, BN_ULONG w); 374 int BN_sub_word(BIGNUM *a, BN_ULONG w); 375 int BN_set_word(BIGNUM *a, BN_ULONG w); 376 BN_ULONG BN_get_word(const BIGNUM *a); 377 378 int BN_cmp(const BIGNUM *a, const BIGNUM *b); 379 void BN_free(BIGNUM *a); 380 int BN_is_bit_set(const BIGNUM *a, int n); 381 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); 382 int BN_lshift1(BIGNUM *r, const BIGNUM *a); 383 int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); 384 385 int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 386 const BIGNUM *m, BN_CTX *ctx); 387 int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 388 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 389 int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, 390 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont); 391 392 int BN_mask_bits(BIGNUM *a, int n); 393 int BN_print_fp(FILE *fp, const BIGNUM *a); 394 int BN_print(BIO *fp, const BIGNUM *a); 395 int BN_rshift(BIGNUM *r, const BIGNUM *a, int n); 396 int BN_rshift1(BIGNUM *r, const BIGNUM *a); 397 void BN_clear(BIGNUM *a); 398 BIGNUM *BN_dup(const BIGNUM *a); 399 int BN_ucmp(const BIGNUM *a, const BIGNUM *b); 400 int BN_set_bit(BIGNUM *a, int n); 401 int BN_clear_bit(BIGNUM *a, int n); 402 char * BN_bn2hex(const BIGNUM *a); 403 char * BN_bn2dec(const BIGNUM *a); 404 int BN_hex2bn(BIGNUM **a, const char *str); 405 int BN_dec2bn(BIGNUM **a, const char *str); 406 int BN_asc2bn(BIGNUM **a, const char *str); 407 int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 408 int BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */ 409 BIGNUM *BN_mod_inverse(BIGNUM *ret, 410 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx); 411 BIGNUM *BN_mod_sqrt(BIGNUM *ret, 412 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx); 413 414 void BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords); 415 416 int BN_security_bits(int L, int N); 417 418 int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, 419 const BIGNUM *rem, BN_GENCB *cb); 420 int BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, BN_GENCB *cb); 421 int BN_is_prime_fasttest_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, 422 int do_trial_division, BN_GENCB *cb); 423 424 BN_MONT_CTX *BN_MONT_CTX_new(void ); 425 int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 426 BN_MONT_CTX *mont, BN_CTX *ctx); 427 int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, 428 BN_CTX *ctx); 429 int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, 430 BN_MONT_CTX *mont, BN_CTX *ctx); 431 void BN_MONT_CTX_free(BN_MONT_CTX *mont); 432 int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx); 433 BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from); 434 BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock, 435 const BIGNUM *mod, BN_CTX *ctx); 436 437 /* Primes from RFC 2409 */ 438 BIGNUM *BN_get_rfc2409_prime_768(BIGNUM *bn); 439 BIGNUM *BN_get_rfc2409_prime_1024(BIGNUM *bn); 440 441 /* Primes from RFC 3526 */ 442 BIGNUM *BN_get_rfc3526_prime_1536(BIGNUM *bn); 443 BIGNUM *BN_get_rfc3526_prime_2048(BIGNUM *bn); 444 BIGNUM *BN_get_rfc3526_prime_3072(BIGNUM *bn); 445 BIGNUM *BN_get_rfc3526_prime_4096(BIGNUM *bn); 446 BIGNUM *BN_get_rfc3526_prime_6144(BIGNUM *bn); 447 BIGNUM *BN_get_rfc3526_prime_8192(BIGNUM *bn); 448 449 void ERR_load_BN_strings(void); 450 451 /* Error codes for the BN functions. */ 452 453 /* Function codes. */ 454 #define BN_F_BNRAND 127 455 #define BN_F_BN_BLINDING_CONVERT_EX 100 456 #define BN_F_BN_BLINDING_CREATE_PARAM 128 457 #define BN_F_BN_BLINDING_INVERT_EX 101 458 #define BN_F_BN_BLINDING_NEW 102 459 #define BN_F_BN_BLINDING_UPDATE 103 460 #define BN_F_BN_BN2DEC 104 461 #define BN_F_BN_BN2HEX 105 462 #define BN_F_BN_CTX_GET 116 463 #define BN_F_BN_CTX_NEW 106 464 #define BN_F_BN_CTX_START 129 465 #define BN_F_BN_DIV 107 466 #define BN_F_BN_DIV_NO_BRANCH 138 467 #define BN_F_BN_DIV_RECP 130 468 #define BN_F_BN_EXP 123 469 #define BN_F_BN_EXPAND2 108 470 #define BN_F_BN_GENERATE_PRIME_EX 140 471 #define BN_F_BN_EXPAND_INTERNAL 120 472 #define BN_F_BN_GF2M_MOD 131 473 #define BN_F_BN_GF2M_MOD_EXP 132 474 #define BN_F_BN_GF2M_MOD_MUL 133 475 #define BN_F_BN_GF2M_MOD_SOLVE_QUAD 134 476 #define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR 135 477 #define BN_F_BN_GF2M_MOD_SQR 136 478 #define BN_F_BN_GF2M_MOD_SQRT 137 479 #define BN_F_BN_MOD_EXP2_MONT 118 480 #define BN_F_BN_MOD_EXP_MONT 109 481 #define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124 482 #define BN_F_BN_MOD_EXP_MONT_WORD 117 483 #define BN_F_BN_MOD_EXP_RECP 125 484 #define BN_F_BN_MOD_EXP_SIMPLE 126 485 #define BN_F_BN_MOD_INVERSE 110 486 #define BN_F_BN_MOD_INVERSE_NO_BRANCH 139 487 #define BN_F_BN_MOD_LSHIFT_QUICK 119 488 #define BN_F_BN_MOD_MUL_RECIPROCAL 111 489 #define BN_F_BN_MOD_SQRT 121 490 #define BN_F_BN_MPI2BN 112 491 #define BN_F_BN_NEW 113 492 #define BN_F_BN_RAND 114 493 #define BN_F_BN_RAND_RANGE 122 494 #define BN_F_BN_USUB 115 495 496 /* Reason codes. */ 497 #define BN_R_ARG2_LT_ARG3 100 498 #define BN_R_BAD_RECIPROCAL 101 499 #define BN_R_BIGNUM_TOO_LONG 114 500 #define BN_R_BITS_TOO_SMALL 117 501 #define BN_R_CALLED_WITH_EVEN_MODULUS 102 502 #define BN_R_DIV_BY_ZERO 103 503 #define BN_R_ENCODING_ERROR 104 504 #define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105 505 #define BN_R_INPUT_NOT_REDUCED 110 506 #define BN_R_INVALID_ARGUMENT 118 507 #define BN_R_INVALID_LENGTH 106 508 #define BN_R_INVALID_RANGE 115 509 #define BN_R_NOT_A_SQUARE 111 510 #define BN_R_NOT_INITIALIZED 107 511 #define BN_R_NO_INVERSE 108 512 #define BN_R_NO_SOLUTION 116 513 #define BN_R_P_IS_NOT_PRIME 112 514 #define BN_R_TOO_MANY_ITERATIONS 113 515 #define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109 516 517 #ifdef __cplusplus 518 } 519 #endif 520 #endif 521