diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_mod.c')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_mod.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/bn/bn_mod.c index 5cf82480d7..77d6ddb91a 100644 --- a/src/lib/libcrypto/bn/bn_mod.c +++ b/src/lib/libcrypto/bn/bn_mod.c | |||
| @@ -149,7 +149,7 @@ int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_ | |||
| 149 | * and less than m */ | 149 | * and less than m */ |
| 150 | int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m) | 150 | int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m) |
| 151 | { | 151 | { |
| 152 | if (!BN_add(r, a, b)) return 0; | 152 | if (!BN_uadd(r, a, b)) return 0; |
| 153 | if (BN_ucmp(r, m) >= 0) | 153 | if (BN_ucmp(r, m) >= 0) |
| 154 | return BN_usub(r, r, m); | 154 | return BN_usub(r, r, m); |
| 155 | return 1; | 155 | return 1; |
| @@ -192,6 +192,7 @@ int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, | |||
| 192 | else | 192 | else |
| 193 | { if (!BN_mul(t,a,b,ctx)) goto err; } | 193 | { if (!BN_mul(t,a,b,ctx)) goto err; } |
| 194 | if (!BN_nnmod(r,t,m,ctx)) goto err; | 194 | if (!BN_nnmod(r,t,m,ctx)) goto err; |
| 195 | bn_check_top(r); | ||
| 195 | ret=1; | 196 | ret=1; |
| 196 | err: | 197 | err: |
| 197 | BN_CTX_end(ctx); | 198 | BN_CTX_end(ctx); |
| @@ -210,6 +211,7 @@ int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx) | |||
| 210 | int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx) | 211 | int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx) |
| 211 | { | 212 | { |
| 212 | if (!BN_lshift1(r, a)) return 0; | 213 | if (!BN_lshift1(r, a)) return 0; |
| 214 | bn_check_top(r); | ||
| 213 | return BN_nnmod(r, r, m, ctx); | 215 | return BN_nnmod(r, r, m, ctx); |
| 214 | } | 216 | } |
| 215 | 217 | ||
| @@ -219,6 +221,7 @@ int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx) | |||
| 219 | int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m) | 221 | int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m) |
| 220 | { | 222 | { |
| 221 | if (!BN_lshift1(r, a)) return 0; | 223 | if (!BN_lshift1(r, a)) return 0; |
| 224 | bn_check_top(r); | ||
| 222 | if (BN_cmp(r, m) >= 0) | 225 | if (BN_cmp(r, m) >= 0) |
| 223 | return BN_sub(r, r, m); | 226 | return BN_sub(r, r, m); |
| 224 | return 1; | 227 | return 1; |
| @@ -240,6 +243,7 @@ int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ct | |||
| 240 | } | 243 | } |
| 241 | 244 | ||
| 242 | ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m)); | 245 | ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m)); |
| 246 | bn_check_top(r); | ||
| 243 | 247 | ||
| 244 | if (abs_m) | 248 | if (abs_m) |
| 245 | BN_free(abs_m); | 249 | BN_free(abs_m); |
| @@ -291,6 +295,7 @@ int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m) | |||
| 291 | if (!BN_sub(r, r, m)) return 0; | 295 | if (!BN_sub(r, r, m)) return 0; |
| 292 | } | 296 | } |
| 293 | } | 297 | } |
| 298 | bn_check_top(r); | ||
| 294 | 299 | ||
| 295 | return 1; | 300 | return 1; |
| 296 | } | 301 | } |
