]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
prov: update digests to support modified ctx params
authorPauli <ppzgs1@gmail.com>
Tue, 2 Mar 2021 23:20:21 +0000 (09:20 +1000)
committerPauli <ppzgs1@gmail.com>
Thu, 11 Mar 2021 22:27:21 +0000 (08:27 +1000)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14383)

providers/implementations/digests/md5_sha1_prov.c
providers/implementations/digests/mdc2_prov.c
providers/implementations/digests/sha2_prov.c
providers/implementations/digests/sha3_prov.c

index e41ac815c5830c0b676b599ae82cd98fa8f74b50..e7b8389b2b5c7b7eb97f0ed9425d17d3fb028ede 100644 (file)
@@ -42,13 +42,16 @@ static int md5_sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])
     const OSSL_PARAM *p;
     MD5_SHA1_CTX *ctx = (MD5_SHA1_CTX *)vctx;
 
-    if (ctx != NULL && params != NULL) {
-        p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
-        if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
-            return ossl_md5_sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET,
-                                      p->data_size, p->data);
-    }
-    return 0;
+    if (ctx == NULL)
+        return 0;
+    if (params == NULL)
+        return 1;
+
+    p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
+    if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
+        return ossl_md5_sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET,
+                                  p->data_size, p->data);
+    return 1;
 }
 
 /* ossl_md5_sha1_functions */
index edd73ed89ee4b4ac309429221ff4b121b7a8a214..de39f8a10482e55784af8628fc00d2dde28b2505 100644 (file)
@@ -41,15 +41,17 @@ static int mdc2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
     const OSSL_PARAM *p;
     MDC2_CTX *ctx = (MDC2_CTX *)vctx;
 
-    if (ctx != NULL && params != NULL) {
-        p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_PAD_TYPE);
-        if (p != NULL && !OSSL_PARAM_get_uint(p, &ctx->pad_type)) {
-            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
-            return 0;
-        }
+    if (ctx == NULL)
+        return 0;
+    if (params == NULL)
         return 1;
+
+    p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_PAD_TYPE);
+    if (p != NULL && !OSSL_PARAM_get_uint(p, &ctx->pad_type)) {
+        ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
+        return 0;
     }
-    return 0; /* Null Parameter */
+    return 1;
 }
 
 /* ossl_mdc2_functions */
index 96f4cc700497d5fe9a4e34340fad4f0a326ac60c..3b731796bdc4a5441760a0dac8f00e1667539d0a 100644 (file)
@@ -45,13 +45,16 @@ static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])
     const OSSL_PARAM *p;
     SHA_CTX *ctx = (SHA_CTX *)vctx;
 
-    if (ctx != NULL && params != NULL) {
-        p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
-        if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
-            return ossl_sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET,
-                                  p->data_size, p->data);
-    }
-    return 0;
+    if (ctx == NULL)
+        return 0;
+    if (params == NULL)
+        return 1;
+
+    p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
+    if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
+        return ossl_sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET,
+                              p->data_size, p->data);
+    return 1;
 }
 
 /* ossl_sha1_functions */
index 0db6f86be85bf86f1c5c0f6edb69db5f5cfe5813..168825d47564e9c2e4626b637a85165a9dd1b395 100644 (file)
@@ -284,15 +284,17 @@ static int shake_set_ctx_params(void *vctx, const OSSL_PARAM params[])
     const OSSL_PARAM *p;
     KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
 
-    if (ctx != NULL && params != NULL) {
-        p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_XOFLEN);
-        if (p != NULL && !OSSL_PARAM_get_size_t(p, &ctx->md_size)) {
-            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
-            return 0;
-        }
+    if (ctx == NULL)
+        return 0;
+    if (params == NULL)
         return 1;
+
+    p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_XOFLEN);
+    if (p != NULL && !OSSL_PARAM_get_size_t(p, &ctx->md_size)) {
+        ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
+        return 0;
     }
-    return 0; /* Null Parameter */
+    return 1;
 }
 
 #define IMPLEMENT_SHA3_functions(bitlen)                                       \