From: Chenghai Huang huangchenghai2@huawei.com
The UADK can identify only the sha512-XXX algorithm name and needs to perform additional processing.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com Signed-off-by: JiangShui Yang yangjiangshui@h-partners.com --- src/uadk_prov.h | 19 ++++++++++++------- src/uadk_prov_digest.c | 21 +++++++++++++++++++-- src/uadk_prov_init.c | 4 ++++ 3 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/src/uadk_prov.h b/src/uadk_prov.h index 8d1b712..e5ac61f 100644 --- a/src/uadk_prov.h +++ b/src/uadk_prov.h @@ -18,6 +18,8 @@ #ifndef UADK_PROV_H #define UADK_PROV_H
+#define FUNC_MAX_NUM 32 + /* Copy openssl/providers/implementations/include/prov/names.h */ #define PROV_NAMES_SHA2_224 "SHA2-224:SHA-224:SHA224:2.16.840.1.101.3.4.2.4" #define PROV_NAMES_SHA2_256 "SHA2-256:SHA-256:SHA256:2.16.840.1.101.3.4.2.1" @@ -98,13 +100,16 @@ static inline OSSL_LIB_CTX *prov_libctx_of(struct uadk_prov_ctx *ctx) return ctx->libctx; }
-extern const OSSL_DISPATCH uadk_md5_functions[]; -extern const OSSL_DISPATCH uadk_sm3_functions[]; -extern const OSSL_DISPATCH uadk_sha1_functions[]; -extern const OSSL_DISPATCH uadk_sha224_functions[]; -extern const OSSL_DISPATCH uadk_sha256_functions[]; -extern const OSSL_DISPATCH uadk_sha384_functions[]; -extern const OSSL_DISPATCH uadk_sha512_functions[]; +extern const OSSL_DISPATCH uadk_md5_functions[FUNC_MAX_NUM]; +extern const OSSL_DISPATCH uadk_sm3_functions[FUNC_MAX_NUM]; +extern const OSSL_DISPATCH uadk_sha1_functions[FUNC_MAX_NUM]; +extern const OSSL_DISPATCH uadk_sha224_functions[FUNC_MAX_NUM]; +extern const OSSL_DISPATCH uadk_sha256_functions[FUNC_MAX_NUM]; +extern const OSSL_DISPATCH uadk_sha384_functions[FUNC_MAX_NUM]; +extern const OSSL_DISPATCH uadk_sha512_functions[FUNC_MAX_NUM]; +extern const OSSL_DISPATCH uadk_sha512_224_functions[FUNC_MAX_NUM]; +extern const OSSL_DISPATCH uadk_sha512_256_functions[FUNC_MAX_NUM]; +
extern const OSSL_DISPATCH uadk_aes_128_cbc_functions[]; extern const OSSL_DISPATCH uadk_aes_192_cbc_functions[]; diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c index 3d8e1e9..2266224 100644 --- a/src/uadk_prov_digest.c +++ b/src/uadk_prov_digest.c @@ -120,6 +120,10 @@ static struct digest_info digest_info_table[] = { 48, SHA_SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT}, {NID_sha512, WD_DIGEST_NORMAL, WD_DIGEST_SHA512, 64, SHA_SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT}, + {NID_sha512_224, WD_DIGEST_NORMAL, WD_DIGEST_SHA512_224, + 28, SHA_SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT}, + {NID_sha512_256, WD_DIGEST_NORMAL, WD_DIGEST_SHA512_256, + 32, SHA_SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT}, };
static int uadk_digests_soft_md(struct digest_priv_ctx *priv) @@ -328,6 +332,14 @@ static void uadk_fill_mac_buffer_len(struct digest_priv_ctx *priv) priv->req.out_bytes = (priv->req.has_next == DIGEST_DOING) ? WD_DIGEST_SHA384_FULL_LEN : WD_DIGEST_SHA384_LEN; break; + case NID_sha512_224: + priv->req.out_bytes = (priv->req.has_next == DIGEST_DOING) ? + WD_DIGEST_SHA512_224_FULL_LEN : WD_DIGEST_SHA512_224_LEN; + break; + case NID_sha512_256: + priv->req.out_bytes = (priv->req.has_next == DIGEST_DOING) ? + WD_DIGEST_SHA512_256_FULL_LEN : WD_DIGEST_SHA512_256_LEN; + break; default: break; } @@ -759,8 +771,8 @@ static OSSL_FUNC_digest_newctx_fn uadk_##name##_newctx; \ static void *uadk_##name##_newctx(void *provctx) \ { \ struct digest_priv_ctx *ctx = OPENSSL_zalloc(sizeof(*ctx)); \ - \ - if (ctx == NULL) \ + char *ptr; \ + if (!ctx) \ return NULL; \ ctx->blk_size = blksize; \ ctx->md_size = mdsize; \ @@ -769,6 +781,9 @@ static void *uadk_##name##_newctx(void *provctx) \ if (ctx->soft_ctx == NULL) \ fprintf(stderr, "EVP_MD_CTX_new failed.\n"); \ strncpy(ctx->alg_name, #name, ALG_NAME_SIZE - 1); \ + ptr = strchr(ctx->alg_name, '_'); \ + if (ptr != NULL) \ + *ptr = '-'; \ return ctx; \ } \ static OSSL_FUNC_digest_get_params_fn uadk_##name##_get_params; \ @@ -798,3 +813,5 @@ UADK_PROVIDER_IMPLEMENTATION(sha224, NID_sha224, 28, 64); UADK_PROVIDER_IMPLEMENTATION(sha256, NID_sha256, 32, 64); UADK_PROVIDER_IMPLEMENTATION(sha384, NID_sha384, 48, 128); UADK_PROVIDER_IMPLEMENTATION(sha512, NID_sha512, 64, 128); +UADK_PROVIDER_IMPLEMENTATION(sha512_224, NID_sha512_224, 28, 128); +UADK_PROVIDER_IMPLEMENTATION(sha512_256, NID_sha512_256, 32, 128); diff --git a/src/uadk_prov_init.c b/src/uadk_prov_init.c index 83bde5e..4a81620 100644 --- a/src/uadk_prov_init.c +++ b/src/uadk_prov_init.c @@ -57,6 +57,10 @@ const OSSL_ALGORITHM uadk_prov_digests[] = { uadk_sha384_functions, "uadk_provider sha2-384" }, { PROV_NAMES_SHA2_512, UADK_DEFAULT_PROPERTIES, uadk_sha512_functions, "uadk_provider sha2-512" }, + { "SHA2-512/224:SHA-512/224:SHA512-224", UADK_DEFAULT_PROPERTIES, + uadk_sha512_224_functions, "uadk_provider sha2-512-224" }, + { "SHA2-512/256:SHA-512/256:SHA512-256", UADK_DEFAULT_PROPERTIES, + uadk_sha512_256_functions, "uadk_provider sha2-512-256" }, { NULL, NULL, NULL } };