File openssl-add-missing-commits-for-bsc1117951.patch of Package compat-openssl098.29129
Index: openssl-0.9.8j/crypto/bn/bn_mont.c
===================================================================
--- openssl-0.9.8j.orig/crypto/bn/bn_mont.c
+++ openssl-0.9.8j/crypto/bn/bn_mont.c
@@ -326,9 +326,6 @@ static int bn_from_montgomery_word(BIGNU
}
for (ri+=4; i<ri; i++)
rp[i]=nrp[i], ap[i]=0;
- bn_correct_top(r);
- bn_correct_top(ret);
- bn_check_top(ret);
return(1);
}
@@ -354,8 +351,6 @@ int bn_from_mont_fixed_top(BIGNUM *ret,
BN_CTX_start(ctx);
if ((t = BN_CTX_get(ctx)) && BN_copy(t, a)) {
retn = bn_from_montgomery_word(ret, t, mont);
- bn_correct_top(ret);
- bn_check_top(ret);
}
BN_CTX_end(ctx);
return retn;
@@ -409,6 +404,11 @@ int BN_from_montgomery(BIGNUM *ret, cons
#ifdef BN_COUNT
fprintf(stderr,"word BN_from_montgomery %d * %d\n",nl,nl);
#endif
+ /*
+ * Add multiples of |n| to |r| until R = 2^(nl * BN_BITS2) divides it. On
+ * input, we had |r| < |n| * R, so now |r| < 2 * |n| * R. Note that |r|
+ * includes |carry| which is stored separately.
+ */
for (i=0; i<nl; i++)
{
#ifdef __TANDEM
@@ -610,6 +610,8 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, c
if((Ri = BN_CTX_get(ctx)) == NULL) goto err;
R= &(mont->RR); /* grab RR as a temp */
if (!BN_copy(&(mont->N),mod)) goto err; /* Set N */
+ if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)
+ BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);
mont->N.neg = 0;
#ifdef MONT_WORD
@@ -617,6 +619,9 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, c
BIGNUM tmod;
BN_ULONG buf[2];
+ if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)
+ BN_set_flags(&tmod, BN_FLG_CONSTTIME);
+
mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
BN_zero(R);
#if 0 /* for OpenSSL 0.9.9 mont->n0, would be "#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)",
Index: openssl-0.9.8j/crypto/bn/bn_mul.c
===================================================================
--- openssl-0.9.8j.orig/crypto/bn/bn_mul.c
+++ openssl-0.9.8j/crypto/bn/bn_mul.c
@@ -1106,7 +1106,7 @@ int bn_mul_fixed_top(BIGNUM *r, const BI
end:
#endif
rr->flags |= BN_FLG_FIXED_TOP;
- if (r != rr) BN_copy(r,rr);
+ if (r != rr && BN_copy(r, rr) == NULL) goto err;
ret=1;
err:
bn_check_top(r);