-
Notifications
You must be signed in to change notification settings - Fork 33
Add support for BLAKE2 algorithms #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -300,6 +300,104 @@ Hash algorithms | |
|
|
||
| It is recommended that these compound algorithms are not supported with `PSA_ALG_ASCON_HASH256`. | ||
|
|
||
| .. macro:: PSA_ALG_BLAKE2S_HASH256 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The only thing I can find on the web (other than software that supports a lot of different hash functions) is Winrar using BLAKE2sp. And p7zip also supports BLAKE2sp but no other BLAKE variant. According to BLAKE2 §2.11, “parallel hashes have exactly the same interfaces as their sequential counterparts”. So specifying them in PSA would be very cheap, we just need to give them an algorithm encoding. So I lean towards doing it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without an explicit request for these variants, with specific use case(s), we might not specify the right algorithms, as BLAKE2 does not map neatly onto our hash vs xof vs MAC taxonomy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, but the only use I've found of a p variant is the s hash, with its nominal length.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So perhaps we can add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done
MarcusJGStreets marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| :definition: ((psa_algorithm_t)0x0200001C) | ||
|
|
||
| .. summary:: | ||
| The BLAKE2s cryptographic hash with 256 bits of output (BLAKE2s-256). | ||
|
|
||
| .. versionadded:: 1.5 | ||
|
|
||
| The BLAKE2s-256 hash is BLAKE2s with a zero-length key, and a 256-bit (32-byte) output. | ||
| BLAKE2s is defined in :rfc-title:`7693`. | ||
|
|
||
| .. note:: | ||
| To use BLAKE2s as a MAC, see `PSA_ALG_BLAKE2_MAC`. | ||
|
|
||
| Where a protocol requires the use of HMAC or HKDF-HMAC, BLAKE2s-256 can be used with HMAC. | ||
| See `PSA_ALG_HMAC`. | ||
|
|
||
| .. note:: | ||
| BLAKE2s-256 is not specified with `PSA_ALG_RSA_PKCS1V15_SIGN`, due to the lack of a standard OID. | ||
|
|
||
| It is recommended that this compound algorithm is not supported with `PSA_ALG_BLAKE2S_HASH256`. | ||
|
|
||
| .. macro:: PSA_ALG_BLAKE2SP_HASH256 | ||
| :definition: ((psa_algorithm_t)0x0200001D) | ||
|
|
||
| .. summary:: | ||
| The BLAKE2sp cryptographic hash with 256 bits of output (BLAKE2sp-256). | ||
|
|
||
| .. versionadded:: 1.5 | ||
|
|
||
| The BLAKE2sp-256 hash is the parallel version of BLAKE2s with a zero-length key, and a 256-bit (32-byte) output. | ||
| BLAKE2sp is defined in :cite-title:`BLAKE2`. | ||
|
|
||
| .. note:: | ||
| To use BLAKE2sp as a MAC, see `PSA_ALG_BLAKE2_MAC`. | ||
|
|
||
| .. note:: | ||
| BLAKE2sp-256 is not specified with `PSA_ALG_RSA_PKCS1V15_SIGN`, due to the lack of a standard OID. | ||
|
|
||
| It is recommended that this compound algorithm is not supported with `PSA_ALG_BLAKE2SP_HASH256`. | ||
|
|
||
| .. macro:: PSA_ALG_BLAKE2B_HASH512 | ||
| :definition: ((psa_algorithm_t)0x0200001E) | ||
|
|
||
| .. summary:: | ||
| The BLAKE2b cryptographic hash with 512 bits of output (BLAKE2b-512). | ||
|
|
||
| .. versionadded:: 1.5 | ||
|
|
||
| The BLAKE2b-512 hash is BLAKE2b with a zero-length key, and a 512-bit (64-byte) output. | ||
| BLAKE2b is defined in :rfc:`7693`. | ||
|
|
||
| .. note:: | ||
| To use BLAKE2b as a MAC, see `PSA_ALG_BLAKE2_MAC`. | ||
|
|
||
| Where a protocol requires the use of HMAC or HKDF-HMAC, BLAKE2b-512 can be used with HMAC. | ||
| See `PSA_ALG_HMAC`. | ||
|
|
||
| .. note:: | ||
| BLAKE2b-512 is not specified with `PSA_ALG_RSA_PKCS1V15_SIGN`, due to the lack of a standard OID. | ||
|
|
||
| It is recommended that this compound algorithm is not supported with `PSA_ALG_BLAKE2B_HASH512`. | ||
|
|
||
| .. macro:: PSA_ALG_BLAKE2BP_HASH512 | ||
| :definition: ((psa_algorithm_t)0x0200001F) | ||
|
|
||
| .. summary:: | ||
| The BLAKE2bp cryptographic hash with 512 bits of output (BLAKE2bp-512). | ||
|
|
||
| .. versionadded:: 1.5 | ||
|
|
||
| The BLAKE2bp-512 hash is the parallel version of BLAKE2b with a zero-length key, and a 512-bit (64-byte) output. | ||
| BLAKE2bp is defined in :cite-title:`BLAKE2`. | ||
|
|
||
| .. note:: | ||
| To use BLAKE2bp as a MAC, see `PSA_ALG_BLAKE2_MAC`. | ||
|
|
||
| .. note:: | ||
| BLAKE2bp-512 is not specified with `PSA_ALG_RSA_PKCS1V15_SIGN`, due to the lack of a standard OID. | ||
|
|
||
| It is recommended that this compound algorithm is not supported with `PSA_ALG_BLAKE2BP_HASH512`. | ||
|
|
||
| .. macro:: PSA_ALG_IS_BLAKE2_HASH | ||
| :definition: /* specification-defined value */ | ||
|
|
||
| .. summary:: | ||
| Whether the specified algorithm is a BLAKE2 hash algorithm. | ||
|
|
||
| .. param:: alg | ||
| An algorithm identifier: a value of type `psa_algorithm_t`. | ||
|
|
||
| .. return:: | ||
| ``1`` if ``alg`` is a BLAKE2 hash algorithm, ``0`` otherwise. | ||
| This macro can return either ``0`` or ``1`` if ``alg`` is not a supported algorithm identifier. | ||
|
|
||
| BLAKE2 is a family of hash and MAC algorithms. | ||
|
|
||
|
|
||
| Single-part hashing functions | ||
| ----------------------------- | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong feelings about this. Technically BLAKE2s-MAC and BLAKE2b-MAC are families of algorithms that use different families of keys, since they have different length constraints. But since they're just an array of bytes, it doesn't really matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to be separate, except that if we implement this idea, then a single key type for the family of
PSA_ALG_BLAKE2_MAC()algorithms actually makes more sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept a single key type in the updated PR