Skip to content

Commit d00c88b

Browse files
committed
Add support for XOF algorithms
* Add psa_xof_operation_t and its functions. * Add SHAKE128 and SHAKE256 XOF algorithms.
1 parent 9a7c5b3 commit d00c88b

File tree

14 files changed

+381
-8
lines changed

14 files changed

+381
-8
lines changed

doc/crypto/api.db/psa/crypto.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef uint32_t psa_pake_primitive_t;
2424
typedef uint8_t psa_pake_primitive_type_t;
2525
typedef uint8_t psa_pake_role_t;
2626
typedef uint8_t psa_pake_step_t;
27+
typedef /* implementation-defined type */ psa_xof_operation_t;
2728
typedef struct psa_custom_key_parameters_t {
2829
uint32_t flags;
2930
} psa_custom_key_parameters_t;
@@ -134,6 +135,7 @@ typedef struct psa_custom_key_parameters_t {
134135
#define PSA_ALG_IS_TLS12_PRF(alg) /* specification-defined value */
135136
#define PSA_ALG_IS_TLS12_PSK_TO_MS(alg) /* specification-defined value */
136137
#define PSA_ALG_IS_WILDCARD(alg) /* specification-defined value */
138+
#define PSA_ALG_IS_XOF(alg) /* specification-defined value */
137139
#define PSA_ALG_JPAKE(hash_alg) /* specification-defined value */
138140
#define PSA_ALG_KEY_AGREEMENT(ka_alg, kdf_alg) \
139141
/* specification-defined value */
@@ -158,6 +160,8 @@ typedef struct psa_custom_key_parameters_t {
158160
#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x02000011)
159161
#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x02000012)
160162
#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x02000013)
163+
#define PSA_ALG_SHAKE128 ((psa_algorithm_t)0x0D000100)
164+
#define PSA_ALG_SHAKE256 ((psa_algorithm_t)0x0D000200)
161165
#define PSA_ALG_SHAKE256_512 ((psa_algorithm_t)0x02000015)
162166
#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x02000005)
163167
#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x02000008)
@@ -210,7 +214,7 @@ typedef struct psa_custom_key_parameters_t {
210214
#define PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
211215
/* implementation-defined value */
212216
#define PSA_CRYPTO_API_VERSION_MAJOR 1
213-
#define PSA_CRYPTO_API_VERSION_MINOR 3
217+
#define PSA_CRYPTO_API_VERSION_MINOR 4
214218
#define PSA_CUSTOM_KEY_PARAMETERS_INIT { 0 }
215219
#define PSA_DH_FAMILY_RFC7919 ((psa_dh_family_t) 0x03)
216220
#define PSA_ECC_FAMILY_BRAINPOOL_P_R1 ((psa_ecc_family_t) 0x30)
@@ -380,6 +384,7 @@ typedef struct psa_custom_key_parameters_t {
380384
/* implementation-defined value */
381385
#define PSA_TLS12_ECJPAKE_TO_PMS_OUTPUT_SIZE 32
382386
#define PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE /* implementation-defined value */
387+
#define PSA_XOF_OPERATION_INIT /* implementation-defined value */
383388
psa_status_t psa_aead_abort(psa_aead_operation_t * operation);
384389
psa_status_t psa_aead_decrypt(psa_key_id_t key,
385390
psa_algorithm_t alg,
@@ -743,3 +748,13 @@ psa_status_t psa_verify_message(psa_key_id_t key,
743748
size_t input_length,
744749
const uint8_t * signature,
745750
size_t signature_length);
751+
psa_status_t psa_xof_abort(psa_xof_operation_t * operation);
752+
psa_status_t psa_xof_input(psa_xof_operation_t * operation,
753+
const uint8_t * input,
754+
size_t input_length);
755+
psa_xof_operation_t psa_xof_operation_init(void);
756+
psa_status_t psa_xof_output(psa_xof_operation_t * operation,
757+
uint8_t * output,
758+
size_t output_length);
759+
psa_status_t psa_xof_setup(psa_xof_operation_t * operation,
760+
psa_algorithm_t alg);

doc/crypto/api/ops/algorithms.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Algorithm identifiers are used for two purposes in the |API|:
1616
The specific algorithm identifiers are described alongside the cryptographic operation functions to which they apply:
1717

1818
* :secref:`hash-algorithms`
19+
* :secref:`xof-algorithms`
1920
* :secref:`mac-algorithms`
2021
* :secref:`cipher-algorithms`
2122
* :secref:`aead-algorithms`
@@ -83,6 +84,21 @@ Algorithm categories
8384

8485
See :secref:`hash-algorithms` for a list of defined hash algorithms.
8586

87+
.. macro:: PSA_ALG_IS_XOF
88+
:definition: /* specification-defined value */
89+
90+
.. summary::
91+
Whether the specified algorithm is an XOF algorithm.
92+
93+
.. param:: alg
94+
An algorithm identifier: a value of type `psa_algorithm_t`.
95+
96+
.. return::
97+
``1`` if ``alg`` is an XOF algorithm, ``0`` otherwise.
98+
This macro can return either ``0`` or ``1`` if ``alg`` is not a supported algorithm identifier.
99+
100+
See :secref:`xof-algorithms` for a list of defined XOF algorithms.
101+
86102
.. macro:: PSA_ALG_IS_MAC
87103
:definition: /* specification-defined value */
88104

doc/crypto/api/ops/hash.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,16 @@ Hash algorithms
184184
:definition: ((psa_algorithm_t)0x02000015)
185185

186186
.. summary::
187-
The first 512 bits (64 bytes) of the SHAKE256 output.
187+
The first 512 bits (64 bytes) of the output from SHAKE256.
188188

189189
.. versionadded:: 1.1
190190

191-
This is the pre-hashing for Ed448ph (see `PSA_ALG_ED448PH`).
191+
This is used for pre-hashing in Ed448ph, see `PSA_ALG_ED448PH`.
192192

193-
SHAKE256 is defined in :cite:`FIPS202`.
193+
The SHAKE256 XOF is defined in :cite:`FIPS202`.
194+
195+
.. note::
196+
To use SHAKE256 as an XOF, see :secref:`xof` and `PSA_ALG_SHAKE256`.
194197

195198
.. note::
196199
For other scenarios where a hash function based on SHA3 or SHAKE is required, SHA3-512 is recommended. SHA3-512 has the same output size, and a theoretically higher security strength.

doc/crypto/api/ops/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. SPDX-FileCopyrightText: Copyright 2018-2022, 2024 Arm Limited and/or its affiliates <[email protected]>
1+
.. SPDX-FileCopyrightText: Copyright 2018-2025 Arm Limited and/or its affiliates <[email protected]>
22
.. SPDX-License-Identifier: CC-BY-SA-4.0 AND LicenseRef-Patent-license
33
44
.. _crypto-operations:
@@ -11,6 +11,7 @@ Cryptographic operation reference
1111

1212
algorithms
1313
hash
14+
xof
1415
mac
1516
cipher
1617
aead

0 commit comments

Comments
 (0)