[openssl] master update

Matt Caswell matt at openssl.org
Wed Apr 3 14:54:26 UTC 2019


The branch master has been updated
       via  64f4fff7967057ba2b963bd0a6ad5cdc64f27417 (commit)
       via  7556b9df597ce43c1c31b294512d5146560f37c6 (commit)
      from  5a2bd6bc66a902ed7aa681e93f0e339c0441e228 (commit)


- Log -----------------------------------------------------------------
commit 64f4fff7967057ba2b963bd0a6ad5cdc64f27417
Author: Matt Caswell <matt at openssl.org>
Date:   Fri Mar 29 15:38:10 2019 +0000

    Add a test for EVP_MD_block_size()
    
    Reviewed-by: Paul Dale <paul.dale at oracle.com>
    (Merged from https://github.com/openssl/openssl/pull/8604)

commit 7556b9df597ce43c1c31b294512d5146560f37c6
Author: Matt Caswell <matt at openssl.org>
Date:   Thu Mar 28 17:22:20 2019 +0000

    Support EVP_MD_block_size() with providers
    
    Fixes #8565
    
    Reviewed-by: Paul Dale <paul.dale at oracle.com>
    (Merged from https://github.com/openssl/openssl/pull/8604)

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

Summary of changes:
 crypto/err/openssl.txt            |  1 +
 crypto/evp/digest.c               |  5 +++++
 crypto/evp/evp_err.c              |  1 +
 crypto/evp/evp_lib.c              |  8 ++++++++
 crypto/include/internal/evp_int.h |  1 +
 include/openssl/core_numbers.h    |  2 ++
 include/openssl/evperr.h          |  1 +
 providers/common/digests/sha2.c   |  6 ++++++
 test/evp_extra_test.c             | 13 ++++++++++---
 9 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt
index fbf35d1..f15fc9c 100644
--- a/crypto/err/openssl.txt
+++ b/crypto/err/openssl.txt
@@ -800,6 +800,7 @@ EVP_F_EVP_MAC_CTRL_STR:210:EVP_MAC_ctrl_str
 EVP_F_EVP_MAC_CTX_COPY:211:EVP_MAC_CTX_copy
 EVP_F_EVP_MAC_CTX_NEW:213:EVP_MAC_CTX_new
 EVP_F_EVP_MAC_INIT:212:EVP_MAC_init
+EVP_F_EVP_MD_BLOCK_SIZE:229:EVP_MD_block_size
 EVP_F_EVP_MD_CTX_COPY_EX:110:EVP_MD_CTX_copy_ex
 EVP_F_EVP_MD_SIZE:162:EVP_MD_size
 EVP_F_EVP_OPENINIT:102:EVP_OpenInit
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index 89f8e54..b93a014 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -549,6 +549,11 @@ static void *evp_md_from_dispatch(int mdtype, const OSSL_DISPATCH *fns,
                 break;
             md->size = OSSL_get_OP_digest_size(fns);
             break;
+        case OSSL_FUNC_DIGEST_BLOCK_SIZE:
+            if (md->dblock_size != NULL)
+                break;
+            md->dblock_size = OSSL_get_OP_digest_block_size(fns);
+            break;
         }
     }
     if ((fncnt != 0 && fncnt != 5)
diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c
index 6e72b6b..a3e01fd 100644
--- a/crypto/evp/evp_err.c
+++ b/crypto/evp/evp_err.c
@@ -71,6 +71,7 @@ static const ERR_STRING_DATA EVP_str_functs[] = {
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_CTX_COPY, 0), "EVP_MAC_CTX_copy"},
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_CTX_NEW, 0), "EVP_MAC_CTX_new"},
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_INIT, 0), "EVP_MAC_init"},
+    {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MD_BLOCK_SIZE, 0), "EVP_MD_block_size"},
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MD_CTX_COPY_EX, 0), "EVP_MD_CTX_copy_ex"},
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MD_SIZE, 0), "EVP_MD_size"},
     {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_OPENINIT, 0), "EVP_OpenInit"},
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c
index f99e905..914a19c 100644
--- a/crypto/evp/evp_lib.c
+++ b/crypto/evp/evp_lib.c
@@ -298,6 +298,14 @@ int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
 
 int EVP_MD_block_size(const EVP_MD *md)
 {
+    if (md == NULL) {
+        EVPerr(EVP_F_EVP_MD_BLOCK_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);
+        return -1;
+    }
+
+    if (md->prov != NULL && md->dblock_size != NULL)
+        return (int)md->dblock_size();
+
     return md->block_size;
 }
 
diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h
index ab8ce00..c932898 100644
--- a/crypto/include/internal/evp_int.h
+++ b/crypto/include/internal/evp_int.h
@@ -204,6 +204,7 @@ struct evp_md_st {
     OSSL_OP_digest_freectx_fn *freectx;
     OSSL_OP_digest_dupctx_fn *dupctx;
     OSSL_OP_digest_size_fn *size;
+    OSSL_OP_digest_block_size_fn *dblock_size;
 
 } /* EVP_MD */ ;
 
diff --git a/include/openssl/core_numbers.h b/include/openssl/core_numbers.h
index a723854..1e53627 100644
--- a/include/openssl/core_numbers.h
+++ b/include/openssl/core_numbers.h
@@ -84,6 +84,7 @@ OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation,
 # define OSSL_FUNC_DIGEST_FREECTX           6
 # define OSSL_FUNC_DIGEST_DUPCTX            7
 # define OSSL_FUNC_DIGEST_SIZE              8
+# define OSSL_FUNC_DIGEST_BLOCK_SIZE        9
 
 OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void))
 OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *vctx))
@@ -98,6 +99,7 @@ OSSL_CORE_MAKE_FUNC(void, OP_digest_cleanctx, (void *vctx))
 OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *vctx))
 OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *vctx))
 OSSL_CORE_MAKE_FUNC(size_t, OP_digest_size, (void))
+OSSL_CORE_MAKE_FUNC(size_t, OP_digest_block_size, (void))
 
 # ifdef __cplusplus
 }
diff --git a/include/openssl/evperr.h b/include/openssl/evperr.h
index d60402c..317be14 100644
--- a/include/openssl/evperr.h
+++ b/include/openssl/evperr.h
@@ -70,6 +70,7 @@ int ERR_load_EVP_strings(void);
 # define EVP_F_EVP_MAC_CTX_COPY                           211
 # define EVP_F_EVP_MAC_CTX_NEW                            213
 # define EVP_F_EVP_MAC_INIT                               212
+# define EVP_F_EVP_MD_BLOCK_SIZE                          229
 # define EVP_F_EVP_MD_CTX_COPY_EX                         110
 # define EVP_F_EVP_MD_SIZE                                162
 # define EVP_F_EVP_OPENINIT                               102
diff --git a/providers/common/digests/sha2.c b/providers/common/digests/sha2.c
index b538ab9..4332e98 100644
--- a/providers/common/digests/sha2.c
+++ b/providers/common/digests/sha2.c
@@ -50,6 +50,11 @@ static size_t sha256_size(void)
     return SHA256_DIGEST_LENGTH;
 }
 
+static size_t sha256_block_size(void)
+{
+    return SHA256_CBLOCK;
+}
+
 extern const OSSL_DISPATCH sha256_functions[];
 const OSSL_DISPATCH sha256_functions[] = {
     { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))sha256_newctx },
@@ -59,5 +64,6 @@ const OSSL_DISPATCH sha256_functions[] = {
     { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))sha256_freectx },
     { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))sha256_dupctx },
     { OSSL_FUNC_DIGEST_SIZE, (void (*)(void))sha256_size },
+    { OSSL_FUNC_DIGEST_BLOCK_SIZE, (void (*)(void))sha256_block_size },
     { 0, NULL }
 };
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index f763bb5..d09eb31 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -1126,8 +1126,11 @@ static int test_EVP_MD_fetch(int tst)
 
     /* Implicit fetching of the MD should produce the expected result */
     if (!TEST_true(calculate_digest(EVP_sha256(), testmsg, sizeof(testmsg),
-                                    exptd)))
+                                    exptd))
+            || !TEST_int_eq(EVP_MD_size(EVP_sha256()), SHA256_DIGEST_LENGTH)
+            || !TEST_int_eq(EVP_MD_block_size(EVP_sha256()), SHA256_CBLOCK))
         goto err;
+
     /*
      * Test that without loading any providers or specifying any properties we
      * can get a sha256 md from the default provider.
@@ -1135,7 +1138,9 @@ static int test_EVP_MD_fetch(int tst)
     if (!TEST_ptr(md = EVP_MD_fetch(ctx, "SHA256", NULL))
             || !TEST_ptr(md)
             || !TEST_int_eq(EVP_MD_nid(md), NID_sha256)
-            || !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd)))
+            || !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd))
+            || !TEST_int_eq(EVP_MD_size(md), SHA256_DIGEST_LENGTH)
+            || !TEST_int_eq(EVP_MD_block_size(md), SHA256_CBLOCK))
         goto err;
 
     /* Also test EVP_MD_upref() while we're doing this */
@@ -1156,7 +1161,9 @@ static int test_EVP_MD_fetch(int tst)
     /* Explicitly asking for the default implementation should succeeed */
     if (!TEST_ptr(md = EVP_MD_fetch(ctx, "SHA256", "default=yes"))
             || !TEST_int_eq(EVP_MD_nid(md), NID_sha256)
-            || !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd)))
+            || !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd))
+            || !TEST_int_eq(EVP_MD_size(md), SHA256_DIGEST_LENGTH)
+            || !TEST_int_eq(EVP_MD_block_size(md), SHA256_CBLOCK))
         goto err;
 
     EVP_MD_meth_free(md);


More information about the openssl-commits mailing list