[openssl-commits] [openssl] master update

Paul I. Dale pauli at openssl.org
Sun Oct 7 21:15:00 UTC 2018


The branch master has been updated
       via  b770a80f6d0b08659cd03f26388b45512adb84f3 (commit)
      from  470096e576941566fd094f2fd793dc2948804ea8 (commit)


- Log -----------------------------------------------------------------
commit b770a80f6d0b08659cd03f26388b45512adb84f3
Author: Mykola Baibuz <nb at cipher.kiev.ua>
Date:   Mon Oct 8 07:14:08 2018 +1000

    Remove useless check.
    Hash can be longer than EC group degree and it will be truncated.
    
    CLA: trivial
    
    Reviewed-by: Paul Yang <yang.yang at baishancloud.com>
    Reviewed-by: Paul Dale <paul.dale at oracle.com>
    (Merged from https://github.com/openssl/openssl/pull/7329)

-----------------------------------------------------------------------

Summary of changes:
 test/ecdsatest.c | 60 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/test/ecdsatest.c b/test/ecdsatest.c
index c4bcb8e..95b642b 100644
--- a/test/ecdsatest.c
+++ b/test/ecdsatest.c
@@ -13,7 +13,7 @@
 #include <string.h>
 
 #include <openssl/opensslconf.h> /* To see if OPENSSL_NO_EC is defined */
-# include "testutil.h"
+#include "testutil.h"
 
 #ifndef OPENSSL_NO_EC
 
@@ -103,7 +103,7 @@ static int x9_62_test_internal(int nid, const char *r_in, const char *s_in)
 {
     int ret = 0;
     const char message[] = "abc";
-    unsigned char digest[20];
+    unsigned char digest[SHA_DIGEST_LENGTH];
     unsigned int dgst_len = 0;
     EVP_MD_CTX *md_ctx;
     EC_KEY *key = NULL;
@@ -135,7 +135,8 @@ static int x9_62_test_internal(int nid, const char *r_in, const char *s_in)
     /* Use ECDSA_sign_setup to avoid use of ECDSA nonces */
     if (!TEST_true(ECDSA_sign_setup(key, NULL, &kinv, &rp)))
         goto x962_int_err;
-    if (!TEST_ptr(signature = ECDSA_do_sign_ex(digest, 20, kinv, rp, key)))
+	if (!TEST_ptr(signature =
+                  ECDSA_do_sign_ex(digest, SHA_DIGEST_LENGTH, kinv, rp, key)))
         goto x962_int_err;
 
     /* compare the created signature with the expected signature */
@@ -149,7 +150,8 @@ static int x9_62_test_internal(int nid, const char *r_in, const char *s_in)
         goto x962_int_err;
 
     /* verify the signature */
-    if (!TEST_int_eq(ECDSA_do_verify(digest, 20, signature, key), 1))
+    if (!TEST_int_eq(ECDSA_do_verify(digest, SHA_DIGEST_LENGTH,
+		signature, key), 1))
         goto x962_int_err;
 
     ret = 1;
@@ -211,7 +213,8 @@ static int test_builtin(void)
     EC_KEY *eckey = NULL, *wrong_eckey = NULL;
     EC_GROUP *group;
     ECDSA_SIG *ecdsa_sig = NULL, *modified_sig = NULL;
-    unsigned char digest[20], wrong_digest[20];
+    unsigned char digest[SHA512_DIGEST_LENGTH],
+             wrong_digest[SHA512_DIGEST_LENGTH];
     unsigned char *signature = NULL;
     const unsigned char *sig_ptr;
     unsigned char *sig_ptr2;
@@ -223,8 +226,8 @@ static int test_builtin(void)
     int nid, ret = 0;
 
     /* fill digest values with some random data */
-    if (!TEST_true(RAND_bytes(digest, 20))
-            || !TEST_true(RAND_bytes(wrong_digest, 20)))
+    if (!TEST_true(RAND_bytes(digest, SHA512_DIGEST_LENGTH))
+            || !TEST_true(RAND_bytes(wrong_digest, SHA512_DIGEST_LENGTH)))
         goto builtin_err;
 
     /* create and verify a ecdsa signature with every available curve */
@@ -239,7 +242,7 @@ static int test_builtin(void)
         unsigned char dirt, offset;
 
         nid = curves[n].nid;
-        if (nid == NID_ipsec4)
+        if (nid == NID_ipsec4 || nid == NID_ipsec3)
             continue;
         /* create new ecdsa key (== EC_KEY) */
         if (!TEST_ptr(eckey = EC_KEY_new())
@@ -248,12 +251,7 @@ static int test_builtin(void)
             goto builtin_err;
         EC_GROUP_free(group);
         degree = EC_GROUP_get_degree(EC_KEY_get0_group(eckey));
-        if (degree < 160) {
-            /* drop the curve */
-            EC_KEY_free(eckey);
-            eckey = NULL;
-            continue;
-        }
+
         TEST_info("testing %s", OBJ_nid2sn(nid));
 
         /* create key */
@@ -275,28 +273,32 @@ static int test_builtin(void)
         /* create signature */
         sig_len = ECDSA_size(eckey);
         if (!TEST_ptr(signature = OPENSSL_malloc(sig_len))
-                || !TEST_true(ECDSA_sign(0, digest, 20, signature, &sig_len,
-                                         eckey)))
+			|| !TEST_true(ECDSA_sign(0, digest, SHA512_DIGEST_LENGTH,
+                                      signature, &sig_len, eckey)))
             goto builtin_err;
 
         /* verify signature */
-        if (!TEST_int_eq(ECDSA_verify(0, digest, 20, signature, sig_len,
-                                      eckey), 1))
+        if (!TEST_int_eq(ECDSA_verify(0, digest, SHA512_DIGEST_LENGTH,
+                                      signature, sig_len, eckey),
+                         1))
             goto builtin_err;
 
         /* verify signature with the wrong key */
-        if (!TEST_int_ne(ECDSA_verify(0, digest, 20, signature, sig_len,
-                                      wrong_eckey), 1))
+        if (!TEST_int_ne(ECDSA_verify(0, digest, SHA512_DIGEST_LENGTH,
+                                      signature, sig_len, wrong_eckey),
+                         1))
             goto builtin_err;
 
         /* wrong digest */
-        if (!TEST_int_ne(ECDSA_verify(0, wrong_digest, 20, signature,
-                                      sig_len, eckey), 1))
+        if (!TEST_int_ne(ECDSA_verify(0, wrong_digest, SHA512_DIGEST_LENGTH,
+                                      signature, sig_len, eckey),
+                         1))
             goto builtin_err;
 
         /* wrong length */
-        if (!TEST_int_ne(ECDSA_verify(0, digest, 20, signature,
-                                      sig_len - 1, eckey), 1))
+        if (!TEST_int_ne(ECDSA_verify(0, digest, SHA512_DIGEST_LENGTH,
+                                      signature, sig_len - 1, eckey),
+                         1))
             goto builtin_err;
 
         /*
@@ -333,7 +335,7 @@ static int test_builtin(void)
             goto builtin_err;
         if (!TEST_ptr(modified_r = BN_bin2bn(raw_buf, bn_len, NULL))
                 || !TEST_ptr(modified_s = BN_bin2bn(raw_buf + bn_len,
-                                                    bn_len, NULL))
+                                          bn_len, NULL))
                 || !TEST_true(ECDSA_SIG_set0(modified_sig,
                                              modified_r, modified_s))) {
             BN_free(modified_r);
@@ -342,14 +344,15 @@ static int test_builtin(void)
         }
         sig_ptr2 = signature;
         sig_len = i2d_ECDSA_SIG(modified_sig, &sig_ptr2);
-        if (!TEST_false(ECDSA_verify(0, digest, 20, signature, sig_len, eckey)))
+        if (!TEST_false(ECDSA_verify(0, digest, SHA512_DIGEST_LENGTH,
+                                     signature, sig_len, eckey)))
             goto builtin_err;
 
         /* Sanity check: undo the modification and verify signature. */
         raw_buf[offset] ^= dirt;
         if (!TEST_ptr(unmodified_r = BN_bin2bn(raw_buf, bn_len, NULL))
                 || !TEST_ptr(unmodified_s = BN_bin2bn(raw_buf + bn_len,
-                                                       bn_len, NULL))
+                                            bn_len, NULL))
                 || !TEST_true(ECDSA_SIG_set0(modified_sig, unmodified_r,
                                              unmodified_s))) {
             BN_free(unmodified_r);
@@ -359,7 +362,8 @@ static int test_builtin(void)
 
         sig_ptr2 = signature;
         sig_len = i2d_ECDSA_SIG(modified_sig, &sig_ptr2);
-        if (!TEST_true(ECDSA_verify(0, digest, 20, signature, sig_len, eckey)))
+        if (!TEST_true(ECDSA_verify(0, digest, SHA512_DIGEST_LENGTH,
+                                    signature, sig_len, eckey)))
             goto builtin_err;
 
         /* cleanup */


More information about the openssl-commits mailing list