Skip to content

Commit 18c5e10

Browse files
authored
Merge pull request #195 from athoelke/crypto-max-export-size
Add a macro to evaluate the maximum asymmetric key export size
2 parents d6dc284 + 670b98a commit 18c5e10

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ typedef uint8_t psa_pake_step_t;
219219
#define PSA_ECC_FAMILY_TWISTED_EDWARDS ((psa_ecc_family_t) 0x42)
220220
#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)-148)
221221
#define PSA_ERROR_INVALID_PADDING ((psa_status_t)-150)
222+
#define PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE /* implementation-defined value */
222223
#define PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits) \
223224
/* implementation-defined value */
224225
#define PSA_EXPORT_KEY_PAIR_MAX_SIZE /* implementation-defined value */

doc/crypto/api/keys/management.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ Key export
331331
This must be appropriate for the key:
332332

333333
* The required output size is :code:`PSA_EXPORT_KEY_OUTPUT_SIZE(type, bits)` where ``type`` is the key type and ``bits`` is the key size in bits.
334+
* `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE` evaluates to the maximum output size of any supported public key or key pair.
334335
* `PSA_EXPORT_KEY_PAIR_MAX_SIZE` evaluates to the maximum output size of any supported key pair.
335336
* `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE` evaluates to the maximum output size of any supported public key.
336337
* This API defines no maximum size for symmetric keys. Arbitrarily large data items can be stored in the key store, for example certificates that correspond to a stored private key or input material for key derivation.
@@ -353,7 +354,7 @@ Key export
353354
* The implementation does not support export of keys with this key type.
354355
.. retval:: PSA_ERROR_BUFFER_TOO_SMALL
355356
The size of the ``data`` buffer is too small.
356-
`PSA_EXPORT_KEY_OUTPUT_SIZE()` or `PSA_EXPORT_KEY_PAIR_MAX_SIZE` can be used to determine a sufficient buffer size.
357+
`PSA_EXPORT_KEY_OUTPUT_SIZE()`, `PSA_EXPORT_KEY_PAIR_MAX_SIZE`, `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE`, or `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE` can be used to determine a sufficient buffer size.
357358
.. retval:: PSA_ERROR_COMMUNICATION_FAILURE
358359
.. retval:: PSA_ERROR_CORRUPTION_DETECTED
359360
.. retval:: PSA_ERROR_STORAGE_FAILURE
@@ -386,6 +387,7 @@ Key export
386387

387388
* The required output size is :code:`PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(type, bits)` where ``type`` is the key type and ``bits`` is the key size in bits.
388389
* `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE` evaluates to the maximum output size of any supported public key or public part of a key pair.
390+
* `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE` evaluates to the maximum output size of any supported public key or key pair.
389391

390392
.. param:: size_t * data_length
391393
On success, the number of bytes that make up the key data.
@@ -405,7 +407,7 @@ Key export
405407
* The implementation does not support export of keys with this key type.
406408
.. retval:: PSA_ERROR_BUFFER_TOO_SMALL
407409
The size of the ``data`` buffer is too small.
408-
`PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE()` or `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE` can be used to determine a sufficient buffer size.
410+
`PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE()`, `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE`, or `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE` can be used to determine a sufficient buffer size.
409411
.. retval:: PSA_ERROR_COMMUNICATION_FAILURE
410412
.. retval:: PSA_ERROR_CORRUPTION_DETECTED
411413
.. retval:: PSA_ERROR_STORAGE_FAILURE
@@ -458,7 +460,7 @@ Key export
458460
if (status != PSA_SUCCESS)
459461
handle_error(...);
460462
461-
See also `PSA_EXPORT_KEY_PAIR_MAX_SIZE` and `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE`.
463+
See also `PSA_EXPORT_KEY_PAIR_MAX_SIZE`, `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE`, and `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE`.
462464

463465
.. macro:: PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE
464466
:definition: /* implementation-defined value */
@@ -497,7 +499,7 @@ Key export
497499
if (status != PSA_SUCCESS)
498500
handle_error(...);
499501
500-
See also `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE`.
502+
See also `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE` and `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE`.
501503

502504
.. macro:: PSA_EXPORT_KEY_PAIR_MAX_SIZE
503505
:definition: /* implementation-defined value */
@@ -507,7 +509,7 @@ Key export
507509

508510
This value must be a sufficient buffer size when calling `psa_export_key()` to export any asymmetric key pair that is supported by the implementation, regardless of the exact key type and key size.
509511

510-
See also `PSA_EXPORT_KEY_OUTPUT_SIZE()`.
512+
See also `PSA_EXPORT_KEY_OUTPUT_SIZE()`, `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE`, and `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE`.
511513

512514
.. macro:: PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
513515
:definition: /* implementation-defined value */
@@ -517,7 +519,17 @@ Key export
517519

518520
This value must be a sufficient buffer size when calling `psa_export_key()` or `psa_export_public_key()` to export any asymmetric public key that is supported by the implementation, regardless of the exact key type and key size.
519521

520-
See also `PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE()`.
522+
See also `PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE()`, `PSA_EXPORT_KEY_OUTPUT_SIZE()`, `PSA_EXPORT_KEY_PAIR_MAX_SIZE`, and `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE`.
523+
524+
.. macro:: PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE
525+
:definition: /* implementation-defined value */
526+
527+
.. summary::
528+
Sufficient buffer size for exporting any asymmetric key pair or public key.
529+
530+
This value must be a sufficient buffer size when calling `psa_export_key()` or `psa_export_public_key()` to export any asymmetric key pair or public key that is supported by the implementation, regardless of the exact key type and key size.
531+
532+
See also `PSA_EXPORT_KEY_PAIR_MAX_SIZE`, `PSA_EXPORT_PUBLIC_KEY_MAX_SIZE`, and `PSA_EXPORT_KEY_OUTPUT_SIZE()`.
521533

522534

523535
.. _key_formats:

doc/crypto/appendix/history.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Changes between *1.2.1* and *1.3.0*
1616

1717
:issue:`TBD`
1818

19+
Changes to the API
20+
~~~~~~~~~~~~~~~~~~
21+
22+
* Added `PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE` to evaluate the export buffer size for any asymmetric key pair or public key.
23+
1924
Other changes
2025
~~~~~~~~~~~~~
2126

0 commit comments

Comments
 (0)