Skip to content

Commit c24b8e8

Browse files
committed
psa: Add get/set domain parameters
DSA and static DH need extra domain parameters. Instead of passing these in with the keys themselves, add get and set functions to set and retrieve this information about keys.
1 parent acb6960 commit c24b8e8

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

include/psa/crypto.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,70 @@ psa_status_t psa_get_key_information(psa_key_handle_t handle,
369369
psa_key_type_t *type,
370370
size_t *bits);
371371

372+
/**
373+
* \brief Set domain parameters for a key.
374+
*
375+
* Some key types require additional domain parameters to be set before import
376+
* or generation of the key. The domain parameters can be set with this
377+
* function or, for key generation, through the \c extra parameter of
378+
* psa_generate_key().
379+
*
380+
* The format for the required domain parameters varies by the key type.
381+
*
382+
* \param[in] data Buffer containing the key domain parameters. The content
383+
* of this buffer is interpreted according to \p type. of
384+
* psa_export_key() or psa_export_public_key() for the
385+
* chosen type.
386+
* \param data_length Size of the \p data buffer in bytes.
387+
*
388+
* \retval #PSA_SUCCESS
389+
* \retval #PSA_ERROR_INVALID_HANDLE
390+
* \retval #PSA_ERROR_OCCUPIED_SLOT
391+
* There is already a key in the specified slot.
392+
* \retval #PSA_ERROR_INVALID_ARGUMENT
393+
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
394+
* \retval #PSA_ERROR_HARDWARE_FAILURE
395+
* \retval #PSA_ERROR_TAMPERING_DETECTED
396+
* \retval #PSA_ERROR_BAD_STATE
397+
* The library has not been previously initialized by psa_crypto_init().
398+
* It is implementation-dependent whether a failure to initialize
399+
* results in this error code.
400+
*/
401+
psa_status_t psa_set_key_domain_parameters(psa_key_handle_t handle,
402+
const uint8_t *data,
403+
size_t data_length);
404+
405+
/**
406+
* \brief Get domain parameters for a key.
407+
*
408+
* Get the domain parameters for a key with this function, if any. The format
409+
* of the domain parameters written to \p data is specified in the
410+
* documentation for psa_set_key_domain_parameters().
411+
*
412+
* \param[out] data On success, the key domain parameters.
413+
* \param data_size Size of the \p data buffer in bytes.
414+
* \param[out] data_length On success, the number of bytes
415+
* that make up the key domain parameters data.
416+
*
417+
* \retval #PSA_SUCCESS
418+
* \retval #PSA_ERROR_INVALID_HANDLE
419+
* \retval #PSA_ERROR_EMPTY_SLOT
420+
* There is no key in the specified slot.
421+
* \retval #PSA_ERROR_INVALID_ARGUMENT
422+
* \retval #PSA_ERROR_NOT_SUPPORTED
423+
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
424+
* \retval #PSA_ERROR_HARDWARE_FAILURE
425+
* \retval #PSA_ERROR_TAMPERING_DETECTED
426+
* \retval #PSA_ERROR_BAD_STATE
427+
* The library has not been previously initialized by psa_crypto_init().
428+
* It is implementation-dependent whether a failure to initialize
429+
* results in this error code.
430+
*/
431+
psa_status_t psa_get_key_domain_parameters(psa_key_handle_t handle,
432+
uint8_t *data,
433+
size_t data_size,
434+
size_t *data_length);
435+
372436
/**
373437
* \brief Export a key in binary format.
374438
*

library/psa_crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ psa_status_t psa_import_key_into_slot( psa_key_slot_t *slot,
719719
}
720720

721721
/* Retrieve an empty key slot (slot with no key data, but possibly
722-
* with some metadata such as a policy). */
722+
* with some metadata such as a policy or domain parameters). */
723723
static psa_status_t psa_get_empty_key_slot( psa_key_handle_t handle,
724724
psa_key_slot_t **p_slot )
725725
{

0 commit comments

Comments
 (0)