TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ps_crypto_interface.c File Reference
#include "ps_crypto_interface.h"
#include <stdbool.h>
#include "tfm_crypto_defs.h"
#include "psa/crypto.h"
#include "tfm_memory_utils.h"
Include dependency graph for ps_crypto_interface.c:

Go to the source code of this file.

Macros

#define PS_CRYPTO_AEAD_ALG   PSA_ALG_GCM
 
#define PS_KEY_TYPE   PSA_KEY_TYPE_AES
 
#define PS_KEY_USAGE   (PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT)
 
#define PS_CRYPTO_ALG   PSA_ALG_AEAD_WITH_TAG_LENGTH(PS_CRYPTO_AEAD_ALG, PS_TAG_LEN_BYTES)
 

Typedefs

typedef char PS_ERROR_NOT_AEAD_ALG [(PSA_ALG_IS_AEAD(PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_GCM, 16)))?1:-1]
 

Functions

psa_status_t ps_crypto_init (void)
 Initializes the crypto engine. More...
 
psa_status_t ps_crypto_setkey (void)
 Sets the key to use for crypto operations for the current client. More...
 
psa_status_t ps_crypto_destroykey (void)
 Destroys the transient key used for crypto operations. More...
 
void ps_crypto_set_iv (const union ps_crypto_t *crypto)
 Provides current IV value to crypto layer. More...
 
void ps_crypto_get_iv (union ps_crypto_t *crypto)
 Gets a new IV value into the crypto union. More...
 
psa_status_t ps_crypto_encrypt_and_tag (union ps_crypto_t *crypto, const uint8_t *add, size_t add_len, const uint8_t *in, size_t in_len, uint8_t *out, size_t out_size, size_t *out_len)
 Encrypts and tags the given plaintext data. More...
 
psa_status_t ps_crypto_auth_and_decrypt (const union ps_crypto_t *crypto, const uint8_t *add, size_t add_len, uint8_t *in, size_t in_len, uint8_t *out, size_t out_size, size_t *out_len)
 Decrypts and authenticates the given encrypted data. More...
 
psa_status_t ps_crypto_generate_auth_tag (union ps_crypto_t *crypto, const uint8_t *add, uint32_t add_len)
 Generates authentication tag for given data. More...
 
psa_status_t ps_crypto_authenticate (const union ps_crypto_t *crypto, const uint8_t *add, uint32_t add_len)
 Authenticate given data against the tag. More...
 

Macro Definition Documentation

#define PS_CRYPTO_AEAD_ALG   PSA_ALG_GCM

Definition at line 17 of file ps_crypto_interface.c.

Definition at line 26 of file ps_crypto_interface.c.

#define PS_KEY_TYPE   PSA_KEY_TYPE_AES

Definition at line 21 of file ps_crypto_interface.c.

#define PS_KEY_USAGE   (PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT)

Definition at line 23 of file ps_crypto_interface.c.

Typedef Documentation

typedef char PS_ERROR_NOT_AEAD_ALG[(PSA_ALG_IS_AEAD(PSA_ALG_AEAD_WITH_TAG_LENGTH(PSA_ALG_GCM,16)))?1:-1]

Definition at line 36 of file ps_crypto_interface.c.

Function Documentation

psa_status_t ps_crypto_auth_and_decrypt ( const union ps_crypto_t crypto,
const uint8_t *  add,
size_t  add_len,
uint8_t *  in,
size_t  in_len,
uint8_t *  out,
size_t  out_size,
size_t *  out_len 
)

Decrypts and authenticates the given encrypted data.

Parameters
[in]cryptoPointer to the crypto union
[in]addPointer to the associated data
[in]add_lenLength of the associated data
[in]inPointer to the input data
[in]in_lenLength of the input data
[out]outPointer to the output buffer for decrypted data
[in]out_sizeSize of the output buffer
[out]out_lenOn success, the length of the output data
Returns
Returns values as described in psa_status_t

Definition at line 186 of file ps_crypto_interface.c.

Here is the call graph for this function:

psa_status_t ps_crypto_authenticate ( const union ps_crypto_t crypto,
const uint8_t *  add,
uint32_t  add_len 
)

Authenticate given data against the tag.

Parameters
[in]cryptoPointer to the crypto union
[in]addPointer to the data to authenticate
[in]add_lenLength of the data to authenticate
Returns
Returns values as described in psa_status_t

Definition at line 232 of file ps_crypto_interface.c.

psa_status_t ps_crypto_destroykey ( void  )

Destroys the transient key used for crypto operations.

Returns
Returns values as described in psa_status_t

Definition at line 99 of file ps_crypto_interface.c.

Here is the caller graph for this function:

psa_status_t ps_crypto_encrypt_and_tag ( union ps_crypto_t crypto,
const uint8_t *  add,
size_t  add_len,
const uint8_t *  in,
size_t  in_len,
uint8_t *  out,
size_t  out_size,
size_t *  out_len 
)

Encrypts and tags the given plaintext data.

Parameters
[in,out]cryptoPointer to the crypto union
[in]addPointer to the associated data
[in]add_lenLength of the associated data
[in]inPointer to the input data
[in]in_lenLength of the input data
[out]outPointer to the output buffer for encrypted data
[in]out_sizeSize of the output buffer
[out]out_lenOn success, the length of the output data
Returns
Returns values as described in psa_status_t

Definition at line 159 of file ps_crypto_interface.c.

Here is the call graph for this function:

psa_status_t ps_crypto_generate_auth_tag ( union ps_crypto_t crypto,
const uint8_t *  add,
uint32_t  add_len 
)

Generates authentication tag for given data.

Parameters
[in,out]cryptoPointer to the crypto union
[in]addPointer to the data to authenticate
[in]add_lenLength of the data to authenticate
Returns
Returns values as described in psa_status_t

Definition at line 213 of file ps_crypto_interface.c.

void ps_crypto_get_iv ( union ps_crypto_t crypto)

Gets a new IV value into the crypto union.

Parameters
[out]cryptoPointer to the crypto union

Definition at line 117 of file ps_crypto_interface.c.

Here is the call graph for this function:

psa_status_t ps_crypto_init ( void  )

Initializes the crypto engine.

Returns
Returns values as described in psa_status_t

Definition at line 42 of file ps_crypto_interface.c.

void ps_crypto_set_iv ( const union ps_crypto_t crypto)

Provides current IV value to crypto layer.

Parameters
[in]cryptoPointer to the crypto union

Definition at line 112 of file ps_crypto_interface.c.

Here is the call graph for this function:

Here is the caller graph for this function:

psa_status_t ps_crypto_setkey ( void  )

Sets the key to use for crypto operations for the current client.

Returns
Returns values as described in psa_status_t

Definition at line 50 of file ps_crypto_interface.c.

Here is the caller graph for this function: