Properly limit the variable output size for BLAKE2
authorTomas Mraz <tomas@openssl.org>
Wed, 8 Nov 2023 09:14:08 +0000 (10:14 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 13 Nov 2023 11:13:17 +0000 (12:13 +0100)
The upper limit of the output size is the default output size of
the respective algorithm variants.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/22659)

doc/man7/EVP_MD-BLAKE2.pod
providers/implementations/digests/blake2_prov.c
test/recipes/30-test_evp_data/evpmd_blake.txt

index 288a6dd735323f51e3c962aa218354d311b0bbdb..bfcf43e199117a3b2c1f9250e66e134b55c4bd83 100644 (file)
@@ -43,16 +43,21 @@ in L<EVP_MD-common(7)>.
 
 =head2 Settable Context Parameters
 
-The BLAKE2B-512 implementation supports the following L<OSSL_PARAM(3)> entries,
-settable for an B<EVP_MD_CTX> with L<EVP_MD_CTX_set_params(3)>:
+The implementation supports the following L<OSSL_PARAM(3)> entries which
+are settable for an B<EVP_MD_CTX> with L<EVP_DigestInit_ex2(3)> or
+L<EVP_MD_CTX_set_params(3)>:
 
 =over 4
 
 =item "size" (B<OSSL_DIGEST_PARAM_SIZE>) <unsigned integer>
 
 Sets a different digest length for the L<EVP_DigestFinal(3)> output.
-The value of the "size" parameter should not exceed 255 and it must be set
-during the L<EVP_DigestInit_ex2(3)> call.
+The value of the "size" parameter must not exceed the default digest length
+of the respective BLAKE2 algorithm variants, 64 for BLAKE2B-512 and
+32 for BLAKE2S-256. The parameter must be set with the
+L<EVP_DigestInit_ex2(3)> call to have an immediate effect. When set with
+L<EVP_MD_CTX_set_params(3)> it will have an effect only if the B<EVP_MD_CTX>
+context is reinitialized.
 
 =back
 
@@ -60,6 +65,13 @@ during the L<EVP_DigestInit_ex2(3)> call.
 
 L<provider-digest(7)>, L<OSSL_PROVIDER-default(7)>
 
+=head1 HISTORY
+
+This functionality was added in OpenSSL 3.0.
+
+The variable size support was added in OpenSSL 3.2 for BLAKE2B-512 and
+in OpenSSL 3.3 for BLAKE2S-256.
+
 =head1 COPYRIGHT
 
 Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
index 4178d0554d3ed554b278f8510b3c8e4dbf7da156..befdcc6a17e83537c7910c047eb6a37ac8da6fa0 100644 (file)
@@ -74,7 +74,7 @@ int ossl_blake##variant##_set_ctx_params(void *vctx, const OSSL_PARAM params[])
             ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); \
             return 0; \
         } \
-        if (size < 1 || size > UINT8_MAX) { \
+        if (size < 1 || size > BLAKE##VARIANT##_OUTBYTES) { \
             ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_SIZE); \
             return 0; \
         } \
index 949de2f783a0f419680a642021067291e65aa2ad..e0907964085d66fa28fa9a2ce68436c5f4d49010 100644 (file)
@@ -64,6 +64,11 @@ Input = 61
 OutputSize = 10
 Output = b60d322755eebca92b5e
 
+Digest = BLAKE2s256
+Input = 61
+OutputSize = 33
+Result = DIGESTINIT_ERROR
+
 Digest = BLAKE2b512
 Input =
 Output = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce
@@ -109,3 +114,8 @@ Digest = BLAKE2b512
 Input = 61
 OutputSize = 32
 Output = 8928aae63c84d87ea098564d1e03ad813f107add474e56aedd286349c0c03ea4
+
+Digest = BLAKE2b512
+Input = 61
+OutputSize = 65
+Result = DIGESTINIT_ERROR