Fix incorrect return check of BN_bn2binpad
authorPW Hu <jlu.hpw@foxmail.com>
Mon, 1 Nov 2021 07:00:54 +0000 (15:00 +0800)
committerPauli <pauli@openssl.org>
Sun, 7 Nov 2021 22:53:02 +0000 (08:53 +1000)
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16942)

crypto/ec/ec_deprecated.c
test/acvp_test.c
test/ecdsatest.c

index cd2eec80b7938ecd709b33c73214065eff2ebf85..22ddb3660ca2570599bf71b40c4bf8740bf0d8c4 100644 (file)
@@ -52,7 +52,7 @@ EC_POINT *EC_POINT_bn2point(const EC_GROUP *group,
         return NULL;
     }
 
-    if (!BN_bn2binpad(bn, buf, buf_len)) {
+    if (BN_bn2binpad(bn, buf, buf_len) < 0) {
         OPENSSL_free(buf);
         return NULL;
     }
index 6512a6ec35574c389a2c144a38d3a757324dd821..4b6632e6890460fd501dc3497cdae9cce1435e65 100644 (file)
@@ -71,7 +71,7 @@ static int pkey_get_bn_bytes(EVP_PKEY *pkey, const char *name,
     buf = OPENSSL_zalloc(sz);
     if (buf == NULL)
         goto err;
-    if (!BN_bn2binpad(bn, buf, sz))
+    if (BN_bn2binpad(bn, buf, sz) <= 0)
         goto err;
 
     *out_len = sz;
index c94d7d8dabf5bb318287cb6244d951cadda18ca6..282b9660d315ff5da965b33347e07b503e0504fe 100644 (file)
@@ -46,7 +46,7 @@ static int fbytes(unsigned char *buf, size_t num, ossl_unused const char *name,
         || !TEST_true(BN_hex2bn(&tmp, numbers[fbytes_counter]))
         /* tmp might need leading zeros so pad it out */
         || !TEST_int_le(BN_num_bytes(tmp), num)
-        || !TEST_true(BN_bn2binpad(tmp, buf, num)))
+        || !TEST_int_gt(BN_bn2binpad(tmp, buf, num), 0))
         goto err;
 
     fbytes_counter = (fbytes_counter + 1) % OSSL_NELEM(numbers);