diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_recp.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_recp.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c index ef5fdd4708..2e8efb8dae 100644 --- a/src/lib/libcrypto/bn/bn_recp.c +++ b/src/lib/libcrypto/bn/bn_recp.c | |||
@@ -94,7 +94,7 @@ void BN_RECP_CTX_free(BN_RECP_CTX *recp) | |||
94 | int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) | 94 | int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) |
95 | { | 95 | { |
96 | if (!BN_copy(&(recp->N),d)) return 0; | 96 | if (!BN_copy(&(recp->N),d)) return 0; |
97 | if (!BN_zero(&(recp->Nr))) return 0; | 97 | BN_zero(&(recp->Nr)); |
98 | recp->num_bits=BN_num_bits(d); | 98 | recp->num_bits=BN_num_bits(d); |
99 | recp->shift=0; | 99 | recp->shift=0; |
100 | return(1); | 100 | return(1); |
@@ -123,6 +123,7 @@ int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, | |||
123 | ret = BN_div_recp(NULL,r,ca,recp,ctx); | 123 | ret = BN_div_recp(NULL,r,ca,recp,ctx); |
124 | err: | 124 | err: |
125 | BN_CTX_end(ctx); | 125 | BN_CTX_end(ctx); |
126 | bn_check_top(r); | ||
126 | return(ret); | 127 | return(ret); |
127 | } | 128 | } |
128 | 129 | ||
@@ -147,7 +148,7 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, | |||
147 | 148 | ||
148 | if (BN_ucmp(m,&(recp->N)) < 0) | 149 | if (BN_ucmp(m,&(recp->N)) < 0) |
149 | { | 150 | { |
150 | if (!BN_zero(d)) return 0; | 151 | BN_zero(d); |
151 | if (!BN_copy(r,m)) return 0; | 152 | if (!BN_copy(r,m)) return 0; |
152 | BN_CTX_end(ctx); | 153 | BN_CTX_end(ctx); |
153 | return(1); | 154 | return(1); |
@@ -190,7 +191,7 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, | |||
190 | { | 191 | { |
191 | if (j++ > 2) | 192 | if (j++ > 2) |
192 | { | 193 | { |
193 | BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL); | 194 | BNerr(BN_F_BN_DIV_RECP,BN_R_BAD_RECIPROCAL); |
194 | goto err; | 195 | goto err; |
195 | } | 196 | } |
196 | if (!BN_usub(r,r,&(recp->N))) goto err; | 197 | if (!BN_usub(r,r,&(recp->N))) goto err; |
@@ -203,6 +204,8 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, | |||
203 | ret=1; | 204 | ret=1; |
204 | err: | 205 | err: |
205 | BN_CTX_end(ctx); | 206 | BN_CTX_end(ctx); |
207 | bn_check_top(dv); | ||
208 | bn_check_top(rem); | ||
206 | return(ret); | 209 | return(ret); |
207 | } | 210 | } |
208 | 211 | ||
@@ -214,17 +217,18 @@ err: | |||
214 | int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) | 217 | int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) |
215 | { | 218 | { |
216 | int ret= -1; | 219 | int ret= -1; |
217 | BIGNUM t; | 220 | BIGNUM *t; |
218 | 221 | ||
219 | BN_init(&t); | 222 | BN_CTX_start(ctx); |
223 | if((t = BN_CTX_get(ctx)) == NULL) goto err; | ||
220 | 224 | ||
221 | if (!BN_zero(&t)) goto err; | 225 | if (!BN_set_bit(t,len)) goto err; |
222 | if (!BN_set_bit(&t,len)) goto err; | ||
223 | 226 | ||
224 | if (!BN_div(r,NULL,&t,m,ctx)) goto err; | 227 | if (!BN_div(r,NULL,t,m,ctx)) goto err; |
225 | 228 | ||
226 | ret=len; | 229 | ret=len; |
227 | err: | 230 | err: |
228 | BN_free(&t); | 231 | bn_check_top(r); |
232 | BN_CTX_end(ctx); | ||
229 | return(ret); | 233 | return(ret); |
230 | } | 234 | } |