Function declarations for PSA Crypto. More...
Function declarations for PSA Crypto.
Definition in file crypto.h.
#include <stdlib.h>
#include <string.h>
#include "kernel_defines.h"
#include "crypto_sizes.h"
#include "crypto_struct.h"
#include "crypto_values.h"
#include "crypto_types.h"
Go to the source code of this file.
#define | PSA_CRYPTO_API_VERSION_MAJOR 1 |
The major version of this implementation of the PSA Crypto API. | |
#define | PSA_CRYPTO_API_VERSION_MINOR 1 |
The minor version of this implementation of the PSA Crypto API. | |
const char * | psa_status_to_humanly_readable (psa_status_t status) |
Helper function to convert PSA status values humanly readable. | |
psa_status_t | psa_crypto_init (void) |
Library initialization. | |
psa_status_t | psa_aead_encrypt (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *nonce, size_t nonce_length, const uint8_t *additional_data, size_t additional_data_length, const uint8_t *plaintext, size_t plaintext_length, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length) |
Process an authenticated encryption operation. | |
psa_status_t | psa_aead_decrypt (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *nonce, size_t nonce_length, const uint8_t *additional_data, size_t additional_data_length, const uint8_t *ciphertext, size_t ciphertext_length, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length) |
Process an authenticated decryption operation. | |
psa_status_t | psa_aead_encrypt_setup (psa_aead_operation_t *operation, psa_key_id_t key, psa_algorithm_t alg) |
Set the key for a multi-part authenticated encryption operation. | |
psa_status_t | psa_aead_decrypt_setup (psa_aead_operation_t *operation, psa_key_id_t key, psa_algorithm_t alg) |
Set the key for a multi-part authenticated decryption operation. | |
psa_status_t | psa_aead_set_lengths (psa_aead_operation_t *operation, size_t ad_length, size_t plaintext_length) |
Declare the lengths of the message and additional data for AEAD. | |
psa_status_t | psa_aead_generate_nonce (psa_aead_operation_t *operation, uint8_t *nonce, size_t nonce_size, size_t *nonce_length) |
Generate a random nonce for an authenticated encryption operation. | |
psa_status_t | psa_aead_set_nonce (psa_aead_operation_t *operation, const uint8_t *nonce, size_t nonce_length) |
Set the nonce for an authenticated encryption or decryption operation. | |
psa_status_t | psa_aead_update_ad (psa_aead_operation_t *operation, const uint8_t *input, size_t input_length) |
Pass additional data to an active AEAD operation. | |
psa_status_t | psa_aead_update (psa_aead_operation_t *operation, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length) |
Encrypt or decrypt a message fragment in an active AEAD operation. | |
psa_status_t | psa_aead_finish (psa_aead_operation_t *operation, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length, uint8_t *tag, size_t tag_size, size_t *tag_length) |
Finish encrypting a message in an AEAD operation. | |
psa_status_t | psa_aead_verify (psa_aead_operation_t *operation, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length, const uint8_t *tag, size_t tag_length) |
Finish authenticating and decrypting a message in an AEAD operation. | |
psa_status_t | psa_aead_abort (psa_aead_operation_t *operation) |
Abort an AEAD operation. | |
psa_status_t | psa_asymmetric_encrypt (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *salt, size_t salt_length, uint8_t *output, size_t output_size, size_t *output_length) |
Encrypt a short message with a public key. | |
psa_status_t | psa_asymmetric_decrypt (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *salt, size_t salt_length, uint8_t *output, size_t output_size, size_t *output_length) |
Decrypt a short message with a private key. | |
psa_status_t | psa_cipher_abort (psa_cipher_operation_t *operation) |
Abort a cipher operation. | |
psa_status_t | psa_cipher_decrypt (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length) |
Decrypt a message using a symmetric cipher. | |
psa_status_t | psa_cipher_decrypt_setup (psa_cipher_operation_t *operation, psa_key_id_t key, psa_algorithm_t alg) |
Set the key for a multi-part symmetric decryption operation. | |
psa_status_t | psa_cipher_encrypt (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length) |
Encrypt a message using a symmetric cipher. | |
psa_status_t | psa_cipher_encrypt_setup (psa_cipher_operation_t *operation, psa_key_id_t key, psa_algorithm_t alg) |
Set the key for a multi-part symmetric encryption operation. | |
psa_status_t | psa_cipher_finish (psa_cipher_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length) |
Finish encrypting or decrypting a message in a cipher operation. | |
psa_status_t | psa_cipher_generate_iv (psa_cipher_operation_t *operation, uint8_t *iv, size_t iv_size, size_t *iv_length) |
Generate an initialization vector (IV) for a symmetric encryption operation. | |
psa_status_t | psa_cipher_set_iv (psa_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length) |
Set the initialization vector (IV) for a symmetric encryption or decryption operation. | |
psa_status_t | psa_cipher_update (psa_cipher_operation_t *operation, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length) |
Encrypt or decrypt a message fragment in an active cipher operation. | |
psa_status_t | psa_copy_key (psa_key_id_t source_key, const psa_key_attributes_t *attributes, psa_key_id_t *target_key) |
Make a copy of a key. | |
psa_status_t | psa_destroy_key (psa_key_id_t key) |
Destroy a key. | |
psa_status_t | psa_export_key (psa_key_id_t key, uint8_t *data, size_t data_size, size_t *data_length) |
Export a key in binary format. | |
psa_status_t | psa_export_public_key (psa_key_id_t key, uint8_t *data, size_t data_size, size_t *data_length) |
Export a public key or the public part of a key pair in binary format. | |
psa_status_t | psa_builtin_generate_key (const psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length) |
Built-in key generation function. | |
psa_status_t | psa_generate_key (const psa_key_attributes_t *attributes, psa_key_id_t *key) |
Generate a key or key pair. | |
psa_status_t | psa_builtin_generate_random (uint8_t *output, size_t output_size) |
Built-in function for random number generation. | |
psa_status_t | psa_generate_random (uint8_t *output, size_t output_size) |
Generate random bytes. | |
static void | psa_set_key_algorithm (psa_key_attributes_t *attributes, psa_algorithm_t alg) |
Declare the permitted algorithm policy for a key. | |
static psa_algorithm_t | psa_get_key_algorithm (const psa_key_attributes_t *attributes) |
Retrieve the permitted algorithm policy from key attributes. | |
static void | psa_set_key_bits (psa_key_attributes_t *attributes, size_t bits) |
Declare the size of a key. | |
static size_t | psa_get_key_bits (const psa_key_attributes_t *attributes) |
Retrieve the key size from key attributes. | |
static void | psa_set_key_id (psa_key_attributes_t *attributes, psa_key_id_t id) |
Declare a key as persistent and set its key identifier. | |
static psa_key_id_t | psa_get_key_id (const psa_key_attributes_t *attributes) |
Retrieve the key identifier from key attributes. | |
static void | psa_set_key_lifetime (psa_key_attributes_t *attributes, psa_key_lifetime_t lifetime) |
Set the location of a persistent key. | |
static psa_key_lifetime_t | psa_get_key_lifetime (const psa_key_attributes_t *attributes) |
Retrieve the lifetime from key attributes. | |
static void | psa_set_key_type (psa_key_attributes_t *attributes, psa_key_type_t type) |
Declare the type of a key. | |
static psa_key_type_t | psa_get_key_type (const psa_key_attributes_t *attributes) |
Retrieve the key type from key attributes. | |
static void | psa_set_key_usage_flags (psa_key_attributes_t *attributes, psa_key_usage_t usage_flags) |
Declare usage flags for a key. | |
static psa_key_usage_t | psa_get_key_usage_flags (const psa_key_attributes_t *attributes) |
Retrieve the usage flags from key attributes. | |
static void | psa_reset_key_attributes (psa_key_attributes_t *attributes) |
Reset a key attribute object to a freshly initialized state. | |
psa_status_t | psa_get_key_attributes (psa_key_id_t key, psa_key_attributes_t *attributes) |
Retrieve the attributes of a key. | |
psa_status_t | psa_hash_abort (psa_hash_operation_t *operation) |
Abort a hash operation. | |
psa_status_t | psa_hash_clone (const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation) |
Clone a hash operation. | |
psa_status_t | psa_hash_compare (psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *hash, size_t hash_length) |
Calculate the hash (digest) of a message and compare it with a reference value. | |
psa_status_t | psa_hash_compute (psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *hash, size_t hash_size, size_t *hash_length) |
Calculate the hash (digest) of a message. | |
psa_status_t | psa_hash_finish (psa_hash_operation_t *operation, uint8_t *hash, size_t hash_size, size_t *hash_length) |
Finish the calculation of the hash of a message. | |
psa_status_t | psa_hash_resume (psa_hash_operation_t *operation, const uint8_t *hash_state, size_t hash_state_length) |
Set up a multi-part hash operation using the hash suspend state from a previously suspended hash operation. | |
psa_status_t | psa_hash_setup (psa_hash_operation_t *operation, psa_algorithm_t alg) |
Set up a multipart hash operation. | |
psa_status_t | psa_hash_suspend (psa_hash_operation_t *operation, uint8_t *hash_state, size_t hash_state_size, size_t *hash_state_length) |
Halt the hash operation and extract the intermediate state of the hash computation. | |
psa_status_t | psa_hash_update (psa_hash_operation_t *operation, const uint8_t *input, size_t input_length) |
Add a message fragment to a multi-part hash operation. | |
psa_status_t | psa_hash_verify (psa_hash_operation_t *operation, const uint8_t *hash, size_t hash_length) |
Finish the calculation of the hash of a message and compare it with an expected value. | |
psa_status_t | psa_builtin_import_key (const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length, size_t *bits) |
Built-in key import function. | |
psa_status_t | psa_import_key (const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, psa_key_id_t *key) |
Import a key in binary format. | |
psa_status_t | psa_key_derivation_abort (psa_key_derivation_operation_t *operation) |
Abort a key derivation operation. | |
psa_status_t | psa_key_derivation_get_capacity (const psa_key_derivation_operation_t *operation, size_t *capacity) |
Retrieve the current capacity of a key derivation operation. | |
psa_status_t | psa_key_derivation_input_bytes (psa_key_derivation_operation_t *operation, psa_key_derivation_step_t step, const uint8_t *data, size_t data_length) |
Provide an input for key derivation or key agreement. | |
psa_status_t | psa_key_derivation_input_integer (psa_key_derivation_operation_t *operation, psa_key_derivation_step_t step, uint64_t value) |
Provide a numeric input for key derivation or key agreement. | |
psa_status_t | psa_key_derivation_input_key (psa_key_derivation_operation_t *operation, psa_key_derivation_step_t step, psa_key_id_t key) |
Provide an input for key derivation in the form of a key. | |
psa_status_t | psa_key_derivation_key_agreement (psa_key_derivation_operation_t *operation, psa_key_derivation_step_t step, psa_key_id_t private_key, const uint8_t *peer_key, size_t peer_key_length) |
Perform a key agreement and use the shared secret as input to a key derivation. | |
psa_status_t | psa_key_derivation_output_bytes (psa_key_derivation_operation_t *operation, uint8_t *output, size_t output_length) |
Read some data from a key derivation operation. | |
psa_status_t | psa_key_derivation_output_key (const psa_key_attributes_t *attributes, psa_key_derivation_operation_t *operation, psa_key_id_t *key) |
Derive a key from an ongoing key derivation operation. | |
psa_status_t | psa_key_derivation_set_capacity (psa_key_derivation_operation_t *operation, size_t capacity) |
Set the maximum capacity of a key derivation operation. | |
psa_status_t | psa_key_derivation_setup (psa_key_derivation_operation_t *operation, psa_algorithm_t alg) |
Set up a key derivation operation. | |
psa_status_t | psa_key_derivation_verify_bytes (psa_key_derivation_operation_t *operation, const uint8_t *expected_output, size_t output_length) |
Compare output data from a key derivation operation to an expected value. | |
psa_status_t | psa_key_derivation_verify_key (psa_key_derivation_operation_t *operation, psa_key_id_t expected) |
Compare output data from a key derivation operation to an expected value stored in a key. | |
psa_status_t | psa_mac_abort (psa_mac_operation_t *operation) |
Abort a MAC operation. | |
psa_status_t | psa_mac_compute (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *mac, size_t mac_size, size_t *mac_length) |
Calculate the message authentication code (MAC) of a message. | |
psa_status_t | psa_mac_sign_finish (psa_mac_operation_t *operation, uint8_t *mac, size_t mac_size, size_t *mac_length) |
Finish the calculation of the MAC of a message. | |
psa_status_t | psa_mac_sign_setup (psa_mac_operation_t *operation, psa_key_id_t key, psa_algorithm_t alg) |
Set up a multi-part MAC calculation operation. | |
psa_status_t | psa_mac_update (psa_mac_operation_t *operation, const uint8_t *input, size_t input_length) |
Add a message fragment to a multi-part MAC operation. | |
psa_status_t | psa_mac_verify (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *mac, size_t mac_length) |
Calculate the MAC of a message and compare it with a reference value. | |
psa_status_t | psa_mac_verify_finish (psa_mac_operation_t *operation, const uint8_t *mac, size_t mac_length) |
Finish the calculation of the MAC of a message and compare it with an expected value. | |
psa_status_t | psa_mac_verify_setup (psa_mac_operation_t *operation, psa_key_id_t key, psa_algorithm_t alg) |
Set up a multi-part MAC verification operation. | |
psa_status_t | psa_purge_key (psa_key_id_t key) |
Remove non-essential copies of key material from memory. | |
psa_status_t | psa_raw_key_agreement (psa_algorithm_t alg, psa_key_id_t private_key, const uint8_t *peer_key, size_t peer_key_length, uint8_t *output, size_t output_size, size_t *output_length) |
Perform a key agreement and return the raw shared secret. | |
psa_status_t | psa_sign_hash (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, uint8_t *signature, size_t signature_size, size_t *signature_length) |
Sign an already-calculated hash with a private key. | |
psa_status_t | psa_sign_message (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *signature, size_t signature_size, size_t *signature_length) |
Sign a message with a private key. | |
psa_status_t | psa_verify_hash (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length) |
Verify the signature of a hash or short message using a public key. | |
psa_status_t | psa_verify_message (psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *signature, size_t signature_length) |
Verify the signature of a message with a public key. | |
#define PSA_CRYPTO_API_VERSION_MAJOR 1 |
#define PSA_CRYPTO_API_VERSION_MINOR 1 |
psa_status_t psa_aead_abort | ( | psa_aead_operation_t * | operation | ) |
Abort an AEAD operation.
Aborting an operation frees all associated resources except for the operation object itself. Once aborted, the operation object can be reused for another operation by calling psa_aead_encrypt_setup() or psa_aead_decrypt_setup() again.
This function can be called any time after the operation object has been initialized as described in psa_aead_operation_t.
In particular, calling psa_aead_abort() after the operation has been terminated by a call to psa_aead_abort(), psa_aead_finish() or psa_aead_verify() is safe and has no effect.
operation | Initialized AEAD operation. |
psa_status_t psa_aead_decrypt | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | nonce, | ||
size_t | nonce_length, | ||
const uint8_t * | additional_data, | ||
size_t | additional_data_length, | ||
const uint8_t * | ciphertext, | ||
size_t | ciphertext_length, | ||
uint8_t * | plaintext, | ||
size_t | plaintext_size, | ||
size_t * | plaintext_length | ||
) |
Process an authenticated decryption operation.
key | Identifier of the key to use for the operation. It must allow the usage PSA_KEY_USAGE_DECRYPT. |
alg | The AEAD algorithm to compute (PSA_ALG_XXX value such that PSA_ALG_IS_AEAD(alg ) is true). |
nonce | Nonce or IV to use. |
nonce_length | Size of the nonce buffer in bytes. This must be appropriate for the selected algorithm. The default nonce size is PSA_AEAD_NONCE_LENGTH(key_type , alg ) where key_type is the type of key . |
additional_data | Additional data that will be authenticated but not encrypted. |
additional_data_length | Size of additional_data in bytes. |
ciphertext | Data that has been authenticated and encrypted. For algorithms where the encrypted data and the authentication tag are defined as separate inputs, the buffer must contain the encrypted data followed by the authentication tag. |
ciphertext_length | Size of ciphertext in bytes. |
plaintext | Output buffer for the decrypted data. |
plaintext_size | Size of the plaintext buffer in bytes. This must be appropriate for the selected algorithm and key:
|
plaintext_length | On success, the size of the output in the plaintext buffer. |
key
is not compatible with alg
. alg
is not supported or is not an AEAD algorithm. plaintext_size
is too small. PSA_AEAD_DECRYPT_OUTPUT_SIZE() or PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE() can be used to determine the required buffer size. psa_status_t psa_aead_decrypt_setup | ( | psa_aead_operation_t * | operation, |
psa_key_id_t | key, | ||
psa_algorithm_t | alg | ||
) |
Set the key for a multi-part authenticated decryption operation.
The sequence of operations to decrypt a message with authentication is as follows:
If an error occurs at any step after a call to psa_aead_decrypt_setup(), the operation will need to be reset by a call to psa_aead_abort(). The application can call psa_aead_abort() at any time after the operation has been initialized.
After a successful call to psa_aead_decrypt_setup(), the application must eventually terminate the operation. The following events terminate an operation:
operation | The operation object to set up. It must have been initialized as per the documentation for psa_aead_operation_t and not yet in use. |
key | Identifier of the key to use for the operation. It must remain valid until the operation terminates. It must allow the usage PSA_KEY_USAGE_DECRYPT. |
alg | The AEAD algorithm to compute (PSA_ALG_XXX value such that PSA_ALG_IS_AEAD(alg ) is true). |
key
is not compatible with alg
. alg
is not supported or is not an AEAD algorithm. psa_status_t psa_aead_encrypt | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | nonce, | ||
size_t | nonce_length, | ||
const uint8_t * | additional_data, | ||
size_t | additional_data_length, | ||
const uint8_t * | plaintext, | ||
size_t | plaintext_length, | ||
uint8_t * | ciphertext, | ||
size_t | ciphertext_size, | ||
size_t * | ciphertext_length | ||
) |
Process an authenticated encryption operation.
key | Identifier of the key to use for the operation. It must allow the usage PSA_KEY_USAGE_ENCRYPT. |
alg | The AEAD algorithm to compute (PSA_ALG_XXX value such that PSA_ALG_IS_AEAD(alg ) is true). |
nonce | Nonce or IV to use. |
nonce_length | Size of the nonce buffer in bytes. This must be appropriate for the selected algorithm. The default nonce size is PSA_AEAD_NONCE_LENGTH(key_type , alg ) where key_type is the type of key. |
additional_data | Additional data that will be authenticated but not encrypted. |
additional_data_length | Size of additional_data in bytes. |
plaintext | Data that will be authenticated and encrypted. |
plaintext_length | Size of plaintext in bytes. |
ciphertext | Output buffer for the authenticated and encrypted data. The additional data is not part of this output. For algorithms where the encrypted data and the authentication tag are defined as separate outputs, the authentication tag is appended to the encrypted data. |
ciphertext_size | Size of the ciphertext buffer in bytes. This must be appropriate for the selected algorithm and key:
|
ciphertext_length | On success, the size of the output in the ciphertext buffer. |
key
is not compatible with alg
. alg
is not supported or is not an AEAD algorithm. ciphertext_size
is too small. PSA_AEAD_ENCRYPT_OUTPUT_SIZE() or PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE() can be used to determine the required buffer size. psa_status_t psa_aead_encrypt_setup | ( | psa_aead_operation_t * | operation, |
psa_key_id_t | key, | ||
psa_algorithm_t | alg | ||
) |
Set the key for a multi-part authenticated encryption operation.
The sequence of operations to encrypt a message with authentication is as follows:
If an error occurs at any step after a call to psa_aead_encrypt_setup(), the operation will need to be reset by a call to psa_aead_abort(). The application can call psa_aead_abort() at any time after the operation has been initialized.
After a successful call to psa_aead_encrypt_setup(), the application must eventually terminate the operation. The following events terminate an operation:
operation | The operation object to set up. It must have been initialized as per the documentation for psa_aead_operation_t and not yet in use. |
key | Identifier of the key to use for the operation. It must remain valid until the operation terminates. It must allow the usage PSA_KEY_USAGE_ENCRYPT. |
alg | The AEAD algorithm to compute (PSA_ALG_XXX value such that PSA_ALG_IS_AEAD(alg ) is true). |
key
is not compatible with alg
. alg
is not supported or is not an AEAD algorithm. psa_status_t psa_aead_finish | ( | psa_aead_operation_t * | operation, |
uint8_t * | ciphertext, | ||
size_t | ciphertext_size, | ||
size_t * | ciphertext_length, | ||
uint8_t * | tag, | ||
size_t | tag_size, | ||
size_t * | tag_length | ||
) |
Finish encrypting a message in an AEAD operation.
The operation must have been set up with psa_aead_encrypt_setup(). This function finishes the authentication of the additional data formed by concatenating the inputs passed to preceding calls to psa_aead_update_ad() with the plaintext formed by concatenating the inputs passed to preceding calls to psa_aead_update(). This function has two output buffers:
ciphertext
contains trailing ciphertext that was buffered from preceding calls to psa_aead_update().tag
contains the authentication tag.When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
operation | Active AEAD operation. |
ciphertext | Buffer where the last part of the ciphertext is to be written. |
ciphertext_size | Size of the ciphertext buffer in bytes. This must be appropriate for the selected algorithm and key:
|
ciphertext_length | On success, the number of bytes of returned ciphertext. |
tag | Buffer where the authentication tag is to be written. |
tag_size | Size of the tag buffer in bytes. This must be appropriate for the selected algorithm and key:
|
tag_length | On success, the number of bytes that make up the returned tag. |
psa_status_t psa_aead_generate_nonce | ( | psa_aead_operation_t * | operation, |
uint8_t * | nonce, | ||
size_t | nonce_size, | ||
size_t * | nonce_length | ||
) |
Generate a random nonce for an authenticated encryption operation.
This function generates a random nonce for the authenticated encryption operation with an appropriate size for the chosen algorithm, key type and key size.
The application must call psa_aead_encrypt_setup() before calling this function. If applicable for the algorithm, the application must call psa_aead_set_lengths() before calling this function.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
operation | Active AEAD operation. |
nonce | Buffer where the generated nonce is to be written. |
nonce_size | Size of the nonce buffer in bytes. This must be at least PSA_AEAD_NONCE_LENGTH(key_type , alg ) where key_type and alg are type of key and the algorithm respectively that were used to set up the AEAD operation. |
nonce_length | On success, the number of bytes of the generated nonce. |
psa_status_t psa_aead_set_lengths | ( | psa_aead_operation_t * | operation, |
size_t | ad_length, | ||
size_t | plaintext_length | ||
) |
Declare the lengths of the message and additional data for AEAD.
The application must call this function before calling psa_aead_set_nonce() or psa_aead_generate_nonce(), if the algorithm for the operation requires it. If the algorithm does not require it, calling this function is optional, but if this function is called then the implementation must enforce the lengths.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
operation | Active AEAD operation. |
ad_length | Size of the non-encrypted additional authenticated data in bytes. |
plaintext_length | Size of the plaintext to encrypt in bytes. |
psa_status_t psa_aead_set_nonce | ( | psa_aead_operation_t * | operation, |
const uint8_t * | nonce, | ||
size_t | nonce_length | ||
) |
Set the nonce for an authenticated encryption or decryption operation.
This function sets the nonce for the authenticated encryption or decryption operation. The application must call psa_aead_encrypt_setup() or psa_aead_decrypt_setup() before calling this function. If applicable for the algorithm, the application must call psa_aead_set_lengths() before calling this function.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
operation | Active AEAD operation. |
nonce | Buffer containing the nonce to use. |
nonce_length | Size of the nonce in bytes. This must be a valid nonce size for the chosen algorithm. The default nonce size is PSA_AEAD_NONCE_LENGTH (key_type , alg ) where key_type and alg are type of key and the algorithm respectively that were used to set up the AEAD operation. |
psa_status_t psa_aead_update | ( | psa_aead_operation_t * | operation, |
const uint8_t * | input, | ||
size_t | input_length, | ||
uint8_t * | output, | ||
size_t | output_size, | ||
size_t * | output_length | ||
) |
Encrypt or decrypt a message fragment in an active AEAD operation.
The following must occur before calling this function:
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
This function does not require the input to be aligned to any particular block boundary. If the implementation can only process a whole block at a time, it must consume all the input provided, but it might delay the end of the corresponding output until a subsequent call to psa_aead_update(), psa_aead_finish() or psa_aead_verify() provides sufficient input. The amount of data that can be delayed in this way is bounded by PSA_AEAD_UPDATE_OUTPUT_SIZE().
operation | Active AEAD operation. |
input | Buffer containing the message fragment to encrypt or decrypt. |
input_length | Size of the input buffer in bytes. |
output | Buffer where the output is to be written. |
output_size | Size of the output buffer in bytes. This must be appropriate for the selected algorithm and key:
|
output_length | On success, the number of bytes that make up the returned output. |
psa_status_t psa_aead_update_ad | ( | psa_aead_operation_t * | operation, |
const uint8_t * | input, | ||
size_t | input_length | ||
) |
Pass additional data to an active AEAD operation.
Additional data is authenticated, but not encrypted. This function can be called multiple times to pass successive fragments of the additional data. This function must not be called after passing data to encrypt or decrypt with psa_aead_update().
The following must occur before calling this function:
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
operation | Active AEAD operation. |
input | Buffer containing the fragment of additional data. |
input_length | Size of the input buffer in bytes. |
psa_status_t psa_aead_verify | ( | psa_aead_operation_t * | operation, |
uint8_t * | plaintext, | ||
size_t | plaintext_size, | ||
size_t * | plaintext_length, | ||
const uint8_t * | tag, | ||
size_t | tag_length | ||
) |
Finish authenticating and decrypting a message in an AEAD operation.
The operation must have been set up with psa_aead_decrypt_setup(). This function finishes the authenticated decryption of the message components:
If the authentication tag is correct, this function outputs any remaining plaintext and reports success. If the authentication tag is not correct, this function returns PSA_ERROR_INVALID_SIGNATURE.
When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
operation | Active AEAD operation. |
plaintext | Buffer where the last part of the plaintext is to be written. This is the remaining data from previous calls to psa_aead_update() that could not be processed until the end of the input. |
plaintext_size | Size of the plaintext buffer in bytes. This must be appropriate for the selected algorithm and key:
|
plaintext_length | On success, the number of bytes of returned plaintext. |
tag | Buffer containing the authentication tag. |
tag_length | Size of the tag buffer in bytes. |
psa_status_t psa_asymmetric_decrypt | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | input, | ||
size_t | input_length, | ||
const uint8_t * | salt, | ||
size_t | salt_length, | ||
uint8_t * | output, | ||
size_t | output_size, | ||
size_t * | output_length | ||
) |
Decrypt a short message with a private key.
For PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is supported.
key | Identifier of the key to use for the operation. It must be an asymmetric key pair. It must allow the usage PSA_KEY_USAGE_DECRYPT. |
alg | An asymmetric encryption algorithm that is compatible with the type of key. |
input | The message to decrypt. |
input_length | Size of the input buffer in bytes. |
salt | A salt or label, if supported by the encryption algorithm. If the algorithm does not support a salt, pass NULL . If the algorithm supports an optional salt, pass NULL to indicate that there is no salt. |
salt_length | Size of the salt buffer in bytes. If salt is NULL , pass 0. |
output | Buffer where the decrypted message is to be written. |
output_size | Size of the output buffer in bytes. This must be appropriate for the selected algorithm and key:
|
output_length | On success, the number of bytes that make up the returned output. |
psa_status_t psa_asymmetric_encrypt | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | input, | ||
size_t | input_length, | ||
const uint8_t * | salt, | ||
size_t | salt_length, | ||
uint8_t * | output, | ||
size_t | output_size, | ||
size_t * | output_length | ||
) |
Encrypt a short message with a public key.
For PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is supported.
key | Identifier of the key to use for the operation. It must be a public key or an asymmetric key pair. It must allow the usage PSA_KEY_USAGE_ENCRYPT. |
alg | An asymmetric encryption algorithm that is compatible with the type of key. |
input | The message to encrypt. |
input_length | Size of the input buffer in bytes. |
salt | A salt or label, if supported by the encryption algorithm. If the algorithm does not support a salt, pass NULL . If the algorithm supports an optional salt, pass NULL to indicate that there is no salt. |
salt_length | Size of the salt buffer in bytes. If salt is NULL , pass 0. |
output | Buffer where the encrypted message is to be written. |
output_size | Size of the output buffer in bytes. This must be appropriate for the selected algorithm and key:
|
output_length | On success, the number of bytes that make up the returned output. |
psa_status_t psa_builtin_generate_key | ( | const psa_key_attributes_t * | attributes, |
uint8_t * | key_buffer, | ||
size_t | key_buffer_size, | ||
size_t * | key_buffer_length | ||
) |
Built-in key generation function.
This function generates a random symmetric key. As of yet it does not implement asymmetric key generation.
attributes | |
key_buffer | |
key_buffer_size | |
key_buffer_length |
psa_status_t psa_builtin_generate_random | ( | uint8_t * | output, |
size_t | output_size | ||
) |
Built-in function for random number generation.
This function is being used to generate a random number if no other driver for random number generation is present. It uses the RIOT RNG module as a default backend.
output | Output buffer of the size of the random number to be generated. |
output_size | Size of output in bytes |
output
is NULL psa_status_t psa_builtin_import_key | ( | const psa_key_attributes_t * | attributes, |
const uint8_t * | data, | ||
size_t | data_length, | ||
uint8_t * | key_buffer, | ||
size_t | key_buffer_size, | ||
size_t * | key_buffer_length, | ||
size_t * | bits | ||
) |
Built-in key import function.
Copies a plain key into local memory. This function is used by the implementation, when an imported key is stored only in local memory.
attributes | The attributes for the new key. This function uses the attributes as follows:
|
data | Buffer containing the key data. The content of this buffer is interpreted according to the type declared in attributes. All implementations must support at least the format described in the documentation of psa_export_key() or psa_export_public_key() for the chosen type. Implementations can support other formats, but be conservative in interpreting the key data: it is recommended that implementations reject content if it might be erroneous, for example, if it is the wrong type or is truncated. |
data_length | Size of the data buffer in bytes. |
key_buffer | Pointer to buffer containing the plain text key material |
key_buffer_size | Size of key_buffer in bytes |
key_buffer_length | Size of the key buffer |
bits | Size of the key in bits |
data
. psa_status_t psa_cipher_abort | ( | psa_cipher_operation_t * | operation | ) |
Abort a cipher operation.
Aborting an operation frees all associated resources except for the operation object itself. Once aborted, the operation object can be reused for another operation by calling psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup() again.
This function can be called any time after the operation object has been initialized as described in psa_cipher_operation_t.
In particular, calling psa_cipher_abort() after the operation has been terminated by a call to psa_cipher_abort() or psa_cipher_finish() is safe and has no effect.
operation | Initialized cipher operation. |
psa_status_t psa_cipher_decrypt | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | input, | ||
size_t | input_length, | ||
uint8_t * | output, | ||
size_t | output_size, | ||
size_t * | output_length | ||
) |
Decrypt a message using a symmetric cipher.
This function decrypts a message encrypted with a symmetric cipher. * The input to this function must contain the IV followed by the ciphertext, as output by psa_cipher_encrypt(). The IV must be PSA_CIPHER_IV_LENGTH(key_type
, alg
) bytes in length, where key_type
is the type of key.
Use the multi-part operation interface with a psa_cipher_operation_t object to decrypt data which is not in the expected input format.
key | Identifier of the key to use for the operation. It must remain valid until the operation terminates. It must allow the usage PSA_KEY_USAGE_DECRYPT. |
alg | The cipher algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_CIPHER(alg ) is true. |
input | Buffer containing the message to decrypt. This consists of the IV followed by the ciphertext proper. |
input_length | Size of the input buffer in bytes. |
output | Buffer where the plaintext is to be written. |
output_size | Size of the output buffer in bytes. This must be appropriate for the selected algorithm and key:
|
output_length | On success, the number of bytes that make up the output. |
(*output_length) bytes of output
contain the plaintext. key
is not a valid key identifier. alg
is not a cipher algorithm.key
is not compatible with alg.alg
is not supported or is not a cipher algorithm.key
is not supported for use with alg.input_length
is too large for the implementation. psa_status_t psa_cipher_decrypt_setup | ( | psa_cipher_operation_t * | operation, |
psa_key_id_t | key, | ||
psa_algorithm_t | alg | ||
) |
Set the key for a multi-part symmetric decryption operation.
The sequence of operations to decrypt a message with a symmetric cipher is as follows:
If an error occurs at any step after a call to psa_cipher_decrypt_setup(), the operation will need to be reset by a call to psa_cipher_abort(). The application can call psa_cipher_abort() at any time after the operation has been initialized.
After a successful call to psa_cipher_decrypt_setup(), the application must eventually terminate the operation. The following events terminate an operation:
operation | The operation object to set up. It must have been initialized as per the documentation for psa_cipher_operation_t and not yet in use. |
key | Identifier of the key to use for the operation. It must remain valid until the operation terminates. It must allow the usage PSA_KEY_USAGE_DECRYPT. |
alg | The cipher algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_CIPHER(alg ) is true. |
key
is not a valid key identifier. alg
is not a cipher algorithm.key
is not compatible with alg. alg
is not supported or is not a cipher algorithm.key
is not supported for use with alg. psa_status_t psa_cipher_encrypt | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | input, | ||
size_t | input_length, | ||
uint8_t * | output, | ||
size_t | output_size, | ||
size_t * | output_length | ||
) |
Encrypt a message using a symmetric cipher.
This function encrypts a message with a random initialization vector (IV). The length of the IV is PSA_CIPHER_IV_LENGTH(key_type
, alg
) where key_type
is the type of key. The output of psa_cipher_encrypt() is the IV followed by the ciphertext.
Use the multi-part operation interface with a psa_cipher_operation_t object to provide other forms of IV or to manage the IV and ciphertext independently.
key | Identifier of the key to use for the operation. It must allow the usage PSA_KEY_USAGE_ENCRYPT. |
alg | The cipher algorithm to compute (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg ) is true). |
input | Buffer containing the message to encrypt. |
input_length | Size of the input buffer in bytes. |
output | Buffer where the output is to be written. The output contains the IV followed by the ciphertext proper. |
output_size | Size of the output buffer in bytes. This must be appropriate for the selected algorithm and key:
|
output_length | On success, the number of bytes that make up the output. |
key
is not compatible with alg. input_length
is not valid for the algorithm and key type. For example, the algorithm is a based on block cipher and requires a whole number of blocks, but the total input size is not a multiple of the block size. alg
is not supported or is not a cipher algorithm. output_size
is too small. PSA_CIPHER_ENCRYPT_OUTPUT_SIZE() or PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE() can be used to determine the required buffer size. psa_status_t psa_cipher_encrypt_setup | ( | psa_cipher_operation_t * | operation, |
psa_key_id_t | key, | ||
psa_algorithm_t | alg | ||
) |
Set the key for a multi-part symmetric encryption operation.
The sequence of operations to encrypt a message with a symmetric cipher is as follows:
If an error occurs at any step after a call to psa_cipher_encrypt_setup(), the operation will need to be reset by a call to psa_cipher_abort(). The application can call psa_cipher_abort() at any time after the operation has been initialized.
After a successful call to psa_cipher_encrypt_setup(), the application must eventually terminate the operation. The following events terminate an operation:
operation | The operation object to set up. It must have been initialized as per the documentation for psa_cipher_operation_t and not yet in use. |
key | Identifier of the key to use for the operation. It must remain valid until the operation terminates. It must allow the usage PSA_KEY_USAGE_ENCRYPT. |
alg | The cipher algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_CIPHER(alg ) is true. |
key
is not a valid key identifier. alg
is not a cipher algorithm.key
is not compatible with alg. alg
is not supported or is not a cipher algorithm.key
is not supported for use with alg
. psa_status_t psa_cipher_finish | ( | psa_cipher_operation_t * | operation, |
uint8_t * | output, | ||
size_t | output_size, | ||
size_t * | output_length | ||
) |
Finish encrypting or decrypting a message in a cipher operation.
The application must call psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup() before calling this function. The choice of setup function determines whether this function encrypts or decrypts its input.
This function finishes the encryption or decryption of the message formed by concatenating the inputs passed to preceding calls to psa_cipher_update().
When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_cipher_abort().
operation | Active cipher operation. |
output | Buffer where the output is to be written. |
output_size | Size of the output buffer in bytes. This must be appropriate for the selected algorithm and key:
|
output_length | On success, the number of bytes that make up the returned output. |
(*output_length) bytes of output
contain the final output. psa_status_t psa_cipher_generate_iv | ( | psa_cipher_operation_t * | operation, |
uint8_t * | iv, | ||
size_t | iv_size, | ||
size_t * | iv_length | ||
) |
Generate an initialization vector (IV) for a symmetric encryption operation.
This function generates a random IV, nonce or initial counter value for the encryption operation as appropriate for the chosen algorithm, key type and key size.
The generated IV is always the default length for the key and algorithm: PSA_CIPHER_IV_LENGTH(key_type
, alg
), where key_type
is the type of key and alg
is the algorithm that were used to set up the operation. To generate different lengths of IV, use psa_generate_random() and psa_cipher_set_iv().
If the cipher algorithm does not use an IV, calling this function returns a PSA_ERROR_BAD_STATE error. For these algorithms, PSA_CIPHER_IV_LENGTH( key_type
, alg
) will be zero.
The application must call psa_cipher_encrypt_setup() before calling this function.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_cipher_abort().
operation | Active cipher operation. |
iv | Buffer where the generated IV is to be written. |
iv_size | Size of the iv buffer in bytes. This must be at least PSA_CIPHER_IV_LENGTH(key_type , alg ) where key_type and alg are type of key and the algorithm respectively that were used to set up the cipher operation. |
iv_length | On success, the number of bytes of the generated IV. |
psa_status_t psa_cipher_set_iv | ( | psa_cipher_operation_t * | operation, |
const uint8_t * | iv, | ||
size_t | iv_length | ||
) |
Set the initialization vector (IV) for a symmetric encryption or decryption operation.
This function sets the IV, nonce or initial counter value for the encryption or decryption operation.
If the cipher algorithm does not use an IV, calling this function returns a PSA_ERROR_BAD_STATE error. For these algorithms, PSA_CIPHER_IV_LENGTH(key_type, alg) will be zero.
The application must call psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup() before calling this function.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_cipher_abort().
operation | Active cipher operation. |
iv | Buffer containing the IV to use. |
iv_length | Size of the IV in bytes. |
iv_length
is not valid for the chosen algorithm. iv_length
is not supported for use with the operation’s algorithm and key. psa_status_t psa_cipher_update | ( | psa_cipher_operation_t * | operation, |
const uint8_t * | input, | ||
size_t | input_length, | ||
uint8_t * | output, | ||
size_t | output_size, | ||
size_t * | output_length | ||
) |
Encrypt or decrypt a message fragment in an active cipher operation.
The following must occur before calling this function:
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_cipher_abort().
operation | Active cipher operation. |
input | Buffer containing the message fragment to encrypt or decrypt. |
input_length | Size of the input buffer in bytes. |
output | Buffer where the output is to be written. |
output_size | Size of the output buffer in bytes. This must be appropriate for the selected algorithm and key:
|
output_length | On success, the number of bytes that make up the returned output. |
(*output_length) bytes of output
contain the output data. psa_status_t psa_copy_key | ( | psa_key_id_t | source_key, |
const psa_key_attributes_t * | attributes, | ||
psa_key_id_t * | target_key | ||
) |
Make a copy of a key.
Copy key material from one location to another. * This function is primarily useful to copy a key from one location to another, as it populates a key using the material from another key which can have a different lifetime.
This function can be used to share a key with a different party, subject to implementation-defined restrictions on key sharing.
The policy on the source key must have the usage flag PSA_KEY_USAGE_COPY set. This flag is sufficient to permit the copy if the key has the lifetime PSA_KEY_LIFETIME_VOLATILE or PSA_KEY_LIFETIME_PERSISTENT. Some secure elements do not provide a way to copy a key without making it extractable from the secure element. If a key is located in such a secure element, then the key must have both usage flags PSA_KEY_USAGE_COPY and PSA_KEY_USAGE_EXPORT in order to make a copy of the key outside the secure element.
The resulting key can only be used in a way that conforms to both the policy of the original key and the policy specified in the attributes parameter:
The effect of this function on implementation-defined attributes is implementation-defined.
source_key | The key to copy. It must allow the usage PSA_KEY_USAGE_COPY. If a private or secret key is being copied outside of a secure element it must also allow PSA_KEY_USAGE_EXPORT. |
attributes | The attributes for the new key. This function uses the attributes as follows:
|
target_key | On success, an identifier for the newly created key. PSA_KEY_ID_NULL on failure. |
source_key
is not a valid key identifier. source_key
does not have the PSA_KEY_USAGE_COPY usage flag.source_key
does not have the PSA_KEY_USAGE_EXPORT usage flag, and its storage location does not allow copying it to the target key’s storage location.The
implementation does not permit creating a key with the specified attributes due to some implementation-specific policy. attributes
specifies a key type or key size which does not match the attributes of source_key
.attributes
are invalid.source_key
and those specified in attributes
are incompatible. source_key
storage location does not support copying to the target key’s storage location.psa_status_t psa_crypto_init | ( | void | ) |
Library initialization.
Applications must call this function before calling any other function in this module. Applications are permitted to call this function more than once. Once a call succeeds, subsequent calls are guaranteed to succeed.
If the application calls other functions before calling psa_crypto_init(), the behavior is undefined. In this situation:
psa_status_t psa_destroy_key | ( | psa_key_id_t | key | ) |
Destroy a key.
This function destroys a key from both volatile memory and, if applicable, non-volatile storage. Implementations must make a best effort to ensure that that the key material cannot be recovered.
This function also erases any metadata such as policies and frees resources associated with the key. Destroying the key makes the key identifier invalid, and the key identifier must not be used again by the application.
If a key is currently in use in a multi-part operation, then destroying the key will cause the multi-part operation to fail.
key | Identifier of the key to erase. If this is PSA_KEY_ID_NULL, do nothing and return PSA_SUCCESS. |
key
was a valid key identifier, then the key material that it referred to has been erased. Alternatively, key
was PSA_KEY_ID_NULL. key
is neither a valid key identifier, nor PSA_KEY_ID_NULL. psa_status_t psa_export_key | ( | psa_key_id_t | key, |
uint8_t * | data, | ||
size_t | data_size, | ||
size_t * | data_length | ||
) |
Export a key in binary format.
The output of this function can be passed to psa_import_key() to create an equivalent object.
If the implementation of psa_import_key() supports other formats beyond the format specified here, the output from psa_export_key() must use the representation specified here, not the original representation.
For standard key types, the output format is as follows:
PSA_ECC_FAMILY_SECT_XX
, PSA_ECC_FAMILY_SECP_XX
, PSA_ECC_FAMILY_FRP and PSA_ECC_FAMILY_BRAINPOOL_P_R1, the content of the privateKey
field of the ECPrivateKey
format defined by Elliptic Curve Private Key Structure [RFC5915]. This is a ceiling
(m/8)-byte string in big-endian order where m
is the key size in bits.decodeScalar25519()
and decodeScalar448()
in [RFC7748] §5. This is a ceiling
(m/8)-byte string where m
is the key size in bits. This is 32 bytes for Curve25519, and 56 bytes for Curve448.The policy on the key must have the usage flag PSA_KEY_USAGE_EXPORT set.
key | Identifier of the key to export. It must allow the usage PSA_KEY_USAGE_EXPORT, unless it is a public key. |
data | Buffer where the key data is to be written. |
data_size | Size of the data buffer in bytes. This must be appropriate for the key:
|
data_length | On success, the number of bytes that make up the key data. |
(*data_length) bytes of data contain the exported key key
is not a valid key identifier. psa_status_t psa_export_public_key | ( | psa_key_id_t | key, |
uint8_t * | data, | ||
size_t | data_size, | ||
size_t * | data_length | ||
) |
Export a public key or the public part of a key pair in binary format.
The output of this function can be passed to psa_import_key() to create an object that is equivalent to the public key.
If the implementation of psa_import_key() supports other formats beyond the format specified here, the output from psa_export_public_key() must use the representation specified here, not the original representation.
For standard key types, the output format is as follows:
RSAPublicKey
. PSA_ECC_FAMILY_SECT_XX
, PSA_ECC_FAMILY_SECP_XX
, PSA_ECC_FAMILY_FRP and PSA_ECC_FAMILY_BRAINPOOL_P_R1, the uncompressed representation of an elliptic curve point as an octet string defined in SEC 1: Elliptic Curve Cryptography [SEC1] §2.3.3. If m
is the bit size associated with the curve, i.e. the bit size of q
for a curve over F_q
. The representation consists of:0x04
;x_P
as a ceiling
(m/8)-byte string, big-endian;y_P
as a ceiling
(m/8)-byte string, big-endian.ceiling
(m/8)-byte string where m
is the key size in bits.X25519(private_key, 9)
.X448(private_key, 5)
.y = g^x mod p
as a big-endian byte string. The length of the byte string is the length of the base prime p in bytes. Exporting a public key object or the public part of a key pair is always permitted, regardless of the key’s usage flags.key | Identifier of the key to export. |
data | Buffer where the key data is to be written. |
data_size | Size of the data buffer in bytes. This must be appropriate for the key:
|
data_length | On success, the number of bytes that make up the key data. |
(*data_length) bytes of data
contain the exported public key. key
is not a valid key identifier. psa_status_t psa_generate_key | ( | const psa_key_attributes_t * | attributes, |
psa_key_id_t * | key | ||
) |
Generate a key or key pair.
The key is generated randomly. Its location, policy, type and size are taken from attributes
.
Implementations must reject an attempt to generate a key of size 0.
The following type-specific considerations apply:
attributes | The attributes for the new key. This function uses the attributes as follows:
|
key | On success, an identifier for the newly created key. PSA_KEY_ID_NULL on failure. |
psa_status_t psa_generate_random | ( | uint8_t * | output, |
size_t | output_size | ||
) |
Generate random bytes.
output | Output buffer for the generated data. |
output_size | Number of bytes to generate and output. |
output
contains output_size
bytes of generated random data. output
is NULL
|
inlinestatic |
Retrieve the permitted algorithm policy from key attributes.
attributes | The key attribute object to query. |
psa_status_t psa_get_key_attributes | ( | psa_key_id_t | key, |
psa_key_attributes_t * | attributes | ||
) |
Retrieve the attributes of a key.
This function first resets the attribute object as with psa_reset_key_attributes(). It then copies the attributes of the given key into the given attribute object.
key | Identifier of the key to query. |
attributes | On entry, *attributes must be in a valid state. On successful return, it contains the attributes of the key. On failure, it is equivalent to a freshly-initialized attribute object. |
|
inlinestatic |
|
inlinestatic |
Retrieve the key identifier from key attributes.
attributes | The key attribute object to query. |
|
inlinestatic |
Retrieve the lifetime from key attributes.
attributes | The key attribute object to query. |
|
inlinestatic |
Retrieve the key type from key attributes.
attributes | The key attribute object to query. |
|
inlinestatic |
Retrieve the usage flags from key attributes.
attributes | The key attribute object to query. |
psa_status_t psa_hash_abort | ( | psa_hash_operation_t * | operation | ) |
Abort a hash operation.
Aborting an operation frees all associated resources except for the operation
structure itself. Once aborted, the operation object can be reused for another operation by calling psa_hash_setup() again.
You may call this function any time after the operation object has been initialized by one of the methods described in psa_hash_operation_t.
In particular, calling psa_hash_abort() after the operation has been terminated by a call to psa_hash_abort(), psa_hash_finish() or psa_hash_verify() is safe and has no effect.
operation | Initialized hash operation. |
psa_status_t psa_hash_clone | ( | const psa_hash_operation_t * | source_operation, |
psa_hash_operation_t * | target_operation | ||
) |
Clone a hash operation.
This function copies the state of an ongoing hash operation to a new operation object. In other words, this function is equivalent to calling psa_hash_setup() on target_operation
with the same algorithm that source_operation
was set up for, then psa_hash_update() on target_operation
with the same input that that was passed to source_operation
. After this function returns, the two objects are independent, i.e. subsequent calls involving one of the objects do not affect the other object.
source_operation | The active hash operation to clone. |
target_operation | The operation object to set up. It must be initialized but not active. |
source_operation
state is not valid: it must be active.target_operation
state is not valid: it must be inactive.psa_status_t psa_hash_compare | ( | psa_algorithm_t | alg, |
const uint8_t * | input, | ||
size_t | input_length, | ||
const uint8_t * | hash, | ||
size_t | hash_length | ||
) |
Calculate the hash (digest) of a message and compare it with a reference value.
alg | The hash algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_HASH(alg ) is true. |
input | Buffer containing the message to hash. |
input_length | Size of the input buffer in bytes. |
hash | Buffer containing the expected hash value. |
hash_length | Size of the hash buffer in bytes. |
alg
is not a hash algorithm.input_length
is too large for alg. alg
is not supported or is not a hash algorithm.input_length
is too large for the implementation. psa_status_t psa_hash_compute | ( | psa_algorithm_t | alg, |
const uint8_t * | input, | ||
size_t | input_length, | ||
uint8_t * | hash, | ||
size_t | hash_size, | ||
size_t * | hash_length | ||
) |
Calculate the hash (digest) of a message.
alg | The hash algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_HASH(alg ) is true. |
input | Buffer containing the message to hash. |
input_length | Size of the input buffer in bytes. |
hash | Buffer where the hash is to be written. |
hash_size | Size of the hash buffer in bytes. This must be at least PSA_HASH_LENGTH(alg ). |
hash_length | On success, the number of bytes that make up the hash value. This is always PSA_HASH_LENGTH(alg ). |
(*hash_length) bytes of hash
contain the hash value. alg
is not a hash algorithminput_length
is too large for alg. alg
is not supported or is not a hash algorithm.input_length
is too large for the implementation. psa_status_t psa_hash_finish | ( | psa_hash_operation_t * | operation, |
uint8_t * | hash, | ||
size_t | hash_size, | ||
size_t * | hash_length | ||
) |
Finish the calculation of the hash of a message.
The application must call psa_hash_setup() before calling this function. This function calculates the hash of the message formed by concatenating the inputs passed to preceding calls to psa_hash_update().
When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_hash_abort().
memcmp
is risky because the time taken by the comparison may leak information about the hashed data which could allow an attacker to guess a valid hash and thereby bypass security controls.operation | Active hash operation. |
hash | Buffer where the hash is to be written. |
hash_size | Size of the hash buffer in bytes. This must be at least PSA_HASH_LENGTH(alg ) where alg is the algorithm that the operation performs. |
hash_length | On success, the number of bytes that make up the hash value. This is always PSA_HASH_LENGTH(alg ) where alg is the hash algorithm that is calculated. |
(*hash_length) bytes of hash
contain the hash value. psa_status_t psa_hash_resume | ( | psa_hash_operation_t * | operation, |
const uint8_t * | hash_state, | ||
size_t | hash_state_length | ||
) |
Set up a multi-part hash operation using the hash suspend state from a previously suspended hash operation.
See psa_hash_suspend() for an example of how to use this function to suspend and resume a hash operation.
After a successful call to psa_hash_resume(), the application must eventually terminate the operation. The following events terminate an operation:
operation | The operation object to set up. It must have been initialized as per the documentation for psa_hash_operation_t and not yet in use. |
hash_state | A buffer containing the suspended hash state which is to be resumed. This must be in the format output by psa_hash_suspend(). |
hash_state_length | Length of hash_state in bytes. |
hash_state
does not correspond to a valid hash suspend state. See Hash suspend state format for the definition. psa_status_t psa_hash_setup | ( | psa_hash_operation_t * | operation, |
psa_algorithm_t | alg | ||
) |
Set up a multipart hash operation.
The sequence of operations to calculate a hash (message digest) is as follows:
If an error occurs at any step after a call to psa_hash_setup(), the operation will need to be reset by a call to psa_hash_abort(). The application may call psa_hash_abort() at any time after the operation has been initialized.
After a successful call to psa_hash_setup(), the application must eventually terminate the operation. The following events terminate an operation:
operation | The operation object to set up. It must have been initialized as per the documentation for psa_hash_operation_t and not yet in use. |
alg | The hash algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_HASH(alg ) is true. |
alg
is not a hash algorithm. alg
is not supported or is not a hash algorithm. psa_status_t psa_hash_suspend | ( | psa_hash_operation_t * | operation, |
uint8_t * | hash_state, | ||
size_t | hash_state_size, | ||
size_t * | hash_state_length | ||
) |
Halt the hash operation and extract the intermediate state of the hash computation.
The application must call psa_hash_setup() or psa_hash_resume() before calling this function. This function extracts an intermediate state of the hash computation of the message formed by concatenating the inputs passed to preceding calls to psa_hash_update().
This function can be used to halt a hash operation, and then resume the hash operation at a later time, or in another application, by transferring the extracted hash suspend state to a call to psa_hash_resume().
When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_hash_abort().
Hash suspend and resume is not defined for the SHA3 family of hash algorithms. Hash suspend state defines the format of the output from psa_hash_suspend().
The sequence of operations to suspend and resume a hash operation is as follows:
If an error occurs at any step after a call to psa_hash_setup() or psa_hash_resume(), the operation will need to be reset by a call to psa_hash_abort(). The application can call psa_hash_abort() at any time after the operation has been initialized.
operation | Active hash operation. |
hash_state | Buffer where the hash suspend state is to be written. |
hash_state_size | Size of the hash_state buffer in bytes. This must be appropriate for the selected algorithm:
|
hash_state_length | On success, the number of bytes that make up the hash suspend state. |
(*hash_state_length) bytes of hash_state
contain the intermediate hash state. psa_status_t psa_hash_update | ( | psa_hash_operation_t * | operation, |
const uint8_t * | input, | ||
size_t | input_length | ||
) |
Add a message fragment to a multi-part hash operation.
The application must call psa_hash_setup() before calling this function. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_hash_abort().
operation | Active hash operation. |
input | Buffer containing the message fragment to hash. |
input_length | Size of the input buffer in bytes. |
psa_status_t psa_hash_verify | ( | psa_hash_operation_t * | operation, |
const uint8_t * | hash, | ||
size_t | hash_length | ||
) |
Finish the calculation of the hash of a message and compare it with an expected value.
The application must call psa_hash_setup() before calling this function. This function calculates the hash of the message formed by concatenating the inputs passed to preceding calls to psa_hash_update(). It then compares the calculated hash with the expected hash passed as a parameter to this function.
When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_hash_abort().
operation | Active hash operation. |
hash | Buffer containing the expected hash value. |
hash_length | Size of the hash buffer in bytes. |
psa_status_t psa_import_key | ( | const psa_key_attributes_t * | attributes, |
const uint8_t * | data, | ||
size_t | data_length, | ||
psa_key_id_t * | key | ||
) |
Import a key in binary format.
This function supports any output from psa_export_key(). Refer to the documentation of psa_export_public_key() for the format of public keys and to the documentation of psa_export_key() for the format for other key types.
The key data determines the key size. The attributes can optionally specify a key size; in this case it must match the size determined from the key data. A key size of 0 in attributes indicates that the key size is solely determined by the key data.
Implementations must reject an attempt to import a key of size 0.
This specification defines a single format for each key type. Implementations can optionally support other formats in addition to the standard format. It is recommended that implementations that support other formats ensure that the formats are clearly unambiguous, to minimize the risk that an invalid input is accidentally interpreted according to a different format.
attributes | The attributes for the new key. This function uses the attributes as follows:
|
data | Buffer containing the key data. The content of this buffer is interpreted according to the type declared in attributes. All implementations must support at least the format described in the documentation of psa_export_key() or psa_export_public_key() for the chosen type. Implementations can support other formats, but be conservative in interpreting the key data: it is recommended that implementations reject content if it might be erroneous, for example, if it is the wrong type or is truncated. |
data_length | Size of the data buffer in bytes. |
key | On success, an identifier for the newly created key. PSA_KEY_ID_NULL on failure. |
data
.psa_status_t psa_key_derivation_abort | ( | psa_key_derivation_operation_t * | operation | ) |
Abort a key derivation operation.
Aborting an operation frees all associated resources except for the operation object itself. Once aborted, the operation object can be reused for another operation by calling psa_key_derivation_setup() again.
This function can be called at any time after the operation object has been initialized as described in psa_key_derivation_operation_t.
In particular, it is valid to call psa_key_derivation_abort() twice, or to call psa_key_derivation_abort() on an operation that has not been set up.
operation | The operation to abort. |
psa_status_t psa_key_derivation_get_capacity | ( | const psa_key_derivation_operation_t * | operation, |
size_t * | capacity | ||
) |
Retrieve the current capacity of a key derivation operation.
The capacity of a key derivation is the maximum number of bytes that it can return. Reading N bytes of output from a key derivation operation reduces its capacity by at least N. The capacity can be reduced by more than N in the following situations:
operation | The operation to query. |
capacity | On success, the capacity of the operation. |
*capacity
). psa_status_t psa_key_derivation_input_bytes | ( | psa_key_derivation_operation_t * | operation, |
psa_key_derivation_step_t | step, | ||
const uint8_t * | data, | ||
size_t | data_length | ||
) |
Provide an input for key derivation or key agreement.
Which inputs are required and in what order depends on the algorithm. Refer to the documentation of each key derivation or key agreement algorithm for information.
This function passes direct inputs, which is usually correct for non-secret inputs. To pass a secret input, which is normally in a key object, call psa_key_derivation_input_key() instead of this function. Refer to the documentation of individual step types (PSA_KEY_DERIVATION_INPUT_xxx
values of type psa_key_derivation_step_t) for more information.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
operation | The key derivation operation object to use. It must have been set up with psa_key_derivation_setup() and must not have produced any output yet. |
step | Which step the input data is for. |
data | Input data to use. |
data_length | Size of the data buffer in bytes. |
step
is not compatible with the operation’s algorithm.step
does not allow direct inputs.data_length
is too small or too large for step in this particular algorithm. step
is not supported with the operation’s algorithm.data_length
is is not supported for step in this particular algorithm. psa_status_t psa_key_derivation_input_integer | ( | psa_key_derivation_operation_t * | operation, |
psa_key_derivation_step_t | step, | ||
uint64_t | value | ||
) |
Provide a numeric input for key derivation or key agreement.
Which inputs are required and in what order depends on the algorithm. However, when an algorithm requires a particular order, numeric inputs usually come first as they tend to be configuration parameters. Refer to the documentation of each key derivation or key agreement algorithm for information.
This function is used for inputs which are fixed-size non-negative integers.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
operation | The key derivation operation object to use. It must have been set up with psa_key_derivation_setup() and must not have produced any output yet. |
step | Which step the input data is for. |
value | The value of the numeric input. |
step
is not compatible with the operation’s algorithm.step
does not allow numerical inputs.value
is not valid for step in the operation’s algorithm. step
is not supported with the operation’s algorithm.value
is not supported for step in the operation’s algorithm. psa_status_t psa_key_derivation_input_key | ( | psa_key_derivation_operation_t * | operation, |
psa_key_derivation_step_t | step, | ||
psa_key_id_t | key | ||
) |
Provide an input for key derivation in the form of a key.
Which inputs are required and in what order depends on the algorithm. Refer to the documentation of each key derivation or key agreement algorithm for information.
This function obtains input from a key object, which is usually correct for secret inputs or for non-secret personalization strings kept in the key store. To pass a non-secret parameter which is not in the key store, call psa_key_derivation_input_bytes() instead of this function. Refer to the documentation of individual step types (PSA_KEY_DERIVATION_INPUT_xxx
values of type psa_key_derivation_step_t) for more information.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
operation | The key derivation operation object to use. It must have been set up with psa_key_derivation_setup() and must not have produced any output yet. |
step | Which step the input data is for. |
key | Identifier of the key. The key must have an appropriate type for step, it must allow the usage PSA_KEY_USAGE_DERIVE or PSA_KEY_USAGE_VERIFY_DERIVATION (see note), and it must permit the algorithm used by the operation. |
key
is not a valid key identifier. step
is not compatible with the operation’s algorithm.step
does not allow key inputs of the given type, or does not allow key inputs at all. step
is not supported with the operation’s algorithm.Key
inputs of the given type are not supported for step in the operation’s algorithm. psa_status_t psa_key_derivation_key_agreement | ( | psa_key_derivation_operation_t * | operation, |
psa_key_derivation_step_t | step, | ||
psa_key_id_t | private_key, | ||
const uint8_t * | peer_key, | ||
size_t | peer_key_length | ||
) |
Perform a key agreement and use the shared secret as input to a key derivation.
A key agreement algorithm takes two inputs: a private key private_key
, and a public key peer_key
. The result of this function is passed as input to the key derivation operation. The output of this key derivation can be extracted by reading from the resulting operation to produce keys and other cryptographic material.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
operation | The key derivation operation object to use. It must have been set up with psa_key_derivation_setup() with a key agreement and derivation algorithm alg: a value of type psa_algorithm_t such that PSA_ALG_IS_KEY_AGREEMENT(alg ) is true and PSA_ALG_IS_RAW_KEY_AGREEMENT(alg ) is false. The operation must be ready for an input of the type given by step. |
step | Which step the input data is for. |
private_key | Identifier of the private key to use. It must allow the usage PSA_KEY_USAGE_DERIVE. |
peer_key | Public key of the peer. The peer key must be in the same format that psa_import_key() accepts for the public key type corresponding to the type of private_key . That is, this function performs the equivalent of psa_import_key(..., peer_key , peer_key_length ), with key attributes indicating the public key type corresponding to the type of private_key . For example, for ECC keys, this means that peer_key is interpreted as a point on the curve that the private key is on. The standard formats for public keys are documented in the documentation of psa_export_public_key(). |
peer_key_length | Size of peer_key in bytes. |
private_key
is not a valid key identifier. private_key
does not have the PSA_KEY_USAGE_DERIVE flag, or it does not permit the operation’s algorithm. step
does not allow an input resulting from a key agreement.private_key
is not compatible with the operation’s algorithm.peer_key
is not a valid public key corresponding to private_key
. private_key
is not supported for use with the operation’s algorithm. psa_status_t psa_key_derivation_output_bytes | ( | psa_key_derivation_operation_t * | operation, |
uint8_t * | output, | ||
size_t | output_length | ||
) |
Read some data from a key derivation operation.
This function calculates output bytes from a key derivation algorithm and returns those bytes. If the key derivation’s output is viewed as a stream of bytes, this function consumes the requested number of bytes from the stream and returns them to the caller. The operation’s capacity decreases by the number of bytes read.
If this function returns an error status other than PSA_ERROR_INSUFFICIENT_DATA, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
operation | The key derivation operation object to read from. |
output | Buffer where the output will be written. |
output_length | Number of bytes to output. |
output_length
bytes. In this case, the following occurs:psa_status_t psa_key_derivation_output_key | ( | const psa_key_attributes_t * | attributes, |
psa_key_derivation_operation_t * | operation, | ||
psa_key_id_t * | key | ||
) |
Derive a key from an ongoing key derivation operation.
This function calculates output bytes from a key derivation algorithm and uses those bytes to generate a key deterministically. The key’s location, policy, type and size are taken from attributes.
If the key derivation’s output is viewed as a stream of bytes, this function consumes the required number of bytes from the stream. The operation’s capacity decreases by the number of bytes used to derive the key.
If this function returns an error status other than PSA_ERROR_INSUFFICIENT_DATA, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
How much output is produced and consumed from the operation, and how the key is derived, depends on the key type.
(bits/8) bytes from the operation. The following key types defined in this specification follow this scheme:dh_family
) where dh_family
designates any Diffie-Hellman family.ecc_family
) where ecc_family
designates a Weierstrass curve family.) require the generation of a private key which is an integer in the range [1, N - 1], where N is the boundary of the private key domain: N is the prime p for Diffie-Hellman, or the order of the curve’s base point for ECC. Let m be the bit size of N, such that 2^m > N >= 2^(m-1). This function generates the private key using the following process:In all cases, the data that is read is discarded from the operation. The operation’s capacity is decreased by the number of bytes read.
For algorithms that take an input step PSA_KEY_DERIVATION_INPUT_SECRET, the input to that step must be provided with psa_key_derivation_input_key(). Future versions of this specification might include additional restrictions on the derived key based on the attributes and strength of the secret key.
attributes | The attributes for the new key. This function uses the attributes as follows:
|
operation | The key derivation operation object to read from. |
key | On success, an identifier for the newly created key. PSA_KEY_ID_NULL on failure. |
psa_status_t psa_key_derivation_set_capacity | ( | psa_key_derivation_operation_t * | operation, |
size_t | capacity | ||
) |
Set the maximum capacity of a key derivation operation.
The capacity of a key derivation operation is the maximum number of bytes that the key derivation operation can return from this point onwards.
operation | The key derivation operation object to modify. |
capacity | The new capacity of the operation. It must be less or equal to the operation’s current capacity. |
capacity
is larger than the operation’s current capacity. In this case, the operation object remains valid and its capacity remains unchanged. psa_status_t psa_key_derivation_setup | ( | psa_key_derivation_operation_t * | operation, |
psa_algorithm_t | alg | ||
) |
Set up a key derivation operation.
A key derivation algorithm takes some inputs and uses them to generate a byte stream in a deterministic way. This byte stream can be used to produce keys and other cryptographic material.
A key agreement and derivation algorithm uses a key agreement protocol to provide a shared secret which is used for the key derivation. See psa_key_derivation_key_agreement().
To derive a key:
If this function returns an error, the key derivation operation object is not changed.
If an error occurs at any step after a call to psa_key_derivation_setup(), the operation will need to be reset by a call to psa_key_derivation_abort().
Implementations must reject an attempt to derive a key of size 0.
operation | The key derivation operation object to set up. It must have been initialized but not set up yet. |
alg | The algorithm to compute. This must be one of the following:
|
alg
is neither a key derivation algorithm, nor a key agreement and derivation algorithm. alg
is not supported or is not a key derivation algorithm, or a key agreement and derivation algorithm. psa_status_t psa_key_derivation_verify_bytes | ( | psa_key_derivation_operation_t * | operation, |
const uint8_t * | expected_output, | ||
size_t | output_length | ||
) |
Compare output data from a key derivation operation to an expected value.
This function calculates output bytes from a key derivation algorithm and compares those bytes to an expected value. If the key derivation’s output is viewed as a stream of bytes, this function destructively reads output_length
bytes from the stream before comparing them with expected_output
. The operation’s capacity decreases by the number of bytes read.
This is functionally equivalent to the following code:
However, calling psa_key_derivation_verify_bytes() works even if the key’s policy does not allow output of the bytes.
If this function returns an error status other than PSA_ERROR_INSUFFICIENT_DATA or PSA_ERROR_INVALID_SIGNATURE, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
operation | The key derivation operation object to read from. |
expected_output | Buffer containing the expected derivation output. |
output_length | Length ot the expected output. This is also the number of bytes that will be read. |
output_length
bytes. In this case, the operation’s capacity is set to zero — subsequent calls to this function will not succeed, even with a smaller expected output length. psa_status_t psa_key_derivation_verify_key | ( | psa_key_derivation_operation_t * | operation, |
psa_key_id_t | expected | ||
) |
Compare output data from a key derivation operation to an expected value stored in a key.
This function calculates output bytes from a key derivation algorithm and compares those bytes to an expected value, provided as key of type PSA_KEY_TYPE_PASSWORD_HASH. If the key derivation’s output is viewed as a stream of bytes, this function destructively reads the number of bytes corresponding to the length of the expected key from the stream before comparing them with the key value. The operation’s capacity decreases by the number of bytes read.
This is functionally equivalent to exporting the expected key and calling psa_key_derivation_verify_bytes() on the result, except that it works when the key cannot be exported.
If this function returns an error status other than PSA_ERROR_INSUFFICIENT_DATA or PSA_ERROR_INVALID_SIGNATURE, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
operation | The key derivation operation object to read from. |
expected | A key of type PSA_KEY_TYPE_PASSWORD_HASH containing the expected output. The key must allow the usage PSA_KEY_USAGE_VERIFY_DERIVATION, and the permitted algorithm must match the operation’s algorithm. The value of this key is typically computed by a previous call to psa_key_derivation_output_key(). |
expected
is not a valid key identifier. expected
key. In this case, the operation’s capacity is set to zero — subsequent calls to this function will not succeed, even with a smaller expected key length. psa_status_t psa_mac_abort | ( | psa_mac_operation_t * | operation | ) |
Abort a MAC operation.
Aborting an operation frees all associated resources except for the operation object itself. Once aborted, the operation object can be reused for another operation by calling psa_mac_sign_setup() or psa_mac_verify_setup() again.
This function can be called any time after the operation object has been initialized by one of the methods described in psa_mac_operation_t.
In particular, calling psa_mac_abort() after the operation has been terminated by a call to psa_mac_abort(), psa_mac_sign_finish() or psa_mac_verify_finish() is safe and has no effect.
operation | Initialized MAC operation. |
psa_status_t psa_mac_compute | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | input, | ||
size_t | input_length, | ||
uint8_t * | mac, | ||
size_t | mac_size, | ||
size_t * | mac_length | ||
) |
Calculate the message authentication code (MAC) of a message.
memcmp()
is risky because the time taken by the comparison might leak information about the MAC value which could allow an attacker to guess a valid MAC and thereby bypass security controls.key | Identifier of the key to use for the operation. It must allow the usage PSA_KEY_USAGE_SIGN_MESSAGE. |
alg | The MAC algorithm to compute (PSA_ALG_XXX value such that PSA_ALG_IS_MAC(alg ) is true). |
input | Buffer containing the input message. |
input_length | Size of the input buffer in bytes. |
mac | Buffer where the MAC value is to be written. |
mac_size | Size of the mac buffer in bytes. This must be appropriate for the selected algorithm and key:
|
mac_length | On success, the number of bytes that make up the MAC value. |
(*mac_length) bytes of mac
contain the MAC value. key
is not a valid key identifier. alg
is not a MAC algorithm.key
is not compatible with alg
.input_length
is too large for alg
. alg
is not supported or is not a MAC algorithm.key
is not supported for use with alg
.input_length
is too large for the implementation. psa_status_t psa_mac_sign_finish | ( | psa_mac_operation_t * | operation, |
uint8_t * | mac, | ||
size_t | mac_size, | ||
size_t * | mac_length | ||
) |
Finish the calculation of the MAC of a message.
The application must call psa_mac_sign_setup() before calling this function. This function calculates the MAC of the message formed by concatenating the inputs passed to preceding calls to psa_mac_update().
When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_mac_abort().
memcmp()
is risky because the time taken by the comparison might leak information about the hashed data which could allow an attacker to guess a valid MAC and thereby bypass security controls.operation | Active MAC operation. |
mac | Buffer where the MAC value is to be written. |
mac_size | Size of the mac buffer in bytes. This must be appropriate for the selected algorithm and key:
|
mac_length | On success, the number of bytes that make up the MAC value. This is always PSA_MAC_LENGTH(key_type , key_bits , alg ) where key_type and key_bits are attributes of the key, and alg is the algorithm used to compute the MAC. |
(*mac_length) bytes of mac contain the MAC value. psa_status_t psa_mac_sign_setup | ( | psa_mac_operation_t * | operation, |
psa_key_id_t | key, | ||
psa_algorithm_t | alg | ||
) |
Set up a multi-part MAC calculation operation.
This function sets up the calculation of the message authentication code (MAC) of a byte string. To verify the MAC of a message against an expected value, use psa_mac_verify_setup() instead.
The sequence of operations to calculate a MAC is as follows:
If an error occurs at any step after a call to psa_mac_sign_setup(), the operation will need to be reset by a call to psa_mac_abort(). The application can call psa_mac_abort() at any time after the operation has been initialized.
After a successful call to psa_mac_sign_setup(), the application must eventually terminate the operation through one of the following methods:
operation | The operation object to set up. It must have been initialized as per the documentation for psa_mac_operation_t and not yet in use. |
key | Identifier of the key to use for the operation. It must remain valid until the operation terminates. It must allow the usage PSA_KEY_USAGE_SIGN_MESSAGE. |
alg | The MAC algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_MAC(alg ) is true. |
key
is not a valid key identifier. alg
is not a MAC algorithm.key
is not compatible with alg
. alg
is not supported or is not a MAC algorithm.key
is not supported for use with alg
. psa_status_t psa_mac_update | ( | psa_mac_operation_t * | operation, |
const uint8_t * | input, | ||
size_t | input_length | ||
) |
Add a message fragment to a multi-part MAC operation.
The application must call psa_mac_sign_setup() or psa_mac_verify_setup() before calling this function.
If this function returns an error status, the operation enters an error state and must be aborted by calling psa_mac_abort().
operation | Active MAC operation. |
input | Buffer containing the message fragment to add to the MAC calculation. |
input_length | Size of the input buffer in bytes. |
psa_status_t psa_mac_verify | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | input, | ||
size_t | input_length, | ||
const uint8_t * | mac, | ||
size_t | mac_length | ||
) |
Calculate the MAC of a message and compare it with a reference value.
key | Identifier of the key to use for the operation. It must allow the usage PSA_KEY_USAGE_VERIFY_MESSAGE. |
alg | The MAC algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_MAC(alg ) is true. |
input | Buffer containing the input message. |
input_length | Size of the input buffer in bytes. |
mac | Buffer containing the expected MAC value. |
mac_length | Size of the mac buffer in bytes. |
key
is not a valid key identifier. mac
. alg
is not a MAC algorithm.key
is not compatible with alg
.input_length
is too large for alg
. alg
is not supported or is not a MAC algorithm.key
is not supported for use with alg
.input_length
is too large for the implementation. psa_status_t psa_mac_verify_finish | ( | psa_mac_operation_t * | operation, |
const uint8_t * | mac, | ||
size_t | mac_length | ||
) |
Finish the calculation of the MAC of a message and compare it with an expected value.
The application must call psa_mac_verify_setup() before calling this function. This function calculates the MAC of the message formed by concatenating the inputs passed to preceding calls to psa_mac_update(). It then compares the calculated MAC with the expected MAC passed as a parameter to this function.
When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_mac_abort().
operation | Active MAC operation. |
mac | Buffer containing the expected MAC value. |
mac_length | Size of the mac buffer in bytes. |
psa_status_t psa_mac_verify_setup | ( | psa_mac_operation_t * | operation, |
psa_key_id_t | key, | ||
psa_algorithm_t | alg | ||
) |
Set up a multi-part MAC verification operation.
This function sets up the verification of the message authentication code (MAC) of a byte string against an expected value.
The sequence of operations to verify a MAC is as follows:
If an error occurs at any step after a call to psa_mac_verify_setup(), the operation will need to be reset by a call to psa_mac_abort(). The application can call psa_mac_abort() at any time after the operation has been initialized.
After a successful call to psa_mac_verify_setup(), the application must eventually terminate the operation through one of the following methods:
operation | The operation object to set up. It must have been initialized as per the documentation for psa_mac_operation_t and not yet in use. |
key | Identifier of the key to use for the operation. It must remain valid until the operation terminates. It must allow the usage PSA_KEY_USAGE_VERIFY_MESSAGE. |
alg | The MAC algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_MAC(alg ) is true. |
key
is not a valid key identifier. alg
is not a MAC algorithm.key
is not compatible with alg
. alg
is not supported or is not a MAC algorithm.key
is not supported for use with alg
. psa_status_t psa_purge_key | ( | psa_key_id_t | key | ) |
Remove non-essential copies of key material from memory.
For keys that have been created with the PSA_KEY_USAGE_CACHE usage flag, an implementation is permitted to make additional copies of the key material that are not in storage and not for the purpose of ongoing operations.
This function will remove these extra copies of the key material from memory.
This function is not required to remove key material from memory in any of the following situations:
key | Identifier of the key to purge. |
key
is not a valid key identifier. psa_status_t psa_raw_key_agreement | ( | psa_algorithm_t | alg, |
psa_key_id_t | private_key, | ||
const uint8_t * | peer_key, | ||
size_t | peer_key_length, | ||
uint8_t * | output, | ||
size_t | output_size, | ||
size_t * | output_length | ||
) |
Perform a key agreement and return the raw shared secret.
alg | The key agreement algorithm to compute: a value of type psa_algorithm_t such that PSA_ALG_IS_RAW_KEY_AGREEMENT(alg ) is true. |
private_key | Identifier of the private key to use. It must allow the usage PSA_KEY_USAGE_DERIVE. |
peer_key | Public key of the peer. The peer key must be in the same format that psa_import_key() accepts for the public key type corresponding to the type of private_key. That is, this function performs the equivalent of psa_import_key(..., peer_key , peer_key_length ), with key attributes indicating the public key type corresponding to the type of private_key . For example, for ECC keys, this means that peer_key is interpreted as a point on the curve that the private key is on. The standard formats for public keys are documented in the documentation of psa_export_public_key(). |
peer_key_length | Size of peer_key in bytes. |
output | Buffer where the raw shared secret is to be written. |
output_size | Size of the output buffer in bytes. This must be appropriate for the keys:
|
output_length | On success, the number of bytes that make up the returned output. |
private_key
is not a valid key identifier. private_key
does not have the PSA_KEY_USAGE_DERIVE flag, or it does not permit the requested algorithm. alg
is not a key agreement algorithm.private_key
is not compatible with alg
.peer_key
is not a valid public key corresponding to private_key
. alg
is not supported or is not a key agreement algorithm.private_key
is not supported for use with alg
.
|
inlinestatic |
Reset a key attribute object to a freshly initialized state.
The attribute object must be initialized as described in the documentation of the type psa_key_attributes_t before calling this function. Once the object has been initialized, this function can be called at any time.
This function frees any auxiliary resources that the object might contain.
attributes | The attribute object to reset. |
|
inlinestatic |
Declare the permitted algorithm policy for a key.
The permitted algorithm policy of a key encodes which algorithm or algorithms are permitted to be used with this key. This function overwrites any permitted algorithm policy previously set in attributes.
attributes | The attribute object to write to. |
alg | The permitted algorithm to write. |
|
inlinestatic |
Declare the size of a key.
This function overwrites any key size previously set in attributes.
attributes | The attribute object to write to. |
bits | The key size in bits. If this is 0, the key size in attributes becomes unspecified. Keys of size 0 are not supported. |
|
inlinestatic |
Declare a key as persistent and set its key identifier.
The application must choose a value for id between PSA_KEY_ID_USER_MIN and PSA_KEY_ID_USER_MAX. If the attribute object currently declares the key as volatile, which is the default lifetime of an attribute object, this function sets the lifetime attribute to PSA_KEY_LIFETIME_PERSISTENT.
This function does not access storage, it merely stores the given value in the attribute object. The persistent key will be written to storage when the attribute object is passed to a key creation function such as psa_import_key(), psa_generate_key(), psa_key_derivation_output_key() or psa_copy_key().
attributes | The attribute object to write to. |
id | The persistent identifier for the key. |
|
inlinestatic |
Set the location of a persistent key.
To make a key persistent, give it a persistent key identifier by using psa_set_key_id(). By default, a key that has a persistent identifier is stored in the default storage area identifier by PSA_KEY_LIFETIME_PERSISTENT. Call this function to choose a storage area, or to explicitly declare the key as volatile.
This function does not access storage, it merely stores the given value in the attribute object. The persistent key will be written to storage when the attribute object is passed to a key creation function such as psa_import_key(), psa_generate_key(), psa_key_derivation_output_key() or psa_copy_key().
attributes | The attribute object to write to. |
lifetime | The lifetime for the key. If this is PSA_KEY_LIFETIME_VOLATILE, the key will be volatile, and the key identifier attribute is reset to PSA_KEY_ID_NULL. |
|
inlinestatic |
Declare the type of a key.
This function overwrites any key type previously set in attributes
.
attributes | The attribute object to write to. |
type | The key type to write. If this is PSA_KEY_TYPE_NONE, the key type in attributes becomes unspecified. |
|
inlinestatic |
Declare usage flags for a key.
Usage flags are part of a key’s policy. They encode what kind of operations are permitted on the key. For more details, see Key policies.
This function overwrites any usage flags previously set in attributes.
attributes | The attribute object to write to. |
usage_flags | The usage flags to write. |
psa_status_t psa_sign_hash | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | hash, | ||
size_t | hash_length, | ||
uint8_t * | signature, | ||
size_t | signature_size, | ||
size_t * | signature_length | ||
) |
Sign an already-calculated hash with a private key.
With most signature mechanisms that follow the hash-and-sign paradigm, the hash input to this function is the hash of the message to sign. The hash algorithm is encoded in the signature algorithm.
Some hash-and-sign mechanisms apply a padding or encoding to the hash. In such cases, the encoded hash must be passed to this function. The current version of this specification defines one such signature algorithm: PSA_ALG_RSA_PKCS1V15_SIGN_RAW.
Alternatively, to hash and sign a message in a single call, use psa_sign_message().
key | Identifier of the key to use for the operation. It must be an asymmetric key pair. The key must allow the usage PSA_KEY_USAGE_SIGN_HASH. |
alg | An asymmetric signature algorithm that separates the hash and sign operations: a value of type psa_algorithm_t such that PSA_ALG_IS_SIGN_HASH(alg ) is true. |
hash | The input to sign. This is usually the hash of a message. See the detailed description of this function and the description of individual signature algorithms for a detailed description of acceptable inputs. |
hash_length | Size of the hash buffer in bytes. |
signature | Buffer where the signature is to be written. |
signature_size | Size of the signature buffer in bytes. This must be appropriate for the selected algorithm and key:
|
signature_length | On success, the number of bytes that make up the returned signature value. |
(*signature_length) bytes of signature
contain the signature value. key
is not a valid key identifier. alg
is not an asymmetric signature algorithm.key
is not an asymmetric key pair, that is compatible with alg
.hash_length
is not valid for the algorithm and key type. alg
is not supported or is not an asymmetric signature algorithm.key
is not supported for use with alg. psa_status_t psa_sign_message | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | input, | ||
size_t | input_length, | ||
uint8_t * | signature, | ||
size_t | signature_size, | ||
size_t * | signature_length | ||
) |
Sign a message with a private key.
For hash-and-sign algorithms, this includes the hashing step.
alg
) can be used to determine the hash algorithm to use.key | Identifier of the key to use for the operation. It must be an asymmetric key pair. The key must allow the usage PSA_KEY_USAGE_SIGN_MESSAGE. |
alg | An asymmetric signature algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_SIGN_MESSAGE(alg ) is true. |
input | The input message to sign. |
input_length | Size of the input buffer in bytes. |
signature | Buffer where the signature is to be written. |
signature_size | Size of the signature buffer in bytes. This must be appropriate for the selected algorithm and key:
|
signature_length | On success, the number of bytes that make up the returned signature value. |
(*signature_length) bytes of signature
contain the signature value. key
is not a valid key identifier. alg
is not an asymmetric signature algorithm.key
is not an asymmetric key pair, that is compatible with alg
.input_length
is too large for the algorithm and key type. alg
is not supported or is not an asymmetric signature algorithm.key
is not supported for use with alg
.input_length
is too large for the implementation. const char * psa_status_to_humanly_readable | ( | psa_status_t | status | ) |
Helper function to convert PSA status values humanly readable.
status | PSA status value |
psa_status_t psa_verify_hash | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | hash, | ||
size_t | hash_length, | ||
const uint8_t * | signature, | ||
size_t | signature_length | ||
) |
Verify the signature of a hash or short message using a public key.
With most signature mechanisms that follow the hash-and-sign paradigm, the hash input to this function is the hash of the message to sign. The hash algorithm is encoded in the signature algorithm.
Some hash-and-sign mechanisms apply a padding or encoding to the hash. In such cases, the encoded hash must be passed to this function. The current version of this specification defines one such signature algorithm: PSA_ALG_RSA_PKCS1V15_SIGN_RAW.
key | Identifier of the key to use for the operation. It must be a public key or an asymmetric key pair. The key must allow the usage PSA_KEY_USAGE_VERIFY_HASH. |
alg | An asymmetric signature algorithm that separates the hash and sign operations (PSA_ALG_XXX value such that PSA_ALG_IS_SIGN_HASH(alg ) is true), that is compatible with the type of key. |
hash | The input whose signature is to be verified. This is usually the hash of a message. See the detailed description of this function and the description of individual signature algorithms for a detailed description of acceptable inputs. |
hash_length | Size of the hash buffer in bytes. |
signature | Buffer containing the signature to verify. |
signature_length | Size of the signature buffer in bytes. |
key
is not a valid key identifier. signature
is not the result of signing hash with algorithm alg
using the private key corresponding to key
. alg
is not an asymmetric signature algorithm.key
is not a public key or an asymmetric key pair, that is compatible with alg
.hash_length
is not valid for the algorithm and key type. alg
is not supported or is not an asymmetric signature algorithm.key
is not supported for use with alg
. psa_status_t psa_verify_message | ( | psa_key_id_t | key, |
psa_algorithm_t | alg, | ||
const uint8_t * | input, | ||
size_t | input_length, | ||
const uint8_t * | signature, | ||
size_t | signature_length | ||
) |
Verify the signature of a message with a public key.
For hash-and-sign algorithms, this includes the hashing step.
alg
) can be used to determine the hash algorithm to use.key | Identifier of the key to use for the operation. It must be a public key or an asymmetric key pair. The key must allow the usage PSA_KEY_USAGE_VERIFY_MESSAGE. |
alg | An asymmetric signature algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_SIGN_MESSAGE(alg ) is true. |
input | The message whose signature is to be verified. |
input_length | Size of the input buffer in bytes. |
signature | Buffer containing the signature to verify. |
signature_length | Size of the signature buffer in bytes. |
key
is not a valid key identifier. signature
is not the result of signing the input message with algorithm alg
using the private key corresponding to key
. alg
is not an asymmetric signature algorithm.key
is not a public key or an asymmetric key pair, that is compatible with alg
.input_length
is too large for the algorithm and key type. alg
is not supported or is not an asymmetric signature algorithm.key
is not supported for use with alg
.input_length
is too large for the implementation.