Skip to content

Commit b4019bc

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 b0ce828 commit b4019bc

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

include/psa/crypto.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,72 @@ 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 handle Handle to the key to set domain parameters for.
383+
* \param[in] data Buffer containing the key domain parameters. The content
384+
* of this buffer is interpreted according to \p type. of
385+
* psa_export_key() or psa_export_public_key() for the
386+
* chosen type.
387+
* \param data_length Size of the \p data buffer in bytes.
388+
*
389+
* \retval #PSA_SUCCESS
390+
* \retval #PSA_ERROR_INVALID_HANDLE
391+
* \retval #PSA_ERROR_OCCUPIED_SLOT
392+
* There is already a key in the specified slot.
393+
* \retval #PSA_ERROR_INVALID_ARGUMENT
394+
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
395+
* \retval #PSA_ERROR_HARDWARE_FAILURE
396+
* \retval #PSA_ERROR_TAMPERING_DETECTED
397+
* \retval #PSA_ERROR_BAD_STATE
398+
* The library has not been previously initialized by psa_crypto_init().
399+
* It is implementation-dependent whether a failure to initialize
400+
* results in this error code.
401+
*/
402+
psa_status_t psa_set_key_domain_parameters(psa_key_handle_t handle,
403+
const uint8_t *data,
404+
size_t data_length);
405+
406+
/**
407+
* \brief Get domain parameters for a key.
408+
*
409+
* Get the domain parameters for a key with this function, if any. The format
410+
* of the domain parameters written to \p data is specified in the
411+
* documentation for psa_set_key_domain_parameters().
412+
*
413+
* \param handle Handle to the key to get domain parameters from.
414+
* \param[out] data On success, the key domain parameters.
415+
* \param data_size Size of the \p data buffer in bytes.
416+
* \param[out] data_length On success, the number of bytes
417+
* that make up the key domain parameters data.
418+
*
419+
* \retval #PSA_SUCCESS
420+
* \retval #PSA_ERROR_INVALID_HANDLE
421+
* \retval #PSA_ERROR_EMPTY_SLOT
422+
* There is no key in the specified slot.
423+
* \retval #PSA_ERROR_INVALID_ARGUMENT
424+
* \retval #PSA_ERROR_NOT_SUPPORTED
425+
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
426+
* \retval #PSA_ERROR_HARDWARE_FAILURE
427+
* \retval #PSA_ERROR_TAMPERING_DETECTED
428+
* \retval #PSA_ERROR_BAD_STATE
429+
* The library has not been previously initialized by psa_crypto_init().
430+
* It is implementation-dependent whether a failure to initialize
431+
* results in this error code.
432+
*/
433+
psa_status_t psa_get_key_domain_parameters(psa_key_handle_t handle,
434+
uint8_t *data,
435+
size_t data_size,
436+
size_t *data_length);
437+
372438
/**
373439
* \brief Export a key in binary format.
374440
*

library/psa_crypto.c

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

740740
/* Retrieve an empty key slot (slot with no key data, but possibly
741-
* with some metadata such as a policy). */
741+
* with some metadata such as a policy or domain parameters). */
742742
static psa_status_t psa_get_empty_key_slot( psa_key_handle_t handle,
743743
psa_key_slot_t **p_slot )
744744
{

0 commit comments

Comments
 (0)