AES Device Interface Functions More...
#include <stdbool.h>
#include <stdint.h>
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_base.h"
#include "sw/device/lib/dif/autogen/dif_aes_autogen.h"
Go to the source code of this file.
Data Structures | |
struct | dif_aes_key_share |
A typed representation of the AES key share. More... | |
struct | dif_aes_iv |
A typed representation of the AES Initialisation Vector (IV). More... | |
struct | dif_aes_data |
A typed representation of the AES data. More... | |
struct | dif_aes_transaction |
Parameters for an AES transaction. More... | |
Typedefs | |
typedef struct dif_aes_key_share | dif_aes_key_share_t |
A typed representation of the AES key share. More... | |
typedef struct dif_aes_iv | dif_aes_iv_t |
A typed representation of the AES Initialisation Vector (IV). | |
typedef struct dif_aes_data | dif_aes_data_t |
A typed representation of the AES data. | |
typedef enum dif_aes_operation | dif_aes_operation_t |
AES operation. | |
typedef enum dif_aes_mode | dif_aes_mode_t |
AES block cipher mode of operation. | |
typedef enum dif_aes_key_length | dif_aes_key_length_t |
AES key length in bits. | |
typedef enum dif_aes_manual_operation | dif_aes_manual_operation_t |
AES manual operation. | |
typedef enum dif_aes_key_provider | dif_aes_key_provider_t |
AES key sideloaded. More... | |
typedef enum dif_aes_mask_reseeding | dif_aes_mask_reseeding_t |
AES reseeding rate. More... | |
typedef struct dif_aes_transaction | dif_aes_transaction_t |
Parameters for an AES transaction. | |
typedef enum dif_aes_trigger | dif_aes_trigger_t |
AES Trigger flags. | |
typedef enum dif_aes_status | dif_aes_status_t |
AES Status flags. | |
AES Device Interface Functions
This API assumes transactional nature of work, where the peripheral is configured once per message (data consisting of 1..N 128-bit blocks), and then "de-initialised" when this message has been fully encrypted/decrypted.
The peripheral is configured through one of the cipher mode "start" functions: dif_aes_start_ecb
, dif_aes_start_cbc
, ... .
Then the encryption/decryption data is fed one 128-bit block at the time through dif_aes_load_data
function. The cipher mode operation details are described in the description of above mentioned "start" functions. When configured in "automatic" operation mode, every "load data" call, will trigger encryption/decryption. This is not true when in "manual" operation mode, where encryption/decryption is triggered by explicitly setting the aes.TRIGGER.START
flag through dif_aes_trigger
call.
When an entire requested message has been processed the internal state of AES registers must be securely cleared, by calling dif_aes_end
.
Please see the following documentation for further information: https://docs.opentitan.org/hw/ip/aes/doc/ https://csrc.nist.gov/csrc/media/publications/fips/197/final/documents/fips-197.pdf https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf
Definition in file dif_aes.h.
struct dif_aes_key_share |
A typed representation of the AES key share.
Two part masked AES key, where XOR operation of these two parts results in the actual key.
struct dif_aes_iv |
struct dif_aes_data |
struct dif_aes_transaction |
Data Fields | ||
---|---|---|
bool | ctrl_aux_lock |
If true reseed_on_key_change and force_masks will be locked until the device is reset. |
bool | force_masks |
If true, the internal pseudo-random number generator used for masking is not advancing leading to constant masks. NOTE: This should only be used for development purpose (SCA), and is expected to be removed for the production version. |
dif_aes_key_length_t | key_len | |
dif_aes_key_provider_t | key_provider | |
dif_aes_manual_operation_t | manual_operation | |
dif_aes_mask_reseeding_t | mask_reseeding | |
dif_aes_mode_t | mode | |
dif_aes_operation_t | operation | |
bool | reseed_on_key_change | If true the internal pseudo-random number generators used for clearing and masking will be reseeded every time the key changes. |
typedef enum dif_aes_key_provider dif_aes_key_provider_t |
AES key sideloaded.
Controls whether the AES uses the key provided by the key manager or software.
typedef struct dif_aes_key_share dif_aes_key_share_t |
A typed representation of the AES key share.
Two part masked AES key, where XOR operation of these two parts results in the actual key.
typedef enum dif_aes_mask_reseeding dif_aes_mask_reseeding_t |
AES reseeding rate.
Controls the reseeding rate of the internal pseudo-random number generator (PRNG) used for masking.
enum dif_aes_key_length |
enum dif_aes_key_provider |
AES manual operation.
AES reseeding rate.
Controls the reseeding rate of the internal pseudo-random number generator (PRNG) used for masking.
enum dif_aes_mode |
AES block cipher mode of operation.
enum dif_aes_operation |
enum dif_aes_status |
AES Status flags.
enum dif_aes_trigger |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_end | ( | const dif_aes_t * | aes | ) |
Ends an AES transaction.
This function must be called at the end of every dif_aes_<mode>_start
operation.
The peripheral must be in IDLE state for this operation to take effect, and will return kDifAesEndBusy
if this condition is not met.
aes | AES state data. |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_get_status | ( | const dif_aes_t * | aes, |
dif_aes_status_t | flag, | ||
bool * | set | ||
) |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_load_data | ( | const dif_aes_t * | aes, |
const dif_aes_data_t | data | ||
) |
Loads AES Input Data.
This function will trigger encryption/decryption when configured in the automatic operation mode.
The peripheral must be able to accept the input (INPUT_READY set), and will return kDifAesLoadDataBusy
if this condition is not met.
aes | AES state data. |
data | AES Input Data. |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_process_data | ( | const dif_aes_t * | aes, |
const dif_aes_data_t * | plain_text, | ||
dif_aes_data_t * | cipher_text, | ||
size_t | block_amount | ||
) |
Process a stream of data containing the plain text and output a stream of data with the cipher text.
This function should be used when performance is desired. It requires the automatic operation mode activated.
The peripheral must be able to accept the input (INPUT_READY set), and will return kDifAesLoadDataBusy
if this condition is not met.
aes | AES handle. |
plain_text | AES Input Data. |
cipher_text | AES Output Data. |
block_amount | The amount of blocks to be encrypted. |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_read_iv | ( | const dif_aes_t * | aes, |
dif_aes_iv_t * | iv | ||
) |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_read_output | ( | const dif_aes_t * | aes, |
dif_aes_data_t * | data | ||
) |
Reads AES Output Data.
The peripheral must have finished previous encryption/decryption operation, and have valid data in the output registers (OUTPUT_VALID set), and will return kDifAesReadOutputInvalid
if this condition is not met.
aes | AES state data. |
data | AES Output Data. |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_reset | ( | const dif_aes_t * | aes | ) |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_start | ( | const dif_aes_t * | aes, |
const dif_aes_transaction_t * | transaction, | ||
const dif_aes_key_share_t * | key, | ||
const dif_aes_iv_t * | iv | ||
) |
Begins an AES transaction in the mode selected by the transaction->mode
.
Each call to this function should be sequenced with a call to dif_aes_end()
.
The peripheral must be in IDLE state for this operation to take effect, and will return kDifAesBusy
if this condition is not met.
aes | AES state data. |
transaction | Configuration data. |
key | Encryption/decryption key when kDifAesKeySoftwareProvided , can be NULL otherwise. |
iv | Initialization vector when the mode isn't kDifAesModeEcb , can be NULL otherwise. |
OT_WARN_UNUSED_RESULT dif_result_t dif_aes_trigger | ( | const dif_aes_t * | aes, |
dif_aes_trigger_t | trigger | ||
) |
Triggers one of dif_aes_trigger_t
operations.
All the triggers are applicable to both (automatic and manual) modes, with the exception of kDifAesTriggerStart
, which is ignored in automatic mode.
aes | AES state data. |
trigger | AES trigger. |