BN_copy now propagates BN_FLG_CONSTTIME
authorSamuel Weiser <samuel.weiser@iaik.tugraz.at>
Sat, 16 Sep 2017 14:52:44 +0000 (16:52 +0200)
committerMatt Caswell <matt@openssl.org>
Wed, 27 Sep 2017 09:03:37 +0000 (10:03 +0100)
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4377)

crypto/bn/bn_lib.c
crypto/bn/bn_mont.c

index 99179232f448dbb64c3c286c312c23cbf89915cb..f0a3bf1e3d452a4f8e47c1098656a988a2f0020a 100644 (file)
@@ -332,6 +332,9 @@ BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
     if (b->top > 0)
         memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
 
+    if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)
+        BN_set_flags(a, BN_FLG_CONSTTIME);
+
     a->top = b->top;
     a->neg = b->neg;
     bn_check_top(a);
index 0985de2d8227bbdb2dae61a2183ee4c10f355335..975689432a0b8e7af338ccbb1ed85d3861f4ff88 100644 (file)
@@ -258,8 +258,6 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
     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