Add {get,set}table_params() functions for provider digests
authorRichard Levitte <levitte@openssl.org>
Mon, 12 Aug 2019 13:03:24 +0000 (15:03 +0200)
committerRichard Levitte <levitte@openssl.org>
Thu, 15 Aug 2019 08:51:40 +0000 (10:51 +0200)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9576)

providers/common/digests/sha2_prov.c
providers/common/digests/sha3_prov.c
providers/common/include/internal/core_mkdigest.h
providers/default/digests/md5_sha1_prov.c
providers/legacy/digests/mdc2_prov.c

index e823c27039c9f47d4005eb700ab382479947dc3e..0f359171ab50270cd4ee2f465afe42e0543dc1ec 100644 (file)
 #include "internal/sha.h"
 
 static OSSL_OP_digest_ctx_set_params_fn sha1_set_params;
+static OSSL_OP_digest_settable_ctx_params_fn sha1_settable_params;
+
+static const OSSL_PARAM known_sha1_ctx_params[] = {
+    {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
+    OSSL_PARAM_END
+};
+
+static const OSSL_PARAM *sha1_settable_params(void)
+{
+    return known_sha1_ctx_params;
+}
 
 /* Special set_params method for SSL3 */
 static int sha1_set_params(void *vctx, const OSSL_PARAM params[])
@@ -39,7 +50,7 @@ OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(sha1, SHA_CTX,
                            SHA_CBLOCK, SHA_DIGEST_LENGTH,
                            EVP_MD_FLAG_DIGALGID_ABSENT,
                            SHA1_Init, SHA1_Update, SHA1_Final,
-                           sha1_set_params)
+                           sha1_settable_params, sha1_set_params)
 
 OSSL_FUNC_DIGEST_CONSTRUCT(sha224, SHA256_CTX,
                            SHA256_CBLOCK, SHA224_DIGEST_LENGTH,
index 63a57dbcb321d9bb9cc256b8340470edae5744c7..bcef28c98c5c4825de4ed357f8166b0067296455 100644 (file)
@@ -26,7 +26,8 @@ static OSSL_OP_digest_update_fn keccak_update;
 static OSSL_OP_digest_final_fn keccak_final;
 static OSSL_OP_digest_freectx_fn keccak_freectx;
 static OSSL_OP_digest_dupctx_fn keccak_dupctx;
-static OSSL_OP_digest_ctx_set_params_fn shake_set_params;
+static OSSL_OP_digest_ctx_set_params_fn shake_ctx_set_params;
+static OSSL_OP_digest_settable_ctx_params_fn shake_settable_ctx_params;
 static sha3_absorb_fn generic_sha3_absorb;
 static sha3_final_fn generic_sha3_final;
 
@@ -203,8 +204,21 @@ static void *uname##_newctx(void *provctx) \
 }
 
 #define OSSL_FUNC_SHA3_DIGEST(name, bitlen, blksize, dgstsize, flags,   \
-                              stparams)                                 \
+                              stparamtypes, stparams)                   \
 static OSSL_OP_digest_get_params_fn name##_get_params;                  \
+static OSSL_OP_digest_gettable_params_fn name##_gettable_params;        \
+static const OSSL_PARAM known_##name##_gettable_params[] = {            \
+    {OSSL_DIGEST_PARAM_BLOCK_SIZE, OSSL_PARAM_INTEGER,                  \
+     NULL, sizeof(int), 0},                                             \
+    {OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0}, \
+    {OSSL_DIGEST_PARAM_FLAGS, OSSL_PARAM_INTEGER,                       \
+     NULL, sizeof(unsigned long), 0},                                   \
+    OSSL_PARAM_END                                                      \
+};                                                                      \
+static const OSSL_PARAM *name##_gettable_params(void)                   \
+{                                                                       \
+    return known_##name##_gettable_params;                              \
+}                                                                       \
 static int name##_get_params(OSSL_PARAM params[])                       \
 {                                                                       \
     OSSL_PARAM *p = NULL;                                               \
@@ -228,7 +242,11 @@ const OSSL_DISPATCH name##_functions[] = {                              \
     { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))keccak_freectx },       \
     { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))keccak_dupctx },         \
     { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, \
+    { OSSL_FUNC_DIGEST_GETTABLE_PARAMS,                                 \
+      (void (*)(void))name##_gettable_params },                         \
     { OSSL_FUNC_DIGEST_CTX_SET_PARAMS, (void (*)(void))stparams },      \
+    { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS,                             \
+      (void (*)(void))stparamtypes },                                   \
 OSSL_FUNC_DIGEST_CONSTRUCT_END
 
 static void keccak_freectx(void *vctx)
@@ -247,7 +265,17 @@ static void *keccak_dupctx(void *ctx)
     return ret;
 }
 
-static int shake_set_params(void *vctx, const OSSL_PARAM params[])
+static const OSSL_PARAM known_shake_settable_ctx_params[] = {
+    {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
+    OSSL_PARAM_END
+};
+
+static const OSSL_PARAM *shake_settable_ctx_params(void)
+{
+    return known_shake_settable_ctx_params;
+}
+
+static int shake_ctx_set_params(void *vctx, const OSSL_PARAM params[])
 {
     const OSSL_PARAM *p;
     KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
@@ -265,18 +293,20 @@ static int shake_set_params(void *vctx, const OSSL_PARAM params[])
     SHA3_newctx(sha3, SHA3_##bitlen, sha3_##bitlen, bitlen, '\x06') \
     OSSL_FUNC_SHA3_DIGEST(sha3_##bitlen, bitlen, \
                           SHA3_BLOCKSIZE(bitlen), SHA3_MDSIZE(bitlen), \
-                          EVP_MD_FLAG_DIGALGID_ABSENT, NULL)
+                          EVP_MD_FLAG_DIGALGID_ABSENT, NULL, NULL)
 
 #define SHAKE(bitlen) \
     SHA3_newctx(shake, SHAKE_##bitlen, shake_##bitlen, bitlen, '\x1f') \
     OSSL_FUNC_SHA3_DIGEST(shake_##bitlen, bitlen, \
                           SHA3_BLOCKSIZE(bitlen), SHA3_MDSIZE(bitlen), \
-                          EVP_MD_FLAG_XOF, shake_set_params)
+                          EVP_MD_FLAG_XOF, \
+                          shake_settable_ctx_params, shake_ctx_set_params)
 #define KMAC(bitlen) \
     KMAC_newctx(keccak_kmac_##bitlen, bitlen, '\x04') \
     OSSL_FUNC_SHA3_DIGEST(keccak_kmac_##bitlen, bitlen, \
                           SHA3_BLOCKSIZE(bitlen), KMAC_MDSIZE(bitlen), \
-                          EVP_MD_FLAG_XOF, shake_set_params)
+                          EVP_MD_FLAG_XOF, \
+                          shake_settable_ctx_params, shake_ctx_set_params)
 
 SHA3(224)
 SHA3(256)
index 8a077aec471aade09950eaa8a22d0bac300e6025..a8a99ae03674b2bd9fed1e39fece5ea4ff1be16e 100644 (file)
@@ -42,6 +42,19 @@ static void *name##_dupctx(void *ctx) \
 
 # define OSSL_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags)     \
 static OSSL_OP_digest_get_params_fn name##_get_params;                  \
+static OSSL_OP_digest_gettable_params_fn name##_gettable_params;        \
+static const OSSL_PARAM known_##name##_gettable_params[] = {            \
+    {OSSL_DIGEST_PARAM_BLOCK_SIZE, OSSL_PARAM_INTEGER,                  \
+     NULL, sizeof(int), 0},                                             \
+    {OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0}, \
+    {OSSL_DIGEST_PARAM_FLAGS, OSSL_PARAM_INTEGER,                       \
+     NULL, sizeof(unsigned long), 0},                                   \
+    OSSL_PARAM_END                                                      \
+};                                                                      \
+static const OSSL_PARAM *name##_gettable_params(void)                   \
+{                                                                       \
+    return known_##name##_gettable_params;                              \
+}                                                                       \
 static int name##_get_params(OSSL_PARAM params[])                       \
 {                                                                       \
     OSSL_PARAM *p = NULL;                                               \
@@ -77,7 +90,9 @@ const OSSL_DISPATCH name##_functions[] = { \
     { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_wrapfinal }, \
     { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \
     { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx }, \
-    { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params },
+    { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, \
+    { OSSL_FUNC_DIGEST_GETTABLE_PARAMS, \
+      (void (*)(void))name##_gettable_params },
 
 # define OSSL_FUNC_DIGEST_CONSTRUCT_END \
     { 0, NULL } \
@@ -99,9 +114,12 @@ OSSL_FUNC_DIGEST_CONSTRUCT_END
 
 # define OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(name, CTX,                   \
                                            blksize, dgstsize, flags,    \
-                                           init, upd, fin, setparams)   \
+                                           init, upd, fin,              \
+                                           setparamtypes, setparams)    \
 OSSL_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags,   \
                                  init, upd, fin)                        \
+    { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS,                             \
+      (void (*)(void))setparamtypes },                                  \
     { OSSL_FUNC_DIGEST_CTX_SET_PARAMS, (void (*)(void))setparams },     \
 OSSL_FUNC_DIGEST_CONSTRUCT_END
 
index 2ed36d03b3c6284712d365efdb35c786efa7b9af..de40993d93e0f796ee277feb3750c8eebd677949 100644 (file)
 #include "internal/md5_sha1.h"
 #include "internal/provider_algs.h"
 
-static OSSL_OP_digest_ctx_set_params_fn md5_sha1_set_params;
+static OSSL_OP_digest_ctx_set_params_fn md5_sha1_ctx_set_params;
+static OSSL_OP_digest_settable_ctx_params_fn md5_sha1_settable_ctx_params;
+
+static const OSSL_PARAM known_md5_sha1_settable_ctx_params[] = {
+    {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
+    OSSL_PARAM_END
+};
+
+static const OSSL_PARAM *md5_sha1_settable_ctx_params(void)
+{
+    return known_md5_sha1_settable_ctx_params;
+}
 
 /* Special set_params method for SSL3 */
-static int md5_sha1_set_params(void *vctx, const OSSL_PARAM params[])
+static int md5_sha1_ctx_set_params(void *vctx, const OSSL_PARAM params[])
 {
     const OSSL_PARAM *p;
     MD5_SHA1_CTX *ctx = (MD5_SHA1_CTX *)vctx;
@@ -37,4 +48,5 @@ static int md5_sha1_set_params(void *vctx, const OSSL_PARAM params[])
 OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(md5_sha1, MD5_SHA1_CTX,
                                   MD5_SHA1_CBLOCK, MD5_SHA1_DIGEST_LENGTH, 0,
                                   md5_sha1_init, md5_sha1_update, md5_sha1_final,
-                                  md5_sha1_set_params)
+                                  md5_sha1_settable_ctx_params,
+                                  md5_sha1_ctx_set_params)
index f77e3992b0813eddf9392db267394cdabcb40576..d779c967cde8467adf0c266ba1d229a7615a7192 100644 (file)
 #include "internal/core_mkdigest.h"
 #include "internal/provider_algs.h"
 
-static OSSL_OP_digest_ctx_set_params_fn mdc2_set_params;
+static OSSL_OP_digest_ctx_set_params_fn mdc2_ctx_set_params;
+static OSSL_OP_digest_settable_ctx_params_fn mdc2_settable_ctx_params;
 
-static int mdc2_set_params(void *vctx, const OSSL_PARAM params[])
+static const OSSL_PARAM known_mdc2_settable_ctx_params[] = {
+    {OSSL_DIGEST_PARAM_PAD_TYPE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0},
+    OSSL_PARAM_END
+};
+
+static const OSSL_PARAM *mdc2_settable_ctx_params(void)
+{
+    return known_mdc2_settable_ctx_params;
+}
+
+static int mdc2_ctx_set_params(void *vctx, const OSSL_PARAM params[])
 {
     const OSSL_PARAM *p;
     MDC2_CTX *ctx = (MDC2_CTX *)vctx;
@@ -34,4 +45,4 @@ static int mdc2_set_params(void *vctx, const OSSL_PARAM params[])
 OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(mdc2, MDC2_CTX,
                                   MDC2_BLOCK, MDC2_DIGEST_LENGTH, 0,
                                   MDC2_Init, MDC2_Update, MDC2_Final,
-                                  mdc2_set_params)
+                                  mdc2_settable_ctx_params, mdc2_ctx_set_params)