lcx_des.h | Developers

lcx_des.h

Back to the files list

DES (Data Encryption Standard). More...

Functions

cx_err_t cx_des_init_key_no_throw (const uint8_t *rawkey, size_t key_len, cx_des_key_t *key)
 Initializes a DES key. More...
static int cx_des_init_key (const unsigned char *rawkey, unsigned int key_len, cx_des_key_t *key)
 Initializes a DES key. More...
cx_err_t cx_des_iv_no_throw (const cx_des_key_t *key, uint32_t mode, const uint8_t *iv, size_t iv_len, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
 Encrypts, decrypts, signs or verifies data with DES algorithm. More...
static int cx_des_iv (const cx_des_key_t *key, int mode, unsigned char *iv, unsigned int iv_len, const unsigned char *in, unsigned int in_len, unsigned char *out, unsigned int out_len)
 Encrypts, decrypts, signs or verifies data with DES algorithm. More...
cx_err_t cx_des_no_throw (const cx_des_key_t *key, uint32_t mode, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
 Encrypts, decrypts, signs or verifies data with DES algorithm. More...
static int cx_des (const cx_des_key_t *key, int mode, const unsigned char *in, unsigned int in_len, unsigned char *out, unsigned int out_len)
 Encrypts, decrypts, signs or verifies data with DES algorithm. More...
void cx_des_enc_block (const cx_des_key_t *key, const uint8_t *inblock, uint8_t *outblock)
 Encrypts a 8-byte block using DES/3-DES algorithm. More...
void cx_des_dec_block (const cx_des_key_t *key, const uint8_t *inblock, uint8_t *outblock)
 Decrypts a 8-byte block using DES/3-DES algorithm. More...

Detailed Description

DES (Data Encryption Standard).

DES is an encryption algorithm designed to encipher and decipher blocks of 64 bits under control of a 56-bit key. However, the key is represented with 64 bits.

Triple DES variant supports either a 128-bit (two 64-bit keys) or 192-bit key (three 64-bit keys).

Function Documentation

cx_des()

static int cx_des ( const cx_des_key_t key,
int  mode,
const unsigned char *  in,
unsigned int  in_len,
unsigned char *  out,
unsigned int  out_len 
)

Encrypts, decrypts, signs or verifies data with DES algorithm.

This function throws an exception if the computation fails.

Warning
It is recommended to use cx_des_no_throw rather than this function.
Parameters
[in]keyPointer to the key initialized with cx_des_init_key_no_throw.
[in]modeCrypto mode flags. Supported flags:
  • CX_LAST
  • CX_ENCRYPT
  • CX_DECRYPT
  • CX_SIGN
  • CX_VERIFY
  • CX_PAD_NONE
  • CX_PAD_ISO9797M1
  • CX_PAD_ISO9797M2
  • CX_CHAIN_ECB
  • CX_CHAIN_CBC
  • CX_CHAIN_CTR
[in]inInput data.
[in]in_lenLength of the input data. If CX_LAST is set, padding is automatically done according to the mode. Otherwise, in_len shall be a multiple of DES_BLOCK_SIZE.
[out]outOutput data according to the mode:
  • encrypted/decrypted output data
  • generated signature
  • signature to be verified
[in]out_lenLength of the output data.
Returns
Length of the output.
Exceptions
CX_INVALID_PARAMETER
INVALID_PARAMETER

cx_des_dec_block()

void cx_des_dec_block ( const cx_des_key_t key,
const uint8_t *  inblock,
uint8_t *  outblock 
)

Decrypts a 8-byte block using DES/3-DES algorithm.

Parameters
[in]keyPointer to the DES key.
[in]inblockCiphertext block to decrypt.
[out]outblockPlaintext block.
Returns
Error code:
  • CX_OK
  • CX_INVALID_PARAMETER
  • INVALID_PARAMETER

cx_des_enc_block()

void cx_des_enc_block ( const cx_des_key_t key,
const uint8_t *  inblock,
uint8_t *  outblock 
)

Encrypts a 8-byte block using DES/3-DES algorithm.

Parameters
[in]keyPointer to the DES key.
[in]inblockPlaintext block to encrypt.
[out]outblockCiphertext block.
Returns
Error code:
  • CX_OK
  • CX_INVALID_PARAMETER
  • INVALID_PARAMETER

cx_des_init_key()

static int cx_des_init_key ( const unsigned char *  rawkey,
unsigned int  key_len,
cx_des_key_t key 
)

Initializes a DES key.

Once initialized, the key can be stored in non-volatile memory and directly used for any DES processing. This function throws an exception if the initialization fails.

Warning
It is recommended to use cx_des_init_key_no_throw rather than this function.
Parameters
[in]rawkeyPointer to the supplied key.
[in]key_lenLength of the key: 8, 16 or 24 octets.
[out]keyPointer to the key structure. This must not be NULL.
Returns
Length of the key.
Exceptions
CX_INVALID_PARAMETER

cx_des_init_key_no_throw()

cx_err_t cx_des_init_key_no_throw ( const uint8_t *  rawkey,
size_t  key_len,
cx_des_key_t key 
)

Initializes a DES key.

Once initialized, the key can be stored in non-volatile memory and directly used for any DES processing.

Parameters
[in]rawkeyPointer to the supplied key.
[in]key_lenLength of the key: 8, 16 or 24 octets.
[out]keyPointer to the key structure. This must not be NULL.
Returns
Error code:
  • CX_OK on success
  • CX_INVALID_PARAMETER

cx_des_iv()

static int cx_des_iv ( const cx_des_key_t key,
int  mode,
unsigned char *  iv,
unsigned int  iv_len,
const unsigned char *  in,
unsigned int  in_len,
unsigned char *  out,
unsigned int  out_len 
)

Encrypts, decrypts, signs or verifies data with DES algorithm.

This function throws an exception if the computation doesn't succeed.

Warning
It is recommended to use cx_des_iv_no_throw rather than this function.
Parameters
[in]keyPointer to the key initialized with cx_des_init_key_no_throw.
[in]ivInitialization vector.
[in]iv_lenLength of the initialization vector.
[in]modeCrypto mode flags. Supported flags:
  • CX_LAST
  • CX_ENCRYPT
  • CX_DECRYPT
  • CX_SIGN
  • CX_VERIFY
  • CX_PAD_NONE
  • CX_PAD_ISO9797M1
  • CX_PAD_ISO9797M2
  • CX_CHAIN_ECB
  • CX_CHAIN_CBC
  • CX_CHAIN_CTR
[in]inInput data.
[in]in_lenLength of the input data. If CX_LAST is set, padding is automatically done according to the mode. Otherwise, in_len shall be a multiple of DES_BLOCK_SIZE.
[out]outOutput data according to the mode:
  • encrypted/decrypted output data
  • generated signature
  • signature to be verified
[in]out_lenLength of the output data.
Returns
Lenght of the output.
Exceptions
CX_INVALID_PARAMETER
INVALID_PARAMETER

cx_des_iv_no_throw()

cx_err_t cx_des_iv_no_throw ( const cx_des_key_t key,
uint32_t  mode,
const uint8_t *  iv,
size_t  iv_len,
const uint8_t *  in,
size_t  in_len,
uint8_t *  out,
size_t *  out_len 
)

Encrypts, decrypts, signs or verifies data with DES algorithm.

Parameters
[in]keyPointer to the key initialized with cx_des_init_key_no_throw.
[in]ivInitialization vector.
[in]iv_lenLength of the initialization vector.
[in]modeCrypto mode flags. Supported flags:
  • CX_LAST
  • CX_ENCRYPT
  • CX_DECRYPT
  • CX_SIGN
  • CX_VERIFY
  • CX_PAD_NONE
  • CX_PAD_ISO9797M1
  • CX_PAD_ISO9797M2
  • CX_CHAIN_ECB
  • CX_CHAIN_CBC
  • CX_CHAIN_CTR
[in]inInput data.
[in]in_lenLength of the input data. If CX_LAST is set, padding is automatically done according to the mode. Otherwise, in_len shall be a multiple of DES_BLOCK_SIZE.
[out]outOutput data according to the mode:
  • encrypted/decrypted output data
  • generated signature
  • signature to be verified
[in]out_lenLength of the output data.
Returns
Error code:
  • CX_OK on success
  • CX_INVALID_PARAMETER
  • INVALID_PARAMETER

cx_des_no_throw()

cx_err_t cx_des_no_throw ( const cx_des_key_t key,
uint32_t  mode,
const uint8_t *  in,
size_t  in_len,
uint8_t *  out,
size_t *  out_len 
)

Encrypts, decrypts, signs or verifies data with DES algorithm.

Parameters
[in]keyPointer to the key initialized with cx_des_init_key_no_throw.
[in]modeCrypto mode flags. Supported flags:
  • CX_LAST
  • CX_ENCRYPT
  • CX_DECRYPT
  • CX_SIGN
  • CX_VERIFY
  • CX_PAD_NONE
  • CX_PAD_ISO9797M1
  • CX_PAD_ISO9797M2
  • CX_CHAIN_ECB
  • CX_CHAIN_CBC
  • CX_CHAIN_CTR
[in]inInput data.
[in]in_lenLength of the input data. If CX_LAST is set, padding is automatically done according to the mode. Otherwise, in_len shall be a multiple of DES_BLOCK_SIZE.
[out]outOutput data according to the mode:
  • encrypted/decrypted output data
  • generated signature
  • signature to be verified
[in]out_lenLength of the output data.
Returns
Error code:
  • CX_OK on success
  • CX_INVALID_PARAMETER
  • INVALID_PARAMETER

Back to the files list


Did you find this page helpful?


How would you improve this page for developers?



Getting Started
Theme Features
Customization

Nano Apps