Check the return from BN_sub() in BN_X931_generate_Xpq().
authorPauli <paul.dale@oracle.com>
Sun, 2 Sep 2018 21:37:38 +0000 (07:37 +1000)
committerPauli <paul.dale@oracle.com>
Mon, 3 Sep 2018 00:43:01 +0000 (10:43 +1000)
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7088)

(cherry picked from commit 6bcfcf16bf6aef4f9ec267d8b86ae1bffd8deab9)

crypto/bn/bn_x931p.c

index 8bfbcac6a43dec52f64481c95ed27156edfc90eb..24f6a85befa24cffa6870faa291b1fb5f65119b0 100644 (file)
@@ -184,8 +184,10 @@ int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)
     for (i = 0; i < 1000; i++) {
         if (!BN_rand(Xq, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))
             goto err;
+
         /* Check that |Xp - Xq| > 2^(nbits - 100) */
-        BN_sub(t, Xp, Xq);
+        if (!BN_sub(t, Xp, Xq))
+            goto err;
         if (BN_num_bits(t) > (nbits - 100))
             break;
     }