File openssl-add-missing-commits-for-bsc1117951.patch of Package openssl.24728
Index: openssl-1.0.2j/crypto/bn/bn_mont.c
===================================================================
--- openssl-1.0.2j.orig/crypto/bn/bn_mont.c
+++ openssl-1.0.2j/crypto/bn/bn_mont.c
@@ -220,6 +220,11 @@ static int bn_from_montgomery_word(BIGNU
# ifdef BN_COUNT
fprintf(stderr, "word BN_from_montgomery_word %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 (carry = 0, i = 0; i < nl; i++, rp++) {
# ifdef __TANDEM
{
@@ -290,9 +295,6 @@ static int bn_from_montgomery_word(BIGNU
if (bn_sub_words(rp, ap, np, nl) - carry)
memcpy(rp, ap, nl * sizeof(BN_ULONG));
# endif
- bn_correct_top(r);
- bn_correct_top(ret);
- bn_check_top(ret);
return (1);
}
@@ -320,8 +322,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);
#else /* !MONT_WORD */
@@ -414,6 +414,8 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, c
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
@@ -426,6 +428,9 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, c
tmod.dmax = 2;
tmod.neg = 0;
+ 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;
# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)
Index: openssl-1.0.2j/crypto/bn/bn_mul.c
===================================================================
--- openssl-1.0.2j.orig/crypto/bn/bn_mul.c
+++ openssl-1.0.2j/crypto/bn/bn_mul.c
@@ -1093,8 +1093,8 @@ 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);