cbc.h

Cipher block chaining mode of operation for block ciphers.

int cipher_encrypt_cbc(cipher_t * cipher, uint8_t iv, const uint8_t * input, msp430_types.h::size_t input_len, uint8_t * output)

Encrypt data of arbitrary length in cipher block chaining mode.

Parameters

cipher:Already initialized cipher struct
iv:16 octet initialization vector. Must never be used more than once for a given key.
input:pointer to input data to encrypt
input_len:length of the input data
output:pointer to allocated memory for encrypted data. It has to be of size data_len + BLOCK_SIZE - data_len % BLOCK_SIZE.

Return values

  • <0 on error
  • CIPHER_ERR_INVALID_LENGTH when input_len % BLOCK_SIZE != 0
  • CIPHER_ERR_ENC_FAILED on internal encrption error
  • otherwise number of input bytes that aren’t consumed
int cipher_decrypt_cbc(cipher_t * cipher, uint8_t iv, const uint8_t * input, msp430_types.h::size_t input_len, uint8_t * output)

Decrypt encrypted data in cipher block chaining mode.

Parameters

cipher:Already initialized cipher struct
iv:16 octet initialization vector.
input:pointer to input data to decrypt
input_len:length of the input data
output:pointer to allocated memory for plaintext data. It has to be of size input_len.

Return values

  • <0 on error
  • CIPHER_ERR_INVALID_LENGTH when input_len % BLOCK_SIZE != 0
  • CIPHER_ERR_DEC_FAILED on internal decryption error
  • otherwise number of bytes decrypted