summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_recp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_recp.c')
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c22
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)
94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) 94int 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);
124err: 124err:
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;
205err: 204err:
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:
217int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) 214int 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;
230err: 227err:
231 bn_check_top(r); 228 BN_free(&t);
232 BN_CTX_end(ctx);
233 return(ret); 229 return(ret);
234 } 230 }