![]() |
m2mb API docs
30.00.009.1
m2mb API sets documentation
|
AES CBC & ECB algorithm implementation. https://tools.ietf.org/pdf/rfc3602.pdf http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf. More...

Macros | |
| #define | M2MB_CRYPTO_AES_ECB_BLOCK_SIZE 16 |
| #define | M2MB_CRYPTO_AES_IV_SIZE 16 |
Enumerations | |
| enum | M2MB_CRYPTO_AES_MODE_E { M2MB_CRYPTO_AES_MODE_ENCRYPT, M2MB_CRYPTO_AES_MODE_DECRYPT } |
| AES operation mode (encrypt decrypt) | |
Functions | |
| M2MB_RESULT_E | m2mb_crypto_aes_init (M2MB_CRYPTO_AES_CONTEXT *ctx) |
| Allocates an M2MB_CRYPTO_AES_CONTEXT structure. More... | |
| M2MB_RESULT_E | m2mb_crypto_aes_deinit (M2MB_CRYPTO_AES_CONTEXT ctx) |
| Free an M2MB_CRYPTO_AES_CONTEXT structure. More... | |
| M2MB_RESULT_E | m2mb_crypto_aes_generate_key (M2MB_CRYPTO_AES_CONTEXT ctx, UINT32 keybits) |
| Generates an AES encryption key for a given context. More... | |
| M2MB_RESULT_E | m2mb_crypto_aes_keyblob_export (M2MB_CRYPTO_AES_CONTEXT ctx, UINT8 *keyblob, UINT32 *keyblob_length) |
| Exports the AES symmetric key from the given context. More... | |
| M2MB_RESULT_E | m2mb_crypto_aes_keyblob_import (M2MB_CRYPTO_AES_CONTEXT ctx, const UINT8 *keyblob, UINT32 keyblob_length) |
| Import a symmetric key, previously generated on the same device, into a given context. More... | |
| M2MB_RESULT_E | m2mb_crypto_aes_externalkey_import (M2MB_CRYPTO_AES_CONTEXT ctx, const UINT8 *key, UINT32 keylength) |
| Imports a symmetric key into the given context. This is a plaintext key that may have been generated externally. More... | |
| M2MB_RESULT_E | m2mb_crypto_aes_ecb_encdec (M2MB_CRYPTO_AES_CONTEXT ctx, M2MB_CRYPTO_AES_MODE_E mode, const UINT8 in[M2MB_CRYPTO_AES_ECB_BLOCK_SIZE], UINT8 out[M2MB_CRYPTO_AES_ECB_BLOCK_SIZE]) |
| Encrypts/decrypts a single 16 bytes block onto the output buffer using the AES ECB algorithm. More... | |
| M2MB_RESULT_E | m2mb_crypto_aes_cbc_encdec (M2MB_CRYPTO_AES_CONTEXT ctx, M2MB_CRYPTO_AES_MODE_E mode, const UINT8 *in, UINT8 *out, SIZE_T inlen, UINT8 ivec[M2MB_CRYPTO_AES_IV_SIZE]) |
| Encrypts/decrypts a given buffer with a given length using the AES CBC. The length must be a multiple of the block size (16 bytes). More... | |
AES CBC & ECB algorithm implementation. https://tools.ietf.org/pdf/rfc3602.pdf http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf.
| #define M2MB_CRYPTO_AES_ECB_BLOCK_SIZE 16 |
AES ecb block size
| #define M2MB_CRYPTO_AES_IV_SIZE 16 |
AES ecb initialization vector size
| M2MB_RESULT_E m2mb_crypto_aes_cbc_encdec | ( | M2MB_CRYPTO_AES_CONTEXT | ctx, |
| M2MB_CRYPTO_AES_MODE_E | mode, | ||
| const UINT8 * | in, | ||
| UINT8 * | out, | ||
| SIZE_T | inlen, | ||
| UINT8 | ivec[M2MB_CRYPTO_AES_IV_SIZE] | ||
| ) |
Encrypts/decrypts a given buffer with a given length using the AES CBC. The length must be a multiple of the block size (16 bytes).
This function will encrypt/decrypt (depending on the mode parameter) <inlen> bytes from the <in> buffer and store the output into the <out> buffer. The ivec will be updated as part of this function call to allow consecuritve calls to encrypt a stream of data. If it is required to encrypt several independant buffers (which are not related to each other), the ivec should be restored by the caller (i.e. storing a local copy of the ivec).
| [in] | ctx | Pointer to a context structure previously initialized by m2mb_crypto_aes_init() |
| [in] | mode | The requested operation mode (encrypt/decrypt) |
| [in] | in | The input buffer to encrypt/decrypt |
| [out] | out | The output buffer to store the result encryption/decryption values, must have 16 bytes allocated space |
| [in] | inlen | The length of the input data (<in>), must be multiple of block size (16 bytes) |
| [in] | ivec | Initialization vector. The ivec is updated after each use to allow working in "streaming" mode |
| M2MB_RESULT_E m2mb_crypto_aes_deinit | ( | M2MB_CRYPTO_AES_CONTEXT | ctx | ) |
Free an M2MB_CRYPTO_AES_CONTEXT structure.
This function free a previously allocated AES context.
| [in] | ctx | Pointer to a context structure to be free by this function. |
| M2MB_RESULT_E m2mb_crypto_aes_ecb_encdec | ( | M2MB_CRYPTO_AES_CONTEXT | ctx, |
| M2MB_CRYPTO_AES_MODE_E | mode, | ||
| const UINT8 | in[M2MB_CRYPTO_AES_ECB_BLOCK_SIZE], | ||
| UINT8 | out[M2MB_CRYPTO_AES_ECB_BLOCK_SIZE] | ||
| ) |
Encrypts/decrypts a single 16 bytes block onto the output buffer using the AES ECB algorithm.
This function will encrypt/decrypt (depending on the <mode> parameter) a given 16 bytes length input buffer and will store the result into the output 16 bytes buffer.
| [in] | ctx | Pointer to a context structure previously initialized by m2mb_crypto_aes_init() |
| [in] | mode | The requested operation mode (encrypt/decrypt) |
| [in] | in | The input buffer to encrypt/decrypt, 16 bytes length |
| [out] | out | The output buffer to store the result encryption/decryption values, must have 16 bytes allocated space |
| M2MB_RESULT_E m2mb_crypto_aes_externalkey_import | ( | M2MB_CRYPTO_AES_CONTEXT | ctx, |
| const UINT8 * | key, | ||
| UINT32 | keylength | ||
| ) |
Imports a symmetric key into the given context. This is a plaintext key that may have been generated externally.
This function sets up a key with a given size to a context to be later used by any AES encryption function. Assumption made is that this is a plaintext key and this API is to serve a key that was generated outside of the device. AES is a symmetric encryption, i.e. same key is used for encryption and decryption.
| [in] | ctx | Pointer to a context structure previously initialized by m2mb_crypto_aes_init(). |
| [in] | key | Pointer to a key to setup. The key is in the size of keybits bits. This key is a plaintext key created externally. |
| [in] | keylength | The number of bytes in the given key, must be 16, 26, 32 (128, 192, 256 bits key). |
| M2MB_RESULT_E m2mb_crypto_aes_generate_key | ( | M2MB_CRYPTO_AES_CONTEXT | ctx, |
| UINT32 | keybits | ||
| ) |
Generates an AES encryption key for a given context.
This function generates a symmetric AES key with a given size and stores it into the context to be later used by any AES encryption function. AES is a symmetric encryption, i.e. same key is used for encryption and decryption.
| [in] | ctx | Pointer to a context structure previously initialized by m2mb_crypto_aes_init() |
| [in] | keybits | The number of bits in the given key, must be 128, 192 or 256 |
| M2MB_RESULT_E m2mb_crypto_aes_init | ( | M2MB_CRYPTO_AES_CONTEXT * | ctx | ) |
Allocates an M2MB_CRYPTO_AES_CONTEXT structure.
This function allocates an AES context to be later used by any AES ciphering function.
| [in] | ctx | Pointer to a context structure to be allocated by this function. Any consecutive call to AES function must use the context. |
| M2MB_RESULT_E m2mb_crypto_aes_keyblob_export | ( | M2MB_CRYPTO_AES_CONTEXT | ctx, |
| UINT8 * | keyblob, | ||
| UINT32 * | keyblob_length | ||
| ) |
Exports the AES symmetric key from the given context.
This function exports the AES symmetric key from the given context. The key information will be exported from the given context (assuming context has keys associated, either imported or via m2mb_crypto_aes_generate_key()). The key blob is encrypted with a device specific key and can only be used on the same HW originating it.
| [in] | ctx | Pointer to a context structure previously allocated by m2mb_crypto_rsa_init. |
| [out] | keyblob | The buffer that will hold the result keyblob representing the exported AES symmetric key. If keyblob ptr is NULL, this function will return the number of bytes required for the keyblob via the keyblob_length pointer. The key blob is encrypted with a device specific key and can only be used on the same HW originating it. |
| [out] | keyblob_length | The length of the AES key blob |
Example
| M2MB_RESULT_E m2mb_crypto_aes_keyblob_import | ( | M2MB_CRYPTO_AES_CONTEXT | ctx, |
| const UINT8 * | keyblob, | ||
| UINT32 | keyblob_length | ||
| ) |
Import a symmetric key, previously generated on the same device, into a given context.
This function keyblob into a context to be later used by any AES encryption function. Assumption made is that this is not a plaintext key but a ciphered key that was previously generated via m2mb_crypto_aes_generate_key() and was exported via m2mb_crypto_aes_key_export(). Another option might be that the key was generated via the ECDH key derivation (via m2mb_crypto_ecdh_shared_key_derive()). AES is a symmetric encryption, i.e. same key is used for encryption and decryption.
| [in] | ctx | Pointer to a context structure previously initialized by m2mb_crypto_aes_init(). |
| [in] | keyblob | Pointer to a keyblob to setup. The key blob is encrypted with a device specific key and can only be used on the same HW originating it. |
| [in] | keyblob_length | The length of the keyblob buffer. |