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