summaryrefslogtreecommitdiffstats
path: root/providers/common
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2019-09-14 16:35:08 +0200
committerRichard Levitte <levitte@openssl.org>2019-09-19 14:58:17 +0200
commit7cfa1717b812a126ce6f8e4cc32139164c89d789 (patch)
tree6baeb081c8d404bb4e82cabe0d42b5c78a356e19 /providers/common
parentf7c16d48a945e80f22f6f02550ee3fe14edb52fa (diff)
Modify providers that keep track of underlying algorithms
With some provider implementations, there are underlying ciphers, digests and macs. For some of them, the name was retrieved from the method, but since the methods do not store those any more, we add different mechanics. For code that needs to pass on the name of a cipher or diges via parameters, we simply locally store the name that was used when fetching said cipher or digest. This will ensure that any underlying code that needs to fetch that same cipher or digest does so with the exact same name instead of any random name from the set of names associated with the algorithm. For code that needs to check what kind of algorithm was passed, we provide EVP_{type}_is_a(), that returns true if the given method has the given name as one of its names. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9897)
Diffstat (limited to 'providers/common')
-rw-r--r--providers/common/include/internal/provider_util.h16
-rw-r--r--providers/common/kdfs/sskdf.c10
-rw-r--r--providers/common/provider_util.c15
3 files changed, 31 insertions, 10 deletions
diff --git a/providers/common/include/internal/provider_util.h b/providers/common/include/internal/provider_util.h
index c25c65886e..9fe21c5ef6 100644
--- a/providers/common/include/internal/provider_util.h
+++ b/providers/common/include/internal/provider_util.h
@@ -21,6 +21,9 @@ typedef struct {
/* Conditions for legacy EVP_CIPHER uses */
ENGINE *engine; /* cipher engine */
+
+ /* Name this was fetched by */
+ char name[51]; /* A longer name would be unexpected */
} PROV_CIPHER;
typedef struct {
@@ -34,6 +37,9 @@ typedef struct {
/* Conditions for legacy EVP_MD uses */
ENGINE *engine; /* digest engine */
+
+ /* Name this was fetched by */
+ char name[51]; /* A longer name would be unexpected */
} PROV_DIGEST;
/* Cipher functions */
@@ -43,19 +49,20 @@ typedef struct {
* implementation used. If a provider cannot be found, it falls back to trying
* non-provider based implementations.
*/
-int ossl_prov_cipher_load_from_params(PROV_CIPHER *pd,
+int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
const OSSL_PARAM params[],
OPENSSL_CTX *ctx);
/* Reset the PROV_CIPHER fields and free any allocated cipher reference */
-void ossl_prov_cipher_reset(PROV_CIPHER *pd);
+void ossl_prov_cipher_reset(PROV_CIPHER *pc);
/* Clone a PROV_CIPHER structure into a second */
int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src);
/* Query the cipher and associated engine (if any) */
-const EVP_CIPHER *ossl_prov_cipher_cipher(const PROV_CIPHER *pd);
-ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pd);
+const EVP_CIPHER *ossl_prov_cipher_cipher(const PROV_CIPHER *pc);
+ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pc);
+const char *ossl_prov_cipher_name(const PROV_CIPHER *pc);
/* Digest functions */
/*
@@ -77,3 +84,4 @@ int ossl_prov_digest_copy(PROV_DIGEST *dst, const PROV_DIGEST *src);
/* Query the digest and associated engine (if any) */
const EVP_MD *ossl_prov_digest_md(const PROV_DIGEST *pd);
ENGINE *ossl_prov_digest_engine(const PROV_DIGEST *pd);
+const char *ossl_prov_digest_name(const PROV_DIGEST *pd);
diff --git a/providers/common/kdfs/sskdf.c b/providers/common/kdfs/sskdf.c
index e7921bac35..49da1a690f 100644
--- a/providers/common/kdfs/sskdf.c
+++ b/providers/common/kdfs/sskdf.c
@@ -370,7 +370,6 @@ static int sskdf_derive(void *vctx, unsigned char *key, size_t keylen)
int ret;
const unsigned char *custom = NULL;
size_t custom_len = 0;
- const char *macname;
int default_salt_len;
/*
@@ -378,8 +377,7 @@ static int sskdf_derive(void *vctx, unsigned char *key, size_t keylen)
* Why does KMAC require a salt length that's shorter than the MD
* block size?
*/
- macname = EVP_MAC_name(ctx->mac);
- if (strcmp(macname, OSSL_MAC_NAME_HMAC) == 0) {
+ if (EVP_MAC_is_a(ctx->mac, OSSL_MAC_NAME_HMAC)) {
/* H(x) = HMAC(x, salt, hash) */
if (md == NULL) {
ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
@@ -388,12 +386,12 @@ static int sskdf_derive(void *vctx, unsigned char *key, size_t keylen)
default_salt_len = EVP_MD_block_size(md);
if (default_salt_len <= 0)
return 0;
- } else if (strcmp(macname, OSSL_MAC_NAME_KMAC128) == 0
- || strcmp(macname, OSSL_MAC_NAME_KMAC256) == 0) {
+ } else if (EVP_MAC_is_a(ctx->mac, OSSL_MAC_NAME_KMAC128)
+ || EVP_MAC_is_a(ctx->mac, OSSL_MAC_NAME_KMAC256)) {
/* H(x) = KMACzzz(x, salt, custom) */
custom = kmac_custom_str;
custom_len = sizeof(kmac_custom_str);
- if (strcmp(macname, OSSL_MAC_NAME_KMAC128) == 0)
+ if (EVP_MAC_is_a(ctx->mac, OSSL_MAC_NAME_KMAC128))
default_salt_len = SSKDF_KMAC128_DEFAULT_SALT_SIZE;
else
default_salt_len = SSKDF_KMAC256_DEFAULT_SALT_SIZE;
diff --git a/providers/common/provider_util.c b/providers/common/provider_util.c
index 92cfb749c0..199544730a 100644
--- a/providers/common/provider_util.c
+++ b/providers/common/provider_util.c
@@ -17,6 +17,7 @@ void ossl_prov_cipher_reset(PROV_CIPHER *pc)
pc->alloc_cipher = NULL;
pc->cipher = NULL;
pc->engine = NULL;
+ pc->name[0] = '\0';
}
int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src)
@@ -26,6 +27,7 @@ int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src)
dst->engine = src->engine;
dst->cipher = src->cipher;
dst->alloc_cipher = src->alloc_cipher;
+ OPENSSL_strlcpy(dst->name, src->name, sizeof(dst->name));
return 1;
}
@@ -77,6 +79,7 @@ int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
EVP_CIPHER_free(pc->alloc_cipher);
pc->cipher = pc->alloc_cipher = EVP_CIPHER_fetch(ctx, p->data, propquery);
+ OPENSSL_strlcpy(pc->name, p->data, sizeof(pc->name));
/* TODO legacy stuff, to be removed */
#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy ciphers */
if (pc->cipher == NULL)
@@ -95,12 +98,18 @@ ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pc)
return pc->engine;
}
+const char *ossl_prov_cipher_name(const PROV_CIPHER *pc)
+{
+ return pc->name;
+}
+
void ossl_prov_digest_reset(PROV_DIGEST *pd)
{
EVP_MD_free(pd->alloc_md);
pd->alloc_md = NULL;
pd->md = NULL;
pd->engine = NULL;
+ pd->name[0] = '\0';
}
int ossl_prov_digest_copy(PROV_DIGEST *dst, const PROV_DIGEST *src)
@@ -110,6 +119,7 @@ int ossl_prov_digest_copy(PROV_DIGEST *dst, const PROV_DIGEST *src)
dst->engine = src->engine;
dst->md = src->md;
dst->alloc_md = src->alloc_md;
+ OPENSSL_strlcpy(dst->name, src->name, sizeof(dst->name));
return 1;
}
@@ -132,6 +142,7 @@ int ossl_prov_digest_load_from_params(PROV_DIGEST *pd,
EVP_MD_free(pd->alloc_md);
pd->md = pd->alloc_md = EVP_MD_fetch(ctx, p->data, propquery);
+ OPENSSL_strlcpy(pd->name, p->data, sizeof(pd->name));
/* TODO legacy stuff, to be removed */
#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy digests */
if (pd->md == NULL)
@@ -150,3 +161,7 @@ ENGINE *ossl_prov_digest_engine(const PROV_DIGEST *pd)
return pd->engine;
}
+const char *ossl_prov_digest_name(const PROV_DIGEST *pd)
+{
+ return pd->name;
+}