Skip to content

Commit 3163ef7

Browse files
authored
Merge pull request #224 from athoelke/crypto-key-wrap-v2
Add support for key wrapping (v2)
2 parents 43452d8 + 01d3b2d commit 3163ef7

File tree

16 files changed

+468
-2
lines changed

16 files changed

+468
-2
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ typedef struct psa_custom_key_parameters_t {
110110
#define PSA_ALG_IS_KEY_DERIVATION_STRETCHING(alg) \
111111
/* specification-defined value */
112112
#define PSA_ALG_IS_KEY_ENCAPSULATION(alg) /* specification-defined value */
113+
#define PSA_ALG_IS_KEY_WRAP(alg) /* specification-defined value */
113114
#define PSA_ALG_IS_MAC(alg) /* specification-defined value */
114115
#define PSA_ALG_IS_PAKE(alg) /* specification-defined value */
115116
#define PSA_ALG_IS_PBKDF2_HMAC(alg) /* specification-defined value */
@@ -141,6 +142,8 @@ typedef struct psa_custom_key_parameters_t {
141142
/* specification-defined value */
142143
#define PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) /* specification-defined value */
143144
#define PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) /* specification-defined value */
145+
#define PSA_ALG_KW ((psa_algorithm_t)0x0B400100)
146+
#define PSA_ALG_KWP ((psa_algorithm_t)0x0BC00200)
144147
#define PSA_ALG_MD2 ((psa_algorithm_t)0x02000001)
145148
#define PSA_ALG_MD4 ((psa_algorithm_t)0x02000002)
146149
#define PSA_ALG_MD5 ((psa_algorithm_t)0x02000003)
@@ -340,9 +343,11 @@ typedef struct psa_custom_key_parameters_t {
340343
#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
341344
#define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00001000)
342345
#define PSA_KEY_USAGE_SIGN_MESSAGE ((psa_key_usage_t)0x00000400)
346+
#define PSA_KEY_USAGE_UNWRAP ((psa_key_usage_t)0x00020000)
343347
#define PSA_KEY_USAGE_VERIFY_DERIVATION ((psa_key_usage_t)0x00008000)
344348
#define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00002000)
345349
#define PSA_KEY_USAGE_VERIFY_MESSAGE ((psa_key_usage_t)0x00000800)
350+
#define PSA_KEY_USAGE_WRAP ((psa_key_usage_t)0x00010000)
346351
#define PSA_MAC_LENGTH(key_type, key_bits, alg) \
347352
/* implementation-defined value */
348353
#define PSA_MAC_MAX_SIZE /* implementation-defined value */
@@ -385,6 +390,9 @@ typedef struct psa_custom_key_parameters_t {
385390
/* implementation-defined value */
386391
#define PSA_TLS12_ECJPAKE_TO_PMS_OUTPUT_SIZE 32
387392
#define PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE /* implementation-defined value */
393+
#define PSA_WRAP_KEY_OUTPUT_SIZE(wrap_key_type, alg, key_type, key_bits) \
394+
/* implementation-defined value */
395+
#define PSA_WRAP_KEY_PAIR_MAX_SIZE /* implementation-defined value */
388396
#define PSA_XOF_OPERATION_INIT /* implementation-defined value */
389397
psa_status_t psa_aead_abort(psa_aead_operation_t * operation);
390398
psa_status_t psa_aead_decrypt(psa_key_id_t key,
@@ -744,6 +752,12 @@ psa_status_t psa_sign_message(psa_key_id_t key,
744752
uint8_t * signature,
745753
size_t signature_size,
746754
size_t * signature_length);
755+
psa_status_t psa_unwrap_key(const psa_key_attributes_t * attributes,
756+
psa_key_id_t wrapping_key,
757+
psa_algorithm_t alg,
758+
const uint8_t * data,
759+
size_t data_length,
760+
psa_key_id_t * key);
747761
psa_status_t psa_verify_hash(psa_key_id_t key,
748762
psa_algorithm_t alg,
749763
const uint8_t * hash,
@@ -756,6 +770,12 @@ psa_status_t psa_verify_message(psa_key_id_t key,
756770
size_t input_length,
757771
const uint8_t * signature,
758772
size_t signature_length);
773+
psa_status_t psa_wrap_key(psa_key_id_t wrapping_key,
774+
psa_algorithm_t alg,
775+
psa_key_id_t key,
776+
uint8_t * data,
777+
size_t data_size,
778+
size_t * data_length);
759779
psa_status_t psa_xof_abort(psa_xof_operation_t * operation);
760780
psa_xof_operation_t psa_xof_operation_init(void);
761781
psa_status_t psa_xof_output(psa_xof_operation_t * operation,

doc/crypto/api/keys/policy.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
101101
- `PSA_KEY_USAGE_VERIFY_HASH`
102102
- `PSA_KEY_USAGE_DERIVE`
103103
- `PSA_KEY_USAGE_VERIFY_DERIVATION`
104+
- `PSA_KEY_USAGE_WRAP`
105+
- `PSA_KEY_USAGE_UNWRAP`
104106

105107
The flag `PSA_KEY_USAGE_DERIVE_PUBLIC` is used in the function `psa_check_key_usage()` to query if a key can be used for the public role in the specified algorithm.
106108

@@ -293,6 +295,27 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
293295
The key must have the `PSA_KEY_USAGE_DERIVE` permission.
294296
* `PSA_ALG_HKDF` is invalid, as there is no such role in single-key derivation algorithms.
295297

298+
.. macro:: PSA_KEY_USAGE_WRAP
299+
:definition: ((psa_key_usage_t)0x00010000)
300+
301+
.. summary::
302+
Permission to wrap another key with the key.
303+
304+
This flag is required to use the key in a key-wrapping operation.
305+
The flag must be present on keys used with the following APIs:
306+
307+
* `psa_wrap_key()`
308+
309+
.. macro:: PSA_KEY_USAGE_UNWRAP
310+
:definition: ((psa_key_usage_t)0x00020000)
311+
312+
.. summary::
313+
Permission to unwrap another key with the key.
314+
315+
This flag is required to use the key in a key-unwrapping operation.
316+
The flag must be present on keys used with the following APIs:
317+
318+
* `psa_unwrap_key()`
296319

297320
.. function:: psa_set_key_usage_flags
298321

doc/crypto/api/keys/types.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ Symmetric keys
322322
* `PSA_ALG_ECB_NO_PADDING`
323323
* `PSA_ALG_CCM`
324324
* `PSA_ALG_GCM`
325+
* `PSA_ALG_KW`
326+
* `PSA_ALG_KWP`
325327
* `PSA_ALG_SP800_108_COUNTER_CMAC` (secret input)
326328

327329
.. subsection:: Key format
@@ -369,6 +371,8 @@ Symmetric keys
369371
* `PSA_ALG_ECB_NO_PADDING`
370372
* `PSA_ALG_CCM`
371373
* `PSA_ALG_GCM`
374+
* `PSA_ALG_KW`
375+
* `PSA_ALG_KWP`
372376
* `PSA_ALG_SP800_108_COUNTER_CMAC` (secret input)
373377

374378
.. subsection:: Key format
@@ -463,6 +467,8 @@ Symmetric keys
463467
* `PSA_ALG_ECB_NO_PADDING`
464468
* `PSA_ALG_CCM`
465469
* `PSA_ALG_GCM`
470+
* `PSA_ALG_KW`
471+
* `PSA_ALG_KWP`
466472
* `PSA_ALG_SP800_108_COUNTER_CMAC` (secret input)
467473

468474
.. subsection:: Key format
@@ -500,6 +506,8 @@ Symmetric keys
500506
* `PSA_ALG_ECB_NO_PADDING`
501507
* `PSA_ALG_CCM`
502508
* `PSA_ALG_GCM`
509+
* `PSA_ALG_KW`
510+
* `PSA_ALG_KWP`
503511
* `PSA_ALG_SP800_108_COUNTER_CMAC` (secret input)
504512

505513
.. subsection:: Key format

doc/crypto/api/ops/algorithms.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The specific algorithm identifiers are described alongside the cryptographic ope
2020
* :secref:`mac-algorithms`
2121
* :secref:`cipher-algorithms`
2222
* :secref:`aead-algorithms`
23+
* :secref:`key-wrapping-algorithms`
2324
* :secref:`key-derivation-algorithms`
2425
* :secref:`sign`
2526
* :secref:`asymmetric-encryption-algorithms`
@@ -141,6 +142,20 @@ Algorithm categories
141142

142143
See :secref:`aead-algorithms` for a list of defined AEAD algorithms.
143144

145+
.. macro:: PSA_ALG_IS_KEY_WRAP
146+
:definition: /* specification-defined value */
147+
148+
.. summary::
149+
Whether the specified algorithm is a key wrapping algorithm.
150+
151+
.. param:: alg
152+
An algorithm identifier: a value of type `psa_algorithm_t`.
153+
154+
.. return::
155+
``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.
156+
157+
See :secref:`key-wrapping-algorithms` for a list of defined key-wrapping algorithms.
158+
144159
.. macro:: PSA_ALG_IS_KEY_DERIVATION
145160
:definition: /* specification-defined value */
146161

doc/crypto/api/ops/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Cryptographic operation reference
1515
mac
1616
cipher
1717
aead
18+
key-wrapping
1819
key-derivation
1920
signature
2021
pk-encryption

0 commit comments

Comments
 (0)