Fix propq in x942kdf
authorShane Lontis <shane.lontis@oracle.com>
Tue, 22 Sep 2020 05:57:19 +0000 (15:57 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Wed, 23 Sep 2020 07:31:40 +0000 (17:31 +1000)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12944)

providers/implementations/kdfs/x942kdf.c

index 9dfa8693de902a48670b037529829db42d873ef7..4410ed8dd903fb87afcb7488c1c5343c9cf76de7 100644 (file)
@@ -67,13 +67,14 @@ static const struct {
 #endif
 };
 
-static int find_alg_id(OPENSSL_CTX *libctx, const char *algname, size_t *id)
+static int find_alg_id(OPENSSL_CTX *libctx, const char *algname,
+                       const char *propq, size_t *id)
 {
     int ret = 1;
     size_t i;
     EVP_CIPHER *cipher;
 
-    cipher = EVP_CIPHER_fetch(libctx, algname, NULL);
+    cipher = EVP_CIPHER_fetch(libctx, algname, propq);
     if (cipher != NULL) {
         for (i = 0; i < OSSL_NELEM(kek_algs); i++) {
             if (EVP_CIPHER_is_a(cipher, kek_algs[i].name)) {
@@ -381,9 +382,10 @@ static int x942kdf_derive(void *vctx, unsigned char *key, size_t keylen)
 
 static int x942kdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
 {
-    const OSSL_PARAM *p;
+    const OSSL_PARAM *p, *pq;
     KDF_X942 *ctx = vctx;
     OPENSSL_CTX *provctx = PROV_LIBRARY_CONTEXT_OF(ctx->provctx);
+    const char *propq = NULL;
     size_t id;
 
     if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx))
@@ -401,7 +403,14 @@ static int x942kdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
     if ((p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_CEK_ALG)) != NULL) {
         if (p->data_type != OSSL_PARAM_UTF8_STRING)
             return 0;
-        if (find_alg_id(provctx, p->data, &id) == 0)
+        pq = OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_PROPERTIES);
+        /*
+         * We already grab the properties during ossl_prov_digest_load_from_params()
+         * so there is no need to check the validity again..
+         */
+        if (pq != NULL)
+            propq = p->data;
+        if (find_alg_id(provctx, p->data, propq, &id) == 0)
             return 0;
         ctx->cek_oid = kek_algs[id].oid;
         ctx->cek_oid_len = kek_algs[id].oid_len;