AES utilities. More...

Modules

Types
AES data types.
 

Functions

void gos_aes128_buffer_encrypt_init (gos_aes128_crypt_context_t *aes_context, const uint8_t *key)
 Initialize AES-128 buffer encryption context. More...
 
void gos_aes128_buffer_decrypt_init (gos_aes128_crypt_context_t *aes_context, uint8_t *iv, const uint8_t *key)
 Initialize AES-128 buffer decryption context. More...
 
void gos_aes128_buffer_encrypt (gos_aes128_crypt_context_t *aes_context, uint8_t *buffer, uint16_t length)
 Encrypt buffer using AES-128 CBC. More...
 
void gos_aes128_buffer_decrypt (gos_aes128_crypt_context_t *aes_context, uint8_t *buffer, uint16_t length)
 Decrypt AES-128 CBC encoded buffer. More...
 
int gos_aes_setkey_enc (gos_aes_context_t *ctx, const unsigned char *key, uint32_t keysize_bits)
 AES key schedule (encryption) More...
 
int gos_aes_setkey_dec (gos_aes_context_t *ctx, const unsigned char *key, uint32_t keysize_bits)
 AES key schedule (decryption) More...
 
int gos_aes_encrypt_ecb (gos_aes_context_t *ctx, const unsigned char input[16], unsigned char output[16])
 AES-ECB block encryption. More...
 
int gos_aes_decrypt_ecb (gos_aes_context_t *ctx, const unsigned char input[16], unsigned char output[16])
 AES-ECB block decryption. More...
 
int gos_aes_encrypt_cbc (gos_aes_context_t *ctx, unsigned char iv[16], const gos_buffer_t *input, gos_buffer_t *output)
 AES-CBC buffer encryption. More...
 
int gos_aes_decrypt_cbc (gos_aes_context_t *ctx, unsigned char iv[16], const gos_buffer_t *input, gos_buffer_t *output)
 AES-CBC buffer encryption. More...
 

Detailed Description

AES utilities.

Function Documentation

◆ gos_aes128_buffer_decrypt()

void gos_aes128_buffer_decrypt ( gos_aes128_crypt_context_t aes_context,
uint8_t *  buffer,
uint16_t  length 
)

Decrypt AES-128 CBC encoded buffer.

This is a helper API to perform AES-128 CBC decryption on the supplied buffer.

Note
gos_aes128_buffer_decrypt_init() must be called first to initialize the context.

This can be called multiple times using the same aes_context as the block counter is automatically incremented. If calling multiple times, the provided buffer length must be a multiple of 16 bytes.

For the last call of this API, the block length need NOT be a multiple of 16 bytes.

Note
The provided buffer is decrypted in-place
This is a helper function only. The mBedTLS APIs may be directly used. Refer to Encrypt with AES
Parameters
aes_contextgos_aes128_crypt_context_t pre-initialized context
bufferBuffer to decrypt in-place
lengthLength of buffer

◆ gos_aes128_buffer_decrypt_init()

void gos_aes128_buffer_decrypt_init ( gos_aes128_crypt_context_t aes_context,
uint8_t *  iv,
const uint8_t *  key 
)

Initialize AES-128 buffer decryption context.

This is a helper API to enable AES-128 buffer decrpytion. This must be called before using gos_aes128_buffer_decrypt()

This effectively calls:

mbedtls_aes_init(&aes_context->aes);
aes_context->iv_decrypt = iv
gos_aes_setkey_enc(&aes_context->aes, key, AES128_BLOCK_BITS)
Parameters
aes_contextgos_aes128_crypt_context_t context to initialize
ivIV of data to decrypt
keyDecryption key

◆ gos_aes128_buffer_encrypt()

void gos_aes128_buffer_encrypt ( gos_aes128_crypt_context_t aes_context,
uint8_t *  buffer,
uint16_t  length 
)

Encrypt buffer using AES-128 CBC.

This is a helper API to perform AES-128 CBC encryption on the supplied buffer.

Note
gos_aes128_buffer_encrypt_init() must be called first to initialize the context.

This can be called multiple times using the same aes_context as the block counter is automatically incremented. If calling multiple times, the provided buffer length must be a multiple of 16 bytes.

For the last call of this API, the block length need NOT be a multiple of 16 bytes.

Note
The provided buffer is encrypted in-place
This is a helper function only. The mBedTLS APIs may be directly used. Refer to Encrypt with AES
Parameters
aes_contextgos_aes128_crypt_context_t pre-initialized context
bufferBuffer to encrypt in-place
lengthLength of buffer

◆ gos_aes128_buffer_encrypt_init()

void gos_aes128_buffer_encrypt_init ( gos_aes128_crypt_context_t aes_context,
const uint8_t *  key 
)

Initialize AES-128 buffer encryption context.

This is a helper API to enable AES-128 buffer encrpytion. This must be called before using gos_aes128_buffer_encrypt()

This effectively calls:

gos_get_random_buffer(aes_context->iv_encrypt, AES128_BLOCK_SIZE)
mbedtls_aes_init(&aes_context->aes);
gos_aes_setkey_enc(&aes_context->aes, key, AES128_BLOCK_BITS)
Parameters
aes_contextgos_aes128_crypt_context_t context to initialize
keyEncryption key

◆ gos_aes_decrypt_cbc()

int gos_aes_decrypt_cbc ( gos_aes_context_t ctx,
unsigned char  iv[16],
const gos_buffer_t input,
gos_buffer_t output 
)

AES-CBC buffer encryption.

This effectively calls:

output->size = input->size;
aes_crypt_cbc(aes_context, AES_DECRYPT, input->size, iv, input->data, output->data)
Parameters
ctxAES context
ivinitialization vector (updated after use)
inputbuffer holding the input data
outputbuffer holding the output data

◆ gos_aes_decrypt_ecb()

int gos_aes_decrypt_ecb ( gos_aes_context_t ctx,
const unsigned char  input[16],
unsigned char  output[16] 
)

AES-ECB block decryption.

This effectively calls:

mbedtls_aes_crypt_ecb(aes_context, AES_DECRYPT, input, output)
Parameters
ctxAES context
input16-byte input block
output16-byte output block

◆ gos_aes_encrypt_cbc()

int gos_aes_encrypt_cbc ( gos_aes_context_t ctx,
unsigned char  iv[16],
const gos_buffer_t input,
gos_buffer_t output 
)

AES-CBC buffer encryption.

This effectively calls:

output->size = input->size;
aes_crypt_cbc(aes_context, AES_ENCRYPT, input->size, iv, input->data, output->data)
Parameters
ctxAES context
ivinitialization vector (updated after use)
inputbuffer holding the input data
outputbuffer holding the output data
Examples:
file/file_encrypt/crypto_utils.c, and file/log_file_encrypted/crypto_utils.c.

◆ gos_aes_encrypt_ecb()

int gos_aes_encrypt_ecb ( gos_aes_context_t ctx,
const unsigned char  input[16],
unsigned char  output[16] 
)

AES-ECB block encryption.

This effectively calls:

mbedtls_aes_crypt_ecb(aes_context, AES_ENCRYPT, input, output)
Parameters
ctxAES context
input16-byte input block
output16-byte output block
Examples:
file/file_encrypt/crypto_utils.c, file/log_file_encrypted/crypto_utils.c, and security/aes_ctr/main.c.

◆ gos_aes_setkey_dec()

int gos_aes_setkey_dec ( gos_aes_context_t ctx,
const unsigned char *  key,
uint32_t  keysize_bits 
)

AES key schedule (decryption)

This effectively calls:

mbedtls_aes_init(aes_context)
mbedtls_aes_setkey_dec(aes_context, key, keysize_bits);
Parameters
ctxAES context to be initialized
keydecryption key
keysize_bitsmust be 128, 192 or 256

◆ gos_aes_setkey_enc()

int gos_aes_setkey_enc ( gos_aes_context_t ctx,
const unsigned char *  key,
uint32_t  keysize_bits 
)

AES key schedule (encryption)

This effectively calls:

mbedtls_aes_init(aes_context)
mbedtls_aes_setkey_enc(aes_context, key, keysize_bits);
Parameters
ctxAES context to be initialized
keyencryption key
keysize_bitsmust be 128, 192 or 256
Examples:
file/file_encrypt/crypto_utils.c, file/file_encrypt/decrypt.c, file/file_encrypt/encrypt.c, file/log_file_encrypted/crypto_utils.c, file/log_file_encrypted/main.c, and security/aes_ctr/main.c.