Skip to content

Commit 5d444e2

Browse files
committed
Add support for key wrapping
* psa_wrap_key() and psa_unwrap_key() functions * AES-KW and AES-KWP algorithms
1 parent c931176 commit 5d444e2

File tree

15 files changed

+448
-5
lines changed

15 files changed

+448
-5
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ typedef struct psa_custom_key_parameters_t {
5757
/* specification-defined value */
5858
#define PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length) \
5959
/* specification-defined value */
60+
#define PSA_ALG_AES_KW ((psa_algorithm_t)0x0B400100)
61+
#define PSA_ALG_AES_KWP ((psa_algorithm_t)0x0BC00200)
6062
#define PSA_ALG_AES_MMO_ZIGBEE ((psa_algorithm_t)0x02000007)
6163
#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x020000ff)
6264
#define PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(mac_alg, min_mac_length) \
@@ -109,6 +111,7 @@ typedef struct psa_custom_key_parameters_t {
109111
#define PSA_ALG_IS_KEY_DERIVATION_STRETCHING(alg) \
110112
/* specification-defined value */
111113
#define PSA_ALG_IS_KEY_ENCAPSULATION(alg) /* specification-defined value */
114+
#define PSA_ALG_IS_KEY_WRAP(alg) /* specification-defined value */
112115
#define PSA_ALG_IS_MAC(alg) /* specification-defined value */
113116
#define PSA_ALG_IS_PAKE(alg) /* specification-defined value */
114117
#define PSA_ALG_IS_PBKDF2_HMAC(alg) /* specification-defined value */
@@ -335,9 +338,11 @@ typedef struct psa_custom_key_parameters_t {
335338
#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
336339
#define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00001000)
337340
#define PSA_KEY_USAGE_SIGN_MESSAGE ((psa_key_usage_t)0x00000400)
341+
#define PSA_KEY_USAGE_UNWRAP ((psa_key_usage_t)0x00020000)
338342
#define PSA_KEY_USAGE_VERIFY_DERIVATION ((psa_key_usage_t)0x00008000)
339343
#define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00002000)
340344
#define PSA_KEY_USAGE_VERIFY_MESSAGE ((psa_key_usage_t)0x00000800)
345+
#define PSA_KEY_USAGE_WRAP ((psa_key_usage_t)0x00010000)
341346
#define PSA_MAC_LENGTH(key_type, key_bits, alg) \
342347
/* implementation-defined value */
343348
#define PSA_MAC_MAX_SIZE /* implementation-defined value */
@@ -380,6 +385,9 @@ typedef struct psa_custom_key_parameters_t {
380385
/* implementation-defined value */
381386
#define PSA_TLS12_ECJPAKE_TO_PMS_OUTPUT_SIZE 32
382387
#define PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE /* implementation-defined value */
388+
#define PSA_WRAP_KEY_OUTPUT_SIZE(wrap_key_type, alg, key_type, key_bits) \
389+
/* implementation-defined value */
390+
#define PSA_WRAP_KEY_PAIR_MAX_SIZE /* implementation-defined value */
383391
psa_status_t psa_aead_abort(psa_aead_operation_t * operation);
384392
psa_status_t psa_aead_decrypt(psa_key_id_t key,
385393
psa_algorithm_t alg,
@@ -735,6 +743,12 @@ psa_status_t psa_sign_message(psa_key_id_t key,
735743
uint8_t * signature,
736744
size_t signature_size,
737745
size_t * signature_length);
746+
psa_status_t psa_unwrap_key(const psa_key_attributes_t * attributes,
747+
psa_key_id_t wrapping_key,
748+
psa_algorithm_t alg,
749+
const uint8_t * data,
750+
size_t data_length,
751+
psa_key_id_t * key);
738752
psa_status_t psa_verify_hash(psa_key_id_t key,
739753
psa_algorithm_t alg,
740754
const uint8_t * hash,
@@ -747,3 +761,9 @@ psa_status_t psa_verify_message(psa_key_id_t key,
747761
size_t input_length,
748762
const uint8_t * signature,
749763
size_t signature_length);
764+
psa_status_t psa_wrap_key(psa_key_id_t wrapping_key,
765+
psa_algorithm_t alg,
766+
psa_key_id_t key,
767+
uint8_t * data,
768+
size_t data_size,
769+
size_t * data_length);

doc/crypto/api/keys/policy.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,28 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
267267

268268
If this flag is present on all keys used in calls to `psa_key_derivation_input_key()` for a key-derivation operation, then it permits calling `psa_key_derivation_verify_bytes()` or `psa_key_derivation_verify_key()` at the end of the operation.
269269

270+
.. macro:: PSA_KEY_USAGE_WRAP
271+
:definition: ((psa_key_usage_t)0x00010000)
272+
273+
.. summary::
274+
Permission to wrap another key with the key.
275+
276+
This flag is required to use the key in a key-wrapping operation.
277+
The flag must be present on keys used with the following APIs:
278+
279+
* `psa_wrap_key()`
280+
281+
.. macro:: PSA_KEY_USAGE_UNWRAP
282+
:definition: ((psa_key_usage_t)0x00020000)
283+
284+
.. summary::
285+
Permission to unwrap another key with the key.
286+
287+
This flag is required to use the key in a key-unwrapping operation.
288+
The flag must be present on keys used with the following APIs:
289+
290+
* `psa_unwrap_key()`
291+
270292
.. function:: psa_set_key_usage_flags
271293

272294
.. summary::

doc/crypto/api/ops/algorithms.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ Algorithm categories
125125

126126
See :secref:`aead-algorithms` for a list of defined AEAD algorithms.
127127

128+
.. macro:: PSA_ALG_IS_KEY_WRAP
129+
:definition: /* specification-defined value */
130+
131+
.. summary::
132+
Whether the specified algorithm is a key wrapping algorithm.
133+
134+
.. param:: alg
135+
An algorithm identifier: a value of type `psa_algorithm_t`.
136+
137+
.. return::
138+
``1`` if ``alg`` is a key-wrapping algorithm, ``0`` otherwise. This macro can return either ``0`` or ``1`` if ``alg`` is not a supported algorithm identifier.
139+
140+
See :secref:`key-wrapping-algorithms` for a list of defined key-wrapping algorithms.
141+
128142
.. macro:: PSA_ALG_IS_KEY_DERIVATION
129143
:definition: /* specification-defined value */
130144

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:
@@ -14,6 +14,7 @@ Cryptographic operation reference
1414
mac
1515
cipher
1616
aead
17+
key-wrapping
1718
key-derivation
1819
signature
1920
pk-encryption

0 commit comments

Comments
 (0)