]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
[crypto/bn] BN_consttime_swap: remove superfluous early exit
authorBilly Brumley <bbrumley@gmail.com>
Thu, 9 Jun 2022 21:03:23 +0000 (00:03 +0300)
committerTomas Mraz <tomas@openssl.org>
Mon, 13 Jun 2022 08:50:44 +0000 (10:50 +0200)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18518)

crypto/bn/bn_lib.c
test/bntest.c

index 23a4415fb9f72fd4a1115c71f80553f767070c0f..089b23963d29da530c9550a0ad055d52a381a2a3 100644 (file)
@@ -910,9 +910,6 @@ void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
     BN_ULONG t;
     int i;
 
-    if (a == b)
-        return;
-
     bn_wcheck_size(a, nwords);
     bn_wcheck_size(b, nwords);
 
index 9f4bc0b3eb50d2be0bfe57ac05406f10ac32b63a..85445b701b1c288e7d46bbac4bd7adeda0dc1163 100644 (file)
@@ -171,6 +171,11 @@ static int test_swap(void)
             || !equalBN("swap", b, c))
         goto err;
 
+    /* regular swap: same pointer */
+    BN_swap(a, a);
+    if (!equalBN("swap with same pointer", a, d))
+        goto err;
+
     /* conditional swap: true */
     cond = 1;
     BN_consttime_swap(cond, a, b, top);
@@ -178,6 +183,11 @@ static int test_swap(void)
             || !equalBN("cswap true", b, d))
         goto err;
 
+    /* conditional swap: true, same pointer */
+    BN_consttime_swap(cond, a, a, top);
+    if (!equalBN("cswap true", a, c))
+        goto err;
+
     /* conditional swap: false */
     cond = 0;
     BN_consttime_swap(cond, a, b, top);
@@ -185,6 +195,11 @@ static int test_swap(void)
             || !equalBN("cswap false", b, d))
         goto err;
 
+    /* conditional swap: false, same pointer */
+    BN_consttime_swap(cond, a, a, top);
+    if (!equalBN("cswap false", a, c))
+        goto err;
+
     /* same tests but checking flag swap */
     BN_set_flags(a, BN_FLG_CONSTTIME);