diff options
author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2023-10-19 18:31:33 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2023-11-08 09:42:13 +0100 |
commit | 6d1e730a1ea2c64bdffa88c6b3bee4c3f5bed602 (patch) | |
tree | 3a901c8c3ac87b5ed22b1d879e1bbeaf6adc3fd3 /providers | |
parent | 8349c02e86310d0263b97a26fefd24ab83571ae8 (diff) |
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 <blake2.h>
#include <unistd.h>
int main() {
char buf[16] = {};
blake2s(buf, 0, 0, 16, 0, 0);
write(1, buf, 16);
}
==> b3.c <==
#include <blake2.h>
#include <unistd.h>
int main() {
char buf[10] = {};
blake2s(buf, "\x61", 0, 10, 1, 0);
write(1, buf, 10);
}
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22444)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/implementations/digests/blake2_prov.c | 17 | ||||
-rw-r--r-- | providers/implementations/include/prov/blake2.h | 10 |
2 files changed, 11 insertions, 16 deletions
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 */ |