diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_gcd.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_gcd.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c index 3c8ff5b405..4eab1b36d2 100644 --- a/src/lib/libcrypto/bn/bn_gcd.c +++ b/src/lib/libcrypto/bn/bn_gcd.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_gcd.c,v 1.11 2017/01/21 10:38:29 beck Exp $ */ | 1 | /* $OpenBSD: bn_gcd.c,v 1.12 2017/01/21 11:00:46 beck Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -231,17 +231,16 @@ err: | |||
231 | static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, | 231 | static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, |
232 | const BIGNUM *n, BN_CTX *ctx); | 232 | const BIGNUM *n, BN_CTX *ctx); |
233 | 233 | ||
234 | BIGNUM * | 234 | static BIGNUM * |
235 | BN_mod_inverse(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) | 235 | BN_mod_inverse_internal(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, |
236 | int ct) | ||
236 | { | 237 | { |
237 | BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL; | 238 | BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL; |
238 | BIGNUM *ret = NULL; | 239 | BIGNUM *ret = NULL; |
239 | int sign; | 240 | int sign; |
240 | 241 | ||
241 | if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || | 242 | if (ct) |
242 | (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) { | ||
243 | return BN_mod_inverse_no_branch(in, a, n, ctx); | 243 | return BN_mod_inverse_no_branch(in, a, n, ctx); |
244 | } | ||
245 | 244 | ||
246 | bn_check_top(a); | 245 | bn_check_top(a); |
247 | bn_check_top(n); | 246 | bn_check_top(n); |
@@ -524,6 +523,25 @@ err: | |||
524 | return (ret); | 523 | return (ret); |
525 | } | 524 | } |
526 | 525 | ||
526 | BIGNUM * | ||
527 | BN_mod_inverse(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) | ||
528 | { | ||
529 | int ct = ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || | ||
530 | (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)); | ||
531 | return BN_mod_inverse_internal(in, a, n, ctx, ct); | ||
532 | } | ||
533 | |||
534 | BIGNUM * | ||
535 | BN_mod_inverse_nonct(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) | ||
536 | { | ||
537 | return BN_mod_inverse_internal(in, a, n, ctx, 0); | ||
538 | } | ||
539 | |||
540 | BIGNUM * | ||
541 | BN_mod_inverse_ct(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) | ||
542 | { | ||
543 | return BN_mod_inverse_internal(in, a, n, ctx, 1); | ||
544 | } | ||
527 | 545 | ||
528 | /* BN_mod_inverse_no_branch is a special version of BN_mod_inverse. | 546 | /* BN_mod_inverse_no_branch is a special version of BN_mod_inverse. |
529 | * It does not contain branches that may leak sensitive information. | 547 | * It does not contain branches that may leak sensitive information. |