Support EVP_MD_block_size() with providers
authorMatt Caswell <matt@openssl.org>
Thu, 28 Mar 2019 17:22:20 +0000 (17:22 +0000)
committerMatt Caswell <matt@openssl.org>
Wed, 3 Apr 2019 14:50:13 +0000 (15:50 +0100)
Fixes #8565

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8604)

crypto/err/openssl.txt
crypto/evp/digest.c
crypto/evp/evp_err.c
crypto/evp/evp_lib.c
crypto/include/internal/evp_int.h
include/openssl/core_numbers.h
include/openssl/evperr.h
providers/common/digests/sha2.c

index fbf35d14bf73fdcd92ef8ff565c87969c4938b1a..f15fc9c1bd9c3bc979be07d88bcc43b718ee61e1 100644 (file)
@@ -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
index 89f8e54a91b232b40e278dac7dde71b4929c2fa6..b93a014564f2d871e262036badc07b985a5844e8 100644 (file)
@@ -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)
index 6e72b6b427215ab3d5b41bd6cff6ab1552f13749..a3e01fdd5dfdef143345ab18d0e0f323812d2c75 100644 (file)
@@ -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"},
index f99e905e42af263f87428d41ddf37b63235df2da..914a19cc5e0abf729e0bd2823632bc5cc401f12f 100644 (file)
@@ -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;
 }
 
index ab8ce00e47f06ac044a496e842d37f91a031c881..c9328981393cf8182c0dedf189870e5b6b183f1e 100644 (file)
@@ -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 */ ;
 
index a7238547aa8da6546990f418050fadd4d83639ea..1e53627706bccdf4ed7012445814682055b4d265 100644 (file)
@@ -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
 }
index d60402cdc25fb3650f7350058fbbba97e2916826..317be14a133b05b79fd9e6668373d1c79ec60bf9 100644 (file)
@@ -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
index b538ab9c4a8a542cfdb592b852572f3f1d4549e9..4332e9818eae9adffbb02b09fac8763306589445 100644 (file)
@@ -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 }
 };