Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
AESECB.h File Reference

Detailed Description

AESECB driver header.

============================================================================

Warning
This is a beta API. It may change in future releases.

Overview

The Electronic Code Book (ECB) mode of operation is a generic encryption block cipher mode. It can be used with any block cipher. AESECB encrypts or decrypts one or multiple blocks of plaintext or ciphertext using the Advanced Encryption Standard (AES) block cipher. Each input block is individually encrypted or decrypted. This means that blocks of ciphertext can be decrypted individually and out of order. Encrypting the same plaintext using the same key yields identical ciphertext. This raises several security issues. For this reason, it is not recommended that ECB be used unless interfacing with unupdatable legacy systems or where a standard specifies its use. Better alternatives would be an authenticated encryption with associated data (AEAD) mode such as CCM or GCM.

The AES key is a shared secret between the two parties and has a length of 128, 192, or 256 bits.

Usage

Before starting an ECB operation

Before starting an ECB operation, the application must do the following:

Starting an ECB operation

The AESECB_oneStepEncrypt and AESECB_oneStepDecrypt functions do an ECB operation in a single call. They will always be the most highly optimized routines with the least overhead and the fastest runtime. Since ECB plaintext blocks are simply encrypted with the block cipher block by block, there is no difference in the ciphertext between encrypting two blocks in one go or encypting each block individually.

After the ECB operation completes

After the ECB operation completes, the application should either start another operation or close the driver by calling AESECB_close()

AESECB Driver Configuration

In order to use the AESECB APIs, the application is required to provide device-specific AESECB configuration in the Board.c file. The AESECB driver interface defines a configuration data structure:

typedef struct AESECB_Config_ {
void *object;
void const *hwAttrs;

The application must declare an array of AESECB_Config elements, named AESECB_config[]. Each element of AESECB_config[] must be populated with pointers to a device specific AESECB driver implementation's driver object and hardware attributes. The hardware attributes define properties such as the AESECB peripheral's base address. Each element in AESECB_config[] corresponds to an AESECB instance and none of the elements should have NULL pointers. There is no correlation between the index and the peripheral designation (such as AESECB0 or AESECB1). For example, it is possible to use AESECB_config[0] for AESECB1. Multiple drivers and driver instances may all access the same underlying hardware. This is transparent to the application. Mutual exclusion is performed automatically by the drivers as necessary.

Because the AESECB configuration is very device dependent, you will need to check the doxygen for the device specific AESECB implementation. There you will find a description of the AESECB hardware attributes. Please also refer to the Board.c file of any of your examples to see the AESECB configuration.

AESECB Parameters

The AESECB_Params structure is passed to the AESECB_open() call. If NULL is passed for the parameters, AESECB_open() uses default parameters. An AESECB_Params structure is initialized with default values by passing it to AESECB_Params_init().

Examples

### Encyption of multiple plaintext blocks in blocking mode #

#include <ti/drivers/types/cryptoKey/CryptoKey_Plaintext.h>
...
AESECB_Handle handle;
CryptoKey cryptoKey;
int_fast16_t encryptionResult;
uint8_t plaintext[] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51};
uint8_t ciphertext[sizof(plaintext)];
uint8_t keyingMaterial[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}
handle = AESECB_open(0, NULL);
if (handle == NULL) {
// handle error
}
CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
AESECB_Operation operation;
AESECB_Operation_init(&operation);
operation.key = &cryptoKey;
operation.input = plaintext;
operation.output = ciphertext;
operation.inputLength = sizeof(plaintext);
encryptionResult = AESECB_oneStepEncrypt(handle, &operation);
if (encryptionResult != AESECB_STATUS_SUCCESS) {
// handle error
}
// The resultant ciphertext should be:
// 0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
// 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
// 0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
// 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf
AESECB_close(handle);

Single call ECB decryption in callback mode

...
uint8_t ciphertext[] = {0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8};
uint8_t keyingMaterial[32] = {0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4};
uint8_t plaintext[sizeof(ciphertext)];
// The plaintext should be the following after the decryption operation:
// 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
// 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
void ecbCallback(AESECB_Handle handle,
int_fast16_t returnValue,
AESECB_Operation *operation,
AESECB_OperationType operationType) {
if (returnValue != AESECB_STATUS_SUCCESS) {
// handle error
}
}
AESECB_Operation operation;
void ecbStartFunction(void) {
AESECB_Handle handle;
AESECB_Params params;
CryptoKey cryptoKey;
int_fast16_t decryptionResult;
params.callbackFxn = ecbCallback;
handle = AESECB_open(0, &params);
if (handle == NULL) {
// handle error
}
CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
AESECB_Operation_init(&operation);
operation.key = &cryptoKey;
operation.input = plaintext;
operation.output = ciphertext;
operation.inputLength = sizeof(plaintext);
decryptionResult = AESECB_oneStepDecrypt(handle, &operation);
if (decryptionResult != AESECB_STATUS_SUCCESS) {
// handle error
}
// do other things while ECB operation completes in the background
}
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti/drivers/cryptoutils/cryptokey/CryptoKey.h>

Go to the source code of this file.

Data Structures

struct  AESECB_Operation_
 Struct containing the parameters required for encrypting/decrypting and a message. More...
 
struct  AESECB_Config_
 AESECB Global configuration. More...
 
struct  AESECB_Params_
 ECB Parameters. More...
 

Macros

#define AESECB_CMD_RESERVED   (32)
 
#define AESECB_STATUS_RESERVED   (-32)
 
#define AESECB_STATUS_SUCCESS   (0)
 Successful status code. More...
 
#define AESECB_STATUS_ERROR   (-1)
 Generic error status code. More...
 
#define AESECB_STATUS_UNDEFINEDCMD   (-2)
 An error status code returned by AESECB_control() for undefined command codes. More...
 
#define AESECB_STATUS_RESOURCE_UNAVAILABLE   (-3)
 An error status code returned if the hardware or software resource is currently unavailable. More...
 

Typedefs

typedef struct AESECB_Config_AESECB_Handle
 A handle that is returned from an AESECB_open() call. More...
 
typedef enum AESECB_ReturnBehavior_ AESECB_ReturnBehavior
 The way in which ECB function calls return after performing an encryption + authentication or decryption + verification operation. More...
 
typedef enum AESECB_Mode_ AESECB_Mode
 Enum for the direction of the ECB operation. More...
 
typedef struct AESECB_Operation_ AESECB_Operation
 Struct containing the parameters required for encrypting/decrypting and a message. More...
 
typedef enum AESECB_OperationType_ AESECB_OperationType
 Enum for the operation types supported by the driver. More...
 
typedef struct AESECB_Config_ AESECB_Config
 AESECB Global configuration. More...
 
typedef void(* AESECB_CallbackFxn) (AESECB_Handle handle, int_fast16_t returnValue, AESECB_Operation *operation, AESECB_OperationType operationType)
 The definition of a callback function used by the AESECB driver when used in AESECB_RETURN_BEHAVIOR_CALLBACK. More...
 
typedef struct AESECB_Params_ AESECB_Params
 ECB Parameters. More...
 

Enumerations

enum  AESECB_ReturnBehavior_ { AESECB_RETURN_BEHAVIOR_CALLBACK = 1, AESECB_RETURN_BEHAVIOR_BLOCKING = 2, AESECB_RETURN_BEHAVIOR_POLLING = 4 }
 The way in which ECB function calls return after performing an encryption + authentication or decryption + verification operation. More...
 
enum  AESECB_Mode_ { AESECB_MODE_ENCRYPT = 1, AESECB_MODE_DECRYPT = 2 }
 Enum for the direction of the ECB operation. More...
 
enum  AESECB_OperationType_ { AESECB_OPERATION_TYPE_ENCRYPT = 1, AESECB_OPERATION_TYPE_DECRYPT = 2 }
 Enum for the operation types supported by the driver. More...
 

Functions

void AESECB_init (void)
 This function initializes the ECB module. More...
 
void AESECB_Params_init (AESECB_Params *params)
 Function to initialize the AESECB_Params struct to its defaults. More...
 
AESECB_Handle AESECB_open (uint_least8_t index, AESECB_Params *params)
 This function opens a given ECB peripheral. More...
 
void AESECB_close (AESECB_Handle handle)
 Function to close an ECB peripheral specified by the ECB handle. More...
 
int_fast16_t AESECB_control (AESECB_Handle handle, uint32_t cmd, void *args)
 Function performs implementation specific features on a given AESECB_Handle. More...
 
void AESECB_Operation_init (AESECB_Operation *operationStruct)
 Function to initialize an AESECB_Operation struct to its defaults. More...
 
int_fast16_t AESECB_oneStepEncrypt (AESECB_Handle handle, AESECB_Operation *operation)
 Function to perform an AESECB encryption operation in one call. More...
 
int_fast16_t AESECB_oneStepDecrypt (AESECB_Handle handle, AESECB_Operation *operation)
 Function to perform an AESECB decryption in one call. More...
 

Variables

const AESECB_Params AESECB_defaultParams
 Default AESECB_Params structure. More...
 

Typedef Documentation

§ AESECB_Handle

typedef struct AESECB_Config_* AESECB_Handle

A handle that is returned from an AESECB_open() call.

§ AESECB_ReturnBehavior

The way in which ECB function calls return after performing an encryption + authentication or decryption + verification operation.

Not all ECB operations exhibit the specified return behavor. Functions that do not require significant computation and cannot offload that computation to a background thread behave like regular functions. Which functions exhibit the specfied return behavior is not implementation dependent. Specifically, a software-backed implementation run on the same CPU as the application will emulate the return behavior while not actually offloading the computation to the background thread.

AESECB functions exhibiting the specified return behavior have restrictions on the context from which they may be called.

Task Hwi Swi
AESECB_RETURN_BEHAVIOR_CALLBACK X X X
AESECB_RETURN_BEHAVIOR_BLOCKING X
AESECB_RETURN_BEHAVIOR_POLLING X X X

§ AESECB_Mode

typedef enum AESECB_Mode_ AESECB_Mode

Enum for the direction of the ECB operation.

§ AESECB_Operation

Struct containing the parameters required for encrypting/decrypting and a message.

§ AESECB_OperationType

Enum for the operation types supported by the driver.

§ AESECB_Config

typedef struct AESECB_Config_ AESECB_Config

AESECB Global configuration.

The AESECB_Config structure contains a set of pointers used to characterize the AESECB driver implementation.

This structure needs to be defined before calling AESECB_init() and it must not be changed thereafter.

See also
AESECB_init()

§ AESECB_CallbackFxn

typedef void(* AESECB_CallbackFxn) (AESECB_Handle handle, int_fast16_t returnValue, AESECB_Operation *operation, AESECB_OperationType operationType)

The definition of a callback function used by the AESECB driver when used in AESECB_RETURN_BEHAVIOR_CALLBACK.

Parameters
handleHandle of the client that started the ECB operation.
returnValueThe result of the CCM operation. May contain an error code. Informs the application of why the callback function was called.
operationA pointer to an operation struct.
operationTypeThis parameter determines which operation the callback refers to.

§ AESECB_Params

typedef struct AESECB_Params_ AESECB_Params

ECB Parameters.

ECB Parameters are used to with the AESECB_open() call. Default values for these parameters are set using AESECB_Params_init().

See also
AESECB_Params_init()

Enumeration Type Documentation

§ AESECB_ReturnBehavior_

The way in which ECB function calls return after performing an encryption + authentication or decryption + verification operation.

Not all ECB operations exhibit the specified return behavor. Functions that do not require significant computation and cannot offload that computation to a background thread behave like regular functions. Which functions exhibit the specfied return behavior is not implementation dependent. Specifically, a software-backed implementation run on the same CPU as the application will emulate the return behavior while not actually offloading the computation to the background thread.

AESECB functions exhibiting the specified return behavior have restrictions on the context from which they may be called.

Task Hwi Swi
AESECB_RETURN_BEHAVIOR_CALLBACK X X X
AESECB_RETURN_BEHAVIOR_BLOCKING X
AESECB_RETURN_BEHAVIOR_POLLING X X X
Enumerator
AESECB_RETURN_BEHAVIOR_CALLBACK 

The function call will return immediately while the ECB operation goes on in the background. The registered callback function is called after the operation completes. The context the callback function is called (task, HWI, SWI) is implementation-dependent.

AESECB_RETURN_BEHAVIOR_BLOCKING 

The function call will block while ECB operation goes on in the background. ECB operation results are available after the function returns.

AESECB_RETURN_BEHAVIOR_POLLING 

The function call will continuously poll a flag while ECB operation goes on in the background. ECB operation results are available after the function returns.

§ AESECB_Mode_

Enum for the direction of the ECB operation.

Enumerator
AESECB_MODE_ENCRYPT 
AESECB_MODE_DECRYPT 

§ AESECB_OperationType_

Enum for the operation types supported by the driver.

Enumerator
AESECB_OPERATION_TYPE_ENCRYPT 
AESECB_OPERATION_TYPE_DECRYPT 

Function Documentation

§ AESECB_init()

void AESECB_init ( void  )

This function initializes the ECB module.

Precondition
The AESECB_config structure must exist and be persistent before this function can be called. This function must also be called before any other ECB driver APIs. This function call does not modify any peripheral registers.

§ AESECB_Params_init()

void AESECB_Params_init ( AESECB_Params params)

Function to initialize the AESECB_Params struct to its defaults.

Parameters
paramsAn pointer to AESECB_Params structure for initialization

Defaults values are: returnBehavior = AESECB_RETURN_BEHAVIOR_BLOCKING callbackFxn = NULL timeout = SemaphoreP_WAIT_FOREVER custom = NULL

§ AESECB_open()

AESECB_Handle AESECB_open ( uint_least8_t  index,
AESECB_Params params 
)

This function opens a given ECB peripheral.

Precondition
ECB controller has been initialized using AESECB_init()
Parameters
indexLogical peripheral number for the ECB indexed into the AESECB_config table
paramsPointer to an parameter block, if NULL it will use default values.
Returns
An AESECB_Handle on success or a NULL on an error or if it has been opened already.
See also
AESECB_init()
AESECB_close()

§ AESECB_close()

void AESECB_close ( AESECB_Handle  handle)

Function to close an ECB peripheral specified by the ECB handle.

Precondition
AESECB_open() has to be called first.
Parameters
handleAn ECB handle returned from AESECB_open()
See also
AESECB_open()

§ AESECB_control()

int_fast16_t AESECB_control ( AESECB_Handle  handle,
uint32_t  cmd,
void *  args 
)

Function performs implementation specific features on a given AESECB_Handle.

Commands for AESECB_control can originate from AESECB.h or from implementation specific AESECB*.h (AESECBCC26XX.h, AESECBMSP432.h, etc.. ) files. While commands from AESECB.h are API portable across driver implementations, not all implementations may support all these commands. Conversely, commands from driver implementation specific AESECB*.h files add unique driver capabilities but are not API portable across all AESECB driver implementations.

Commands supported by AESECB.h follow an AESECB_CMD_<cmd> naming convention.
Commands supported by AESECB*.h follow an AESECB*_CMD_<cmd> naming convention.
Each control command defines arg differently. The types of arg are documented with each command.

See AESECB_control command codes for command codes.

See AESECB_control return status codes for status codes.

Precondition
AESECB_open() has to be called first.
Parameters
handleAn AESECB handle returned from AESECB_open()
cmdAESECB.h or AESECB*.h commands.
argsAn optional R/W (read/write) command argument accompanied with cmd
Returns
Implementation specific return codes. Negative values indicate unsuccessful operations.
See also
AESECB_open()

§ AESECB_Operation_init()

void AESECB_Operation_init ( AESECB_Operation operationStruct)

Function to initialize an AESECB_Operation struct to its defaults.

Parameters
operationStructAn pointer to AESECB_Operation structure for initialization

Defaults values are all zeros.

§ AESECB_oneStepEncrypt()

int_fast16_t AESECB_oneStepEncrypt ( AESECB_Handle  handle,
AESECB_Operation operation 
)

Function to perform an AESECB encryption operation in one call.

Note
None of the buffers provided as arguments may be altered by the application during an ongoing operation. Doing so can yield corrupted ciphertext or incorrect authentication.
Precondition
AESECB_open() and AESECB_Operation_init() have to be called first.
Parameters
[in]handleAn ECB handle returned from AESECB_open()
[in]operationA pointer to a struct containing the parameters required to perform the operation.
Returns
A status code
See also
AESECB_oneStepDecrypt()

§ AESECB_oneStepDecrypt()

int_fast16_t AESECB_oneStepDecrypt ( AESECB_Handle  handle,
AESECB_Operation operation 
)

Function to perform an AESECB decryption in one call.

Note
None of the buffers provided as arguments may be altered by the application during an ongoing operation. Doing so can yield corrupted plaintext or incorrectly failed verification.
Precondition
AESECB_open() and AESECB_Operation_init() have to be called first.
Parameters
[in]handleAn ECB handle returned from AESECB_open()
[in]operationA pointer to a struct containing the parameters required to perform the operation.
Returns
A status code
See also
AESECB_oneStepEncrypt()

Variable Documentation

§ AESECB_defaultParams

const AESECB_Params AESECB_defaultParams

Default AESECB_Params structure.

See also
AESECB_Params_init()
Copyright 2018, Texas Instruments Incorporated