Constify the BIGNUM routines a bit more. The only trouble were the
[openssl.git] / crypto / bn / bn_mont.c
index 598fecbf0c89fb2d8932951105c79210a46ef4ac..202eec4462f3e52bc2613e54ecd8cd25729c400a 100644 (file)
@@ -69,7 +69,7 @@
 
 #define MONT_WORD /* use the faster word-based algorithm */
 
 
 #define MONT_WORD /* use the faster word-based algorithm */
 
-int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
+int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
                          BN_MONT_CTX *mont, BN_CTX *ctx)
        {
        BIGNUM *tmp,*tmp2;
                          BN_MONT_CTX *mont, BN_CTX *ctx)
        {
        BIGNUM *tmp,*tmp2;
@@ -85,16 +85,7 @@ int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
 
        if (a == b)
                {
 
        if (a == b)
                {
-#if 0
-               bn_wexpand(tmp,a->top*2);
-               bn_wexpand(tmp2,a->top*4);
-               bn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);
-               tmp->top=a->top*2;
-               if (tmp->d[tmp->top-1] == 0)
-                       tmp->top--;
-#else
                if (!BN_sqr(tmp,a,ctx)) goto err;
                if (!BN_sqr(tmp,a,ctx)) goto err;
-#endif
                }
        else
                {
                }
        else
                {
@@ -157,7 +148,22 @@ int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
 #endif
        for (i=0; i<nl; i++)
                {
 #endif
        for (i=0; i<nl; i++)
                {
+#ifdef __TANDEM
+                {
+                   long long t1;
+                   long long t2;
+                   long long t3;
+                   t1 = rp[0] * (n0 & 0177777);
+                   t2 = 037777600000l;
+                   t2 = n0 & t2;
+                   t3 = rp[0] & 0177777;
+                   t2 = (t3 * t2) & BN_MASK2;
+                   t1 = t1 + t2;
+                   v=bn_mul_add_words(rp,np,nl,(BN_ULONG) t1);
+                }
+#else
                v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
                v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
+#endif
                nrp++;
                rp++;
                if (((nrp[-1]+=v)&BN_MASK2) >= v)
                nrp++;
                rp++;
                if (((nrp[-1]+=v)&BN_MASK2) >= v)
@@ -175,6 +181,7 @@ int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
 #if 0
        BN_rshift(ret,r,mont->ri);
 #else
 #if 0
        BN_rshift(ret,r,mont->ri);
 #else
+       ret->neg = r->neg;
        x=ri;
        rp=ret->d;
        ap= &(r->d[x]);
        x=ri;
        rp=ret->d;
        ap= &(r->d[x]);
@@ -234,7 +241,7 @@ BN_MONT_CTX *BN_MONT_CTX_new(void)
        {
        BN_MONT_CTX *ret;
 
        {
        BN_MONT_CTX *ret;
 
-       if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
+       if ((ret=(BN_MONT_CTX *)OPENSSL_malloc(sizeof(BN_MONT_CTX))) == NULL)
                return(NULL);
 
        BN_MONT_CTX_init(ret);
                return(NULL);
 
        BN_MONT_CTX_init(ret);
@@ -260,7 +267,7 @@ void BN_MONT_CTX_free(BN_MONT_CTX *mont)
        BN_free(&(mont->N));
        BN_free(&(mont->Ni));
        if (mont->flags & BN_FLG_MALLOCED)
        BN_free(&(mont->N));
        BN_free(&(mont->Ni));
        if (mont->flags & BN_FLG_MALLOCED)
-               Free(mont);
+               OPENSSL_free(mont);
        }
 
 int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
        }
 
 int 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)
                buf[1]=0;
                tmod.d=buf;
                tmod.top=1;
                buf[1]=0;
                tmod.d=buf;
                tmod.top=1;
-               tmod.max=2;
+               tmod.dmax=2;
                tmod.neg=mod->neg;
                                                        /* Ri = R^-1 mod N*/
                if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)
                tmod.neg=mod->neg;
                                                        /* Ri = R^-1 mod N*/
                if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)