m2mb API docs  25.30.004.0
m2mb API sets documentation

DES & 3DES CBC & ECB algorithm implementation. More...

Collaboration diagram for M2MB_DES:

Macros

#define M2MB_CRYPTO_DES_KEY_SIZE   8
 
#define M2MB_CRYPTO_3DES_KEY2_SIZE   16
 
#define M2MB_CRYPTO_3DES_KEY3_SIZE   24
 
#define M2MB_CRYPTO_DES_BLOCK_BYTE_LEN   8
 
#define M2MB_CRYPTO_DES_IV_BYTE_LEN   8
 

Enumerations

enum  M2MB_CRYPTO_DES_ALG_TYPE_E { M2MB_CRYPTO_ALG_DES, M2MB_CRYPTO_ALG_3DES }
 
enum  M2MB_CRYPTO_DES_MODE_E { M2MB_CRYPTO_DES_MODE_ENCRYPT, M2MB_CRYPTO_DES_MODE_DECRYPT }
 

Functions

M2MB_RESULT_E m2mb_crypto_des_init (M2MB_CRYPTO_DES_CONTEXT *ctx, M2MB_CRYPTO_DES_ALG_TYPE_E des_alg)
 Allocates an M2MB_CRYPTO_DES_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_des_deinit (M2MB_CRYPTO_DES_CONTEXT ctx)
 Free an M2MB_CRYPTO_DES_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_des_generate_key (M2MB_CRYPTO_DES_CONTEXT ctx, UINT32 keybits)
 Generates a DES encryption key for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_des_externalkey_import (M2MB_CRYPTO_DES_CONTEXT ctx, const UINT8 key[M2MB_CRYPTO_DES_KEY_SIZE])
 Sets up a DES encryption key (64 bits = 56 effective bits key + parity) for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_3des_2externalkey_import (M2MB_CRYPTO_DES_CONTEXT ctx, const UINT8 key[M2MB_CRYPTO_3DES_KEY2_SIZE])
 Sets up a 3DES encryption key (128 bits = 112 effective bits key + parity) for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_3des_3externalkey_import (M2MB_CRYPTO_DES_CONTEXT ctx, const UINT8 key[M2MB_CRYPTO_3DES_KEY3_SIZE])
 Sets up a 3DES encryption key (192 bits = 168 effective bits key + parity) for a given context. More...
 
M2MB_RESULT_E m2mb_crypto_des_keyblob_import (M2MB_CRYPTO_DES_CONTEXT ctx, const UINT8 *keyblob, UINT32 keyblob_length)
 Imports a DES/3DES symmetric key into the context. More...
 
M2MB_RESULT_E m2mb_crypto_des_keyblob_export (M2MB_CRYPTO_DES_CONTEXT ctx, UINT8 *keyblob, UINT32 *keyblob_length)
 Exports a DES key blob from the given context. The blob is encrypted with a device specific key and can only be used on the same HW originating it. More...
 
M2MB_RESULT_E m2mb_crypto_des_ecb_encdec (M2MB_CRYPTO_DES_CONTEXT ctx, M2MB_CRYPTO_DES_MODE_E mode, const UINT8 in[M2MB_CRYPTO_DES_BLOCK_BYTE_LEN], UINT8 out[M2MB_CRYPTO_DES_BLOCK_BYTE_LEN])
 Encrypts/decrypts a single 8 bytes block onto the output buffer using the DES ECB algorithm. More...
 
M2MB_RESULT_E m2mb_crypto_des_cbc_encdec (M2MB_CRYPTO_DES_CONTEXT ctx, M2MB_CRYPTO_DES_MODE_E mode, const UINT8 *in, UINT8 *out, SIZE_T inlen, UINT8 ivec[M2MB_CRYPTO_DES_IV_BYTE_LEN])
 Encrypts/decrypts a given buffer with a given length using the DES CBC. The length must be a multiple of the block size (8 bytes). More...
 

Detailed Description

DES & 3DES CBC & ECB algorithm implementation.

Macro Definition Documentation

◆ M2MB_CRYPTO_3DES_KEY2_SIZE

#define M2MB_CRYPTO_3DES_KEY2_SIZE   16

3DES 112 bit key + parity, i.e. 128 bits

◆ M2MB_CRYPTO_3DES_KEY3_SIZE

#define M2MB_CRYPTO_3DES_KEY3_SIZE   24

3DES 168 bit key + parity, i.e. 192 bits

◆ M2MB_CRYPTO_DES_BLOCK_BYTE_LEN

#define M2MB_CRYPTO_DES_BLOCK_BYTE_LEN   8

DES block bytes length

◆ M2MB_CRYPTO_DES_IV_BYTE_LEN

#define M2MB_CRYPTO_DES_IV_BYTE_LEN   8

DES initialization vector bytes length

◆ M2MB_CRYPTO_DES_KEY_SIZE

#define M2MB_CRYPTO_DES_KEY_SIZE   8

DES 56 bit key + parity, i.e. 64 bits

Enumeration Type Documentation

◆ M2MB_CRYPTO_DES_ALG_TYPE_E

Cipher algorithm to be used by the DES context

◆ M2MB_CRYPTO_DES_MODE_E

DES operation mode (encrypt/decrypt)

Function Documentation

◆ m2mb_crypto_3des_2externalkey_import()

M2MB_RESULT_E m2mb_crypto_3des_2externalkey_import ( M2MB_CRYPTO_DES_CONTEXT  ctx,
const UINT8  key[M2MB_CRYPTO_3DES_KEY2_SIZE] 
)

Sets up a 3DES encryption key (128 bits = 112 effective bits key + parity) for a given context.

This function sets up a key with a given size to a context to be later used by the 3DES encryption functions. This key may have come from the outside and is provided as plaintext.

Parameters
[in]ctxPointer to a context structure previously allocated by m2mb_crypto_des_init.
[in]keyThe encryption key to setup. This key may have come from the outside and is provided as plaintext.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
m2mb_crypto_des_init() must be called before using this function.

◆ m2mb_crypto_3des_3externalkey_import()

M2MB_RESULT_E m2mb_crypto_3des_3externalkey_import ( M2MB_CRYPTO_DES_CONTEXT  ctx,
const UINT8  key[M2MB_CRYPTO_3DES_KEY3_SIZE] 
)

Sets up a 3DES encryption key (192 bits = 168 effective bits key + parity) for a given context.

This function sets up a key with a given size to a context to be later used by the 3DES encryption functions. This key may have come from the outside and is provided as plaintext.

Parameters
[in]ctxPointer to a context structure previously allocated by m2mb_crypto_des_init.
[in]keyThe encryption key to setup. The key is in plaintext.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
m2mb_crypto_des_init() must be called before using this function.

◆ m2mb_crypto_des_cbc_encdec()

M2MB_RESULT_E m2mb_crypto_des_cbc_encdec ( M2MB_CRYPTO_DES_CONTEXT  ctx,
M2MB_CRYPTO_DES_MODE_E  mode,
const UINT8 *  in,
UINT8 *  out,
SIZE_T  inlen,
UINT8  ivec[M2MB_CRYPTO_DES_IV_BYTE_LEN] 
)

Encrypts/decrypts a given buffer with a given length using the DES CBC. The length must be a multiple of the block size (8 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).

Parameters
[in]ctxPointer to a context structure previously initialized by m2mb_crypto_des_init.
[in]modeThe requested operation mode (encrypt/decrypt)
[in]inThe input buffer to encrypt/decrypt.
[out]outThe output buffer to store the result encryption/decryption values, must have 8 bytes allocated space.
[in]inlenThe length of the input data (<in>), must be multiple of block size (8 bytes).
[in]ivecInitialization vector. The ivec is updated after each use to allow working in "streaming" mode.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
m2mb_crypto_des_init() must be called before using this function.

◆ m2mb_crypto_des_deinit()

M2MB_RESULT_E m2mb_crypto_des_deinit ( M2MB_CRYPTO_DES_CONTEXT  ctx)

Free an M2MB_CRYPTO_DES_CONTEXT structure.

This function free a previously allocated DES context.

Parameters
[in]ctxPointer to a context structure to be free by this function.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_des_ecb_encdec()

M2MB_RESULT_E m2mb_crypto_des_ecb_encdec ( M2MB_CRYPTO_DES_CONTEXT  ctx,
M2MB_CRYPTO_DES_MODE_E  mode,
const UINT8  in[M2MB_CRYPTO_DES_BLOCK_BYTE_LEN],
UINT8  out[M2MB_CRYPTO_DES_BLOCK_BYTE_LEN] 
)

Encrypts/decrypts a single 8 bytes block onto the output buffer using the DES ECB algorithm.

This function will encrypt/decrypt (depending on the <mode> parameter) a given 8 bytes length input buffer and will store the result into the output 16 bytes buffer.

Parameters
[in]ctxPointer to a context structure previously allocated by m2mb_crypto_des_init.
[in]modeThe requested operation mode (encrypt/decrypt)
[in]inThe input buffer to encrypt/decrypt, 8 bytes length.
[out]outThe output buffer to store the result encryption/decryption values.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
m2mb_crypto_des_init() must be called before using this function.

◆ m2mb_crypto_des_externalkey_import()

M2MB_RESULT_E m2mb_crypto_des_externalkey_import ( M2MB_CRYPTO_DES_CONTEXT  ctx,
const UINT8  key[M2MB_CRYPTO_DES_KEY_SIZE] 
)

Sets up a DES encryption key (64 bits = 56 effective bits key + parity) for a given context.

This function sets up a key, 64 bits length, to a context to be later used by the DES encryption functions. This key may have come from the outside and is provided as plaintext.

Parameters
[in]ctxPointer to a context structure previously allocated by m2mb_crypto_des_init.
[in]keyThe encryption key to setup. This key may have come from the outside and is provided as plaintext.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
The context must be set for DES algorithm using m2mb_crypto_des_init()

◆ m2mb_crypto_des_generate_key()

M2MB_RESULT_E m2mb_crypto_des_generate_key ( M2MB_CRYPTO_DES_CONTEXT  ctx,
UINT32  keybits 
)

Generates a DES encryption key for a given context.

This function generates a symmetric DES key with a given size and stores it into the context to be later used by any DES encryption function. DES is a symmetric encryption, i.e. same key is used for encryption and decryption.

Parameters
[in]ctxPointer to a context structure previously initialized by m2mb_crypto_des_init.
[in]keybitsThe key-bits size to generate, must be 64, 128 or 192 (length is including parity)
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
m2mb_crypto_des_init() must be called before using this function.

◆ m2mb_crypto_des_init()

M2MB_RESULT_E m2mb_crypto_des_init ( M2MB_CRYPTO_DES_CONTEXT ctx,
M2MB_CRYPTO_DES_ALG_TYPE_E  des_alg 
)

Allocates an M2MB_CRYPTO_DES_CONTEXT structure.

This function allocates a DES context to be later used by any DES ciphering function.

Parameters
[in]ctxPointer to a context structure to be allocated by this function. Any consecutive call to DES function must use the context
[in]des_algThe DES algorithm selected for the context.
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note

◆ m2mb_crypto_des_keyblob_export()

M2MB_RESULT_E m2mb_crypto_des_keyblob_export ( M2MB_CRYPTO_DES_CONTEXT  ctx,
UINT8 *  keyblob,
UINT32 *  keyblob_length 
)

Exports a DES key blob from the given context. The blob is encrypted with a device specific key and can only be used on the same HW originating it.

This function exports a DES key blob for the given context. Assumption made is that the context already have keys, i.e. keys were created using the m2mb_crypto_des_generate_key()

Parameters
[in]ctxPointer to a context structure previously allocated by m2mb_crypto_des_init.
[out]keyblobThe buffer that will hold the result keyblob representing the exported DES key. If keyblob ptr is NULL, this function will return the number of bytes required for the keyblob via the keyblob_length pointer.
[out]keyblob_lengthThe length of the DES key blob
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
m2mb_crypto_des_init() & m2mb_crypto_des_generate_key() must be called before using this function.

◆ m2mb_crypto_des_keyblob_import()

M2MB_RESULT_E m2mb_crypto_des_keyblob_import ( M2MB_CRYPTO_DES_CONTEXT  ctx,
const UINT8 *  keyblob,
UINT32  keyblob_length 
)

Imports a DES/3DES symmetric key into the context.

This function imports a given keyblob (which was previously created by m2mb_crypto_des_generate_key() and was exported by m2mb_crypto_des_keyblob_export()) to the provided context. This basically allows using of an old keys with an existing context. The blob is encrypted with a device specific key and can only be used on the same HW originating it.

Parameters
[in]ctxPointer to a context structure previously allocated by m2mb_crypto_des_init.
[in]keyblobThe keyblob previously exported using m2mb_crypto_des_keyblob_export() that will be imported into the given context. These keys can then be used for DES operations like encrypt & decrypt.
[in]keyblob_lengthThe length of the DES/3DES key blob
Returns
M2MB_RESULT_SUCCESS on success
see M2MB_RESULT_E for different values in case of fail
Note
m2mb_crypto_des_init() must be called before using this function.