summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_mont.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_mont.c')
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
index 598fecbf0c..8cf1febacc 100644
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ b/src/lib/libcrypto/bn/bn_mont.c
@@ -85,16 +85,7 @@ int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
85 85
86 if (a == b) 86 if (a == b)
87 { 87 {
88#if 0
89 bn_wexpand(tmp,a->top*2);
90 bn_wexpand(tmp2,a->top*4);
91 bn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);
92 tmp->top=a->top*2;
93 if (tmp->d[tmp->top-1] == 0)
94 tmp->top--;
95#else
96 if (!BN_sqr(tmp,a,ctx)) goto err; 88 if (!BN_sqr(tmp,a,ctx)) goto err;
97#endif
98 } 89 }
99 else 90 else
100 { 91 {
@@ -157,7 +148,22 @@ int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
157#endif 148#endif
158 for (i=0; i<nl; i++) 149 for (i=0; i<nl; i++)
159 { 150 {
151#ifdef __TANDEM
152 {
153 long long t1;
154 long long t2;
155 long long t3;
156 t1 = rp[0] * (n0 & 0177777);
157 t2 = 037777600000l;
158 t2 = n0 & t2;
159 t3 = rp[0] & 0177777;
160 t2 = (t3 * t2) & BN_MASK2;
161 t1 = t1 + t2;
162 v=bn_mul_add_words(rp,np,nl,(BN_ULONG) t1);
163 }
164#else
160 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2); 165 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
166#endif
161 nrp++; 167 nrp++;
162 rp++; 168 rp++;
163 if (((nrp[-1]+=v)&BN_MASK2) >= v) 169 if (((nrp[-1]+=v)&BN_MASK2) >= v)
@@ -175,6 +181,7 @@ int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
175#if 0 181#if 0
176 BN_rshift(ret,r,mont->ri); 182 BN_rshift(ret,r,mont->ri);
177#else 183#else
184 ret->neg = r->neg;
178 x=ri; 185 x=ri;
179 rp=ret->d; 186 rp=ret->d;
180 ap= &(r->d[x]); 187 ap= &(r->d[x]);
@@ -234,7 +241,7 @@ BN_MONT_CTX *BN_MONT_CTX_new(void)
234 { 241 {
235 BN_MONT_CTX *ret; 242 BN_MONT_CTX *ret;
236 243
237 if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL) 244 if ((ret=(BN_MONT_CTX *)OPENSSL_malloc(sizeof(BN_MONT_CTX))) == NULL)
238 return(NULL); 245 return(NULL);
239 246
240 BN_MONT_CTX_init(ret); 247 BN_MONT_CTX_init(ret);
@@ -260,7 +267,7 @@ void BN_MONT_CTX_free(BN_MONT_CTX *mont)
260 BN_free(&(mont->N)); 267 BN_free(&(mont->N));
261 BN_free(&(mont->Ni)); 268 BN_free(&(mont->Ni));
262 if (mont->flags & BN_FLG_MALLOCED) 269 if (mont->flags & BN_FLG_MALLOCED)
263 Free(mont); 270 OPENSSL_free(mont);
264 } 271 }
265 272
266int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx) 273int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
@@ -284,7 +291,7 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
284 buf[1]=0; 291 buf[1]=0;
285 tmod.d=buf; 292 tmod.d=buf;
286 tmod.top=1; 293 tmod.top=1;
287 tmod.max=2; 294 tmod.dmax=2;
288 tmod.neg=mod->neg; 295 tmod.neg=mod->neg;
289 /* Ri = R^-1 mod N*/ 296 /* Ri = R^-1 mod N*/
290 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL) 297 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)