From: наб Date: Thu, 19 Oct 2023 16:31:33 +0000 (+0200) Subject: Implement BLAKE2s with the same macro as BLAKE2b X-Git-Tag: openssl-3.3.0-alpha1~657 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d1e730a1ea2c64bdffa88c6b3bee4c3f5bed602;p=thirdparty%2Fopenssl.git 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) --- diff --git a/providers/implementations/digests/blake2_prov.c b/providers/implementations/digests/blake2_prov.c index f80d3073211..4178d0554d3 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 445fd89aa21..42229e2d740 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 */ diff --git a/test/recipes/30-test_evp_data/evpmd_blake.txt b/test/recipes/30-test_evp_data/evpmd_blake.txt index 474e6591429..949de2f783a 100644 --- a/test/recipes/30-test_evp_data/evpmd_blake.txt +++ b/test/recipes/30-test_evp_data/evpmd_blake.txt @@ -54,6 +54,16 @@ Digest = BLAKE2s256 Input = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F8081 Output = C80ABEEBB669AD5DEEB5F5EC8EA6B7A05DDF7D31EC4C0A2EE20B0B98CAEC6746 +Digest = BLAKE2s256 +Input = +OutputSize = 16 +Output = 64550d6ffe2c0a01a14aba1eade0200c + +Digest = BLAKE2s256 +Input = 61 +OutputSize = 10 +Output = b60d322755eebca92b5e + Digest = BLAKE2b512 Input = Output = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce