From 6d1e730a1ea2c64bdffa88c6b3bee4c3f5bed602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 19 Oct 2023 18:31:33 +0200 Subject: Implement BLAKE2s with the same macro as BLAKE2b This avoids code duplication and provides variable-size support for BLAKE2s like 786b9a8 Test data obtained with libb2 with the following programs: ==> b2.c <== #include #include int main() { char buf[16] = {}; blake2s(buf, 0, 0, 16, 0, 0); write(1, buf, 16); } ==> b3.c <== #include #include int main() { char buf[10] = {}; blake2s(buf, "\x61", 0, 10, 1, 0); write(1, buf, 10); } Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/22444) --- providers/implementations/digests/blake2_prov.c | 17 +---------------- providers/implementations/include/prov/blake2.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'providers') diff --git a/providers/implementations/digests/blake2_prov.c b/providers/implementations/digests/blake2_prov.c index f80d307321..4178d0554d 100644 --- a/providers/implementations/digests/blake2_prov.c +++ b/providers/implementations/digests/blake2_prov.c @@ -15,22 +15,6 @@ #include "prov/digestcommon.h" #include "prov/implementations.h" -static int ossl_blake2s256_init(void *ctx) -{ - BLAKE2S_PARAM P; - - ossl_blake2s_param_init(&P); - return ossl_blake2s_init((BLAKE2S_CTX *)ctx, &P); -} - -/* ossl_blake2s256_functions */ -IMPLEMENT_digest_functions(blake2s256, BLAKE2S_CTX, - BLAKE2S_BLOCKBYTES, BLAKE2S_DIGEST_LENGTH, 0, - ossl_blake2s256_init, ossl_blake2s_update, - ossl_blake2s_final) - -/* ossl_blake2b512_functions */ - #define IMPLEMENT_BLAKE_functions(variant, VARIANT, variantsize) \ static const OSSL_PARAM known_blake##variant##_ctx_params[] = { \ {OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0}, \ @@ -200,4 +184,5 @@ const OSSL_DISPATCH ossl_blake##variantsize##_functions[] = { \ {0, NULL} \ }; +IMPLEMENT_BLAKE_functions(2s, 2S, 2s256) IMPLEMENT_BLAKE_functions(2b, 2B, 2b512) diff --git a/providers/implementations/include/prov/blake2.h b/providers/implementations/include/prov/blake2.h index 445fd89aa2..42229e2d74 100644 --- a/providers/implementations/include/prov/blake2.h +++ b/providers/implementations/include/prov/blake2.h @@ -88,6 +88,11 @@ struct blake2b_md_data_st { BLAKE2B_PARAM params; }; +struct blake2s_md_data_st { + BLAKE2S_CTX ctx; + BLAKE2S_PARAM params; +}; + int ossl_blake2b_init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P); int ossl_blake2b_init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P, const void *key); @@ -125,4 +130,9 @@ void ossl_blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal, void ossl_blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt, size_t length); +OSSL_FUNC_digest_get_ctx_params_fn ossl_blake2s_get_ctx_params; +OSSL_FUNC_digest_set_ctx_params_fn ossl_blake2s_set_ctx_params; +OSSL_FUNC_digest_gettable_ctx_params_fn ossl_blake2s_gettable_ctx_params; +OSSL_FUNC_digest_settable_ctx_params_fn ossl_blake2s_settable_ctx_params; + #endif /* OSSL_PROV_BLAKE2_H */ -- cgit v1.2.3