diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn.h')
-rw-r--r-- | src/lib/libcrypto/bn/bn.h | 66 |
1 files changed, 1 insertions, 65 deletions
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index db5e7f908c..5d9f17c4d9 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn.h,v 1.50 2021/12/04 16:11:10 tb Exp $ */ | 1 | /* $OpenBSD: bn.h,v 1.51 2022/01/14 07:49:49 tb Exp $ */ |
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -228,14 +228,9 @@ extern "C" { | |||
228 | #ifndef OPENSSL_NO_DEPRECATED | 228 | #ifndef OPENSSL_NO_DEPRECATED |
229 | #define BN_FLG_FREE 0x8000 /* used for debugging */ | 229 | #define BN_FLG_FREE 0x8000 /* used for debugging */ |
230 | #endif | 230 | #endif |
231 | #if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL) | ||
232 | void BN_set_flags(BIGNUM *b, int n); | 231 | void BN_set_flags(BIGNUM *b, int n); |
233 | int BN_get_flags(const BIGNUM *b, int n); | 232 | int BN_get_flags(const BIGNUM *b, int n); |
234 | void BN_with_flags(BIGNUM *dest, const BIGNUM *src, int flags); | 233 | void BN_with_flags(BIGNUM *dest, const BIGNUM *src, int flags); |
235 | #else | ||
236 | #define BN_set_flags(b,n) ((b)->flags|=(n)) | ||
237 | #define BN_get_flags(b,n) ((b)->flags&(n)) | ||
238 | #endif | ||
239 | 234 | ||
240 | /* Values for |top| in BN_rand() */ | 235 | /* Values for |top| in BN_rand() */ |
241 | #define BN_RAND_TOP_ANY -1 | 236 | #define BN_RAND_TOP_ANY -1 |
@@ -246,19 +241,6 @@ void BN_with_flags(BIGNUM *dest, const BIGNUM *src, int flags); | |||
246 | #define BN_RAND_BOTTOM_ANY 0 | 241 | #define BN_RAND_BOTTOM_ANY 0 |
247 | #define BN_RAND_BOTTOM_ODD 1 | 242 | #define BN_RAND_BOTTOM_ODD 1 |
248 | 243 | ||
249 | #if !defined(LIBRESSL_OPAQUE_BN) && !defined(LIBRESSL_CRYPTO_INTERNAL) | ||
250 | /* get a clone of a BIGNUM with changed flags, for *temporary* use only | ||
251 | * (the two BIGNUMs cannot not be used in parallel!) */ | ||
252 | #define BN_with_flags(dest,b,n) ((dest)->d=(b)->d, \ | ||
253 | (dest)->top=(b)->top, \ | ||
254 | (dest)->dmax=(b)->dmax, \ | ||
255 | (dest)->neg=(b)->neg, \ | ||
256 | (dest)->flags=(((dest)->flags & BN_FLG_MALLOCED) \ | ||
257 | | ((b)->flags & ~BN_FLG_MALLOCED) \ | ||
258 | | BN_FLG_STATIC_DATA \ | ||
259 | | (n))) | ||
260 | #endif | ||
261 | |||
262 | /* Move to bn_lcl.h */ | 244 | /* Move to bn_lcl.h */ |
263 | struct bignum_st { | 245 | struct bignum_st { |
264 | BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ | 246 | BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ |
@@ -313,7 +295,6 @@ void BN_GENCB_free(BN_GENCB *cb); | |||
313 | /* Wrapper function to make using BN_GENCB easier, */ | 295 | /* Wrapper function to make using BN_GENCB easier, */ |
314 | int BN_GENCB_call(BN_GENCB *cb, int a, int b); | 296 | int BN_GENCB_call(BN_GENCB *cb, int a, int b); |
315 | 297 | ||
316 | #if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL) | ||
317 | /* Populate a BN_GENCB structure with an "old"-style callback */ | 298 | /* Populate a BN_GENCB structure with an "old"-style callback */ |
318 | void BN_GENCB_set_old(BN_GENCB *gencb, void (*callback)(int, int, void *), | 299 | void BN_GENCB_set_old(BN_GENCB *gencb, void (*callback)(int, int, void *), |
319 | void *cb_arg); | 300 | void *cb_arg); |
@@ -321,20 +302,6 @@ void BN_GENCB_set_old(BN_GENCB *gencb, void (*callback)(int, int, void *), | |||
321 | /* Populate a BN_GENCB structure with a "new"-style callback */ | 302 | /* Populate a BN_GENCB structure with a "new"-style callback */ |
322 | void BN_GENCB_set(BN_GENCB *gencb, int (*callback)(int, int, BN_GENCB *), | 303 | void BN_GENCB_set(BN_GENCB *gencb, int (*callback)(int, int, BN_GENCB *), |
323 | void *cb_arg); | 304 | void *cb_arg); |
324 | #else | ||
325 | /* Macro to populate a BN_GENCB structure with an "old"-style callback */ | ||
326 | #define BN_GENCB_set_old(gencb, callback, cb_arg) { \ | ||
327 | BN_GENCB *tmp_gencb = (gencb); \ | ||
328 | tmp_gencb->ver = 1; \ | ||
329 | tmp_gencb->arg = (cb_arg); \ | ||
330 | tmp_gencb->cb.cb_1 = (callback); } | ||
331 | /* Macro to populate a BN_GENCB structure with a "new"-style callback */ | ||
332 | #define BN_GENCB_set(gencb, callback, cb_arg) { \ | ||
333 | BN_GENCB *tmp_gencb = (gencb); \ | ||
334 | tmp_gencb->ver = 2; \ | ||
335 | tmp_gencb->arg = (cb_arg); \ | ||
336 | tmp_gencb->cb.cb_2 = (callback); } | ||
337 | #endif /* !LIBRESSL_CRYPTO_INTERNAL */ | ||
338 | 305 | ||
339 | void *BN_GENCB_get_arg(BN_GENCB *cb); | 306 | void *BN_GENCB_get_arg(BN_GENCB *cb); |
340 | 307 | ||
@@ -416,7 +383,6 @@ void *BN_GENCB_get_arg(BN_GENCB *cb); | |||
416 | 383 | ||
417 | #define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) | 384 | #define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) |
418 | 385 | ||
419 | #if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL) | ||
420 | int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w); | 386 | int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w); |
421 | int BN_is_zero(const BIGNUM *a); | 387 | int BN_is_zero(const BIGNUM *a); |
422 | int BN_is_one(const BIGNUM *a); | 388 | int BN_is_one(const BIGNUM *a); |
@@ -427,23 +393,6 @@ int BN_is_odd(const BIGNUM *a); | |||
427 | 393 | ||
428 | void BN_zero_ex(BIGNUM *a); | 394 | void BN_zero_ex(BIGNUM *a); |
429 | 395 | ||
430 | #else | ||
431 | #define BN_abs_is_word(a,w) ((((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) || \ | ||
432 | (((w) == 0) && ((a)->top == 0))) | ||
433 | #define BN_is_zero(a) ((a)->top == 0) | ||
434 | #define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg) | ||
435 | #define BN_is_word(a,w) (BN_abs_is_word((a),(w)) && (!(w) || !(a)->neg)) | ||
436 | #define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) | ||
437 | |||
438 | #define BN_one(a) (BN_set_word((a),1)) | ||
439 | #define BN_zero_ex(a) \ | ||
440 | do { \ | ||
441 | BIGNUM *_tmp_bn = (a); \ | ||
442 | _tmp_bn->top = 0; \ | ||
443 | _tmp_bn->neg = 0; \ | ||
444 | } while(0) | ||
445 | #endif /* LIBRESSL_OPAQUE_BN */ | ||
446 | |||
447 | #ifdef OPENSSL_NO_DEPRECATED | 396 | #ifdef OPENSSL_NO_DEPRECATED |
448 | #define BN_zero(a) BN_zero_ex(a) | 397 | #define BN_zero(a) BN_zero_ex(a) |
449 | #else | 398 | #else |
@@ -490,15 +439,7 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx); | |||
490 | */ | 439 | */ |
491 | void BN_set_negative(BIGNUM *b, int n); | 440 | void BN_set_negative(BIGNUM *b, int n); |
492 | 441 | ||
493 | #if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL) | ||
494 | int BN_is_negative(const BIGNUM *b); | 442 | int BN_is_negative(const BIGNUM *b); |
495 | #else | ||
496 | /** BN_is_negative returns 1 if the BIGNUM is negative | ||
497 | * \param a pointer to the BIGNUM object | ||
498 | * \return 1 if a < 0 and 0 otherwise | ||
499 | */ | ||
500 | #define BN_is_negative(a) ((a)->neg != 0) | ||
501 | #endif | ||
502 | 443 | ||
503 | #ifndef LIBRESSL_INTERNAL | 444 | #ifndef LIBRESSL_INTERNAL |
504 | int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | 445 | int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, |
@@ -613,13 +554,8 @@ BN_MONT_CTX *BN_MONT_CTX_new(void ); | |||
613 | void BN_MONT_CTX_init(BN_MONT_CTX *ctx); | 554 | void BN_MONT_CTX_init(BN_MONT_CTX *ctx); |
614 | int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | 555 | int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, |
615 | BN_MONT_CTX *mont, BN_CTX *ctx); | 556 | BN_MONT_CTX *mont, BN_CTX *ctx); |
616 | #if defined(LIBRESSL_OPAQUE_BN) || defined(LIBRESSL_CRYPTO_INTERNAL) | ||
617 | int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, | 557 | int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, |
618 | BN_CTX *ctx); | 558 | BN_CTX *ctx); |
619 | #else | ||
620 | #define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ | ||
621 | (r),(a),&((mont)->RR),(mont),(ctx)) | ||
622 | #endif | ||
623 | int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, | 559 | int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, |
624 | BN_MONT_CTX *mont, BN_CTX *ctx); | 560 | BN_MONT_CTX *mont, BN_CTX *ctx); |
625 | void BN_MONT_CTX_free(BN_MONT_CTX *mont); | 561 | void BN_MONT_CTX_free(BN_MONT_CTX *mont); |