Embedded SDK
Embedded SDK
|
#include "cx_cipher.h"
#include "os_math.h"
#include "os_utils.h"
#include <stddef.h>
#include <string.h>
Go to the source code of this file.
Macros | |
#define | CX_MAX_BLOCK_SIZE 16 |
Functions | |
void | add_one_and_zeros_padding (uint8_t *output, size_t out_len, size_t data_len) |
cx_err_t | cx_cipher_init (cx_cipher_context_t *ctx) |
Initialize a cipher context as NONE. More... | |
cx_err_t | cx_cipher_setup (cx_cipher_context_t *ctx, const cx_cipher_id_t type, uint32_t mode) |
Initialize and fill the context structure given the cipher info. More... | |
cx_err_t | cx_cipher_setkey (cx_cipher_context_t *ctx, const uint8_t *key, uint32_t key_bitlen, uint32_t operation) |
Set the key to use. More... | |
cx_err_t | cx_cipher_setiv (cx_cipher_context_t *ctx, const uint8_t *iv, size_t iv_len) |
Set the initialization vector. More... | |
cx_err_t | cx_cipher_set_padding (cx_cipher_context_t *ctx, uint32_t padding) |
Set the padding type. More... | |
cx_err_t | cx_cipher_update (cx_cipher_context_t *ctx, const uint8_t *input, size_t in_len, uint8_t *output, size_t *out_len) |
Encrypt or decrypt with the given context. More... | |
cx_err_t | cx_cipher_finish (cx_cipher_context_t *ctx, uint8_t *output, size_t *out_len) |
Finalize the operation. More... | |
cx_err_t | cx_cipher_mac (cx_cipher_context_t *ctx, uint8_t *output, size_t *out_len, size_t *finish_len) |
cx_err_t | cx_cipher_enc_dec (cx_cipher_context_t *ctx, const uint8_t *iv, size_t iv_len, const uint8_t *input, size_t in_len, uint8_t *output, size_t *out_len) |
All-in-one encryption or decryption. More... | |
void | cx_cipher_reset (cx_cipher_context_t *ctx) |
#define CX_MAX_BLOCK_SIZE 16 |
Definition at line 10 of file cx_cipher.c.
void add_one_and_zeros_padding | ( | uint8_t * | output, |
size_t | out_len, | ||
size_t | data_len | ||
) |
Definition at line 79 of file cx_cipher.c.
cx_err_t cx_cipher_enc_dec | ( | cx_cipher_context_t * | ctx, |
const uint8_t * | iv, | ||
size_t | iv_len, | ||
const uint8_t * | input, | ||
size_t | in_len, | ||
uint8_t * | output, | ||
size_t * | out_len | ||
) |
All-in-one encryption or decryption.
This function must be called after the cipher context is initialized with cx_cipher_init and set with cx_cipher_setup. The key must be set with cx_cipher_setkey, the padding method to use must be set with cx_cipher_set_padding.
[in] | ctx | Pointer to the context. |
[in] | iv | Initialization vector: a buffer of at least iv_len bytes. |
[in] | iv_len | Length of the initialization vector in bytes. |
[in] | input | Input data: a buffer of at least in_len bytes. |
[in] | in_len | Length of the input in bytes. |
[out] | output | Output data: a buffer of at least in_len + block_size bytes. |
[out] | out_len | Length of the output. |
Definition at line 492 of file cx_cipher.c.
cx_err_t cx_cipher_finish | ( | cx_cipher_context_t * | ctx, |
uint8_t * | output, | ||
size_t * | out_len | ||
) |
Finalize the operation.
This function must be called after the cipher context is initialized with cx_cipher_init and set with cx_cipher_setup. The key must be set with cx_cipher_setkey, the padding method to use must be set with cx_cipher_set_padding and the Initialization Vector must be set with cx_cipher_setiv. This function must be called after the last cx_cipher_update.
[in] | ctx | Pointer to the context. |
[out] | output | Output data: buffer of at least block_size bytes. |
[out] | out_len | Length of the data written to the output. |
Definition at line 411 of file cx_cipher.c.
cx_err_t cx_cipher_init | ( | cx_cipher_context_t * | ctx | ) |
Initialize a cipher context as NONE.
This function must be called first.
[in] | ctx | Pointer to the context. This must not be NULL. |
Definition at line 209 of file cx_cipher.c.
cx_err_t cx_cipher_mac | ( | cx_cipher_context_t * | ctx, |
uint8_t * | output, | ||
size_t * | out_len, | ||
size_t * | finish_len | ||
) |
Definition at line 471 of file cx_cipher.c.
void cx_cipher_reset | ( | cx_cipher_context_t * | ctx | ) |
Definition at line 516 of file cx_cipher.c.
cx_err_t cx_cipher_set_padding | ( | cx_cipher_context_t * | ctx, |
uint32_t | padding | ||
) |
Set the padding type.
This function must be called after the cipher context is initialized with cx_cipher_init.
[in] | ctx | Pointer to the context. |
[in] | padding | Type of padding:
|
Definition at line 301 of file cx_cipher.c.
cx_err_t cx_cipher_setiv | ( | cx_cipher_context_t * | ctx, |
const uint8_t * | iv, | ||
size_t | iv_len | ||
) |
Set the initialization vector.
This function must be called after the cipher context is initialized with cx_cipher_init.
[in] | ctx | Pointer to the context. |
[in] | iv | Initialization vector: a buffer of at least iv_len bytes. |
[in] | iv_len | Length of the initialization vector in bytes. |
Definition at line 276 of file cx_cipher.c.
cx_err_t cx_cipher_setkey | ( | cx_cipher_context_t * | ctx, |
const uint8_t * | key, | ||
uint32_t | key_bitlen, | ||
uint32_t | operation | ||
) |
Set the key to use.
This function must be called after the cipher context is initialized with cx_cipher_init.
[in] | ctx | Pointer to the context. |
[in] | key | Key to use: a buffer of at least key_bitlen bits. |
[in] | key_bitlen | Length of key in bits. |
[in] | operation | The operation that the key will be used for: encryption or decryption. |
Definition at line 253 of file cx_cipher.c.
cx_err_t cx_cipher_setup | ( | cx_cipher_context_t * | ctx, |
const cx_cipher_id_t | type, | ||
uint32_t | mode | ||
) |
Initialize and fill the context structure given the cipher info.
[in] | ctx | Pointer to the context. |
[in] | type | Cipher to use:
|
[in] | mode | Mode of operation:
|
Definition at line 218 of file cx_cipher.c.
cx_err_t cx_cipher_update | ( | cx_cipher_context_t * | ctx, |
const uint8_t * | input, | ||
size_t | in_len, | ||
uint8_t * | output, | ||
size_t * | out_len | ||
) |
Encrypt or decrypt with the given context.
This function must be called after the cipher context is initialized with cx_cipher_init and set with cx_cipher_setup. The key must be set with cx_cipher_setkey, the padding method to use must be set with cx_cipher_set_padding and the Initialization Vector must be set with cx_cipher_setiv. One can call this function multiple times depending on the length of the data that needed to be processed.
[in] | ctx | Pointer to the context. |
[in] | input | Input data: buffer of at least in_len bytes. |
[in] | in_len | Length of the input in bytes. |
[out] | output | Output data: a buffer of at least in_len + block_size bytes. |
[out] | out_len | Length of the data written to the output. |
Definition at line 324 of file cx_cipher.c.