ndn-lite
Functions
tc_cbc_mode.c File Reference
#include "tc_cbc_mode.h"
#include "tc_constants.h"
#include "tc_utils.h"

Functions

int tc_cbc_mode_encrypt (uint8_t *out, unsigned int outlen, const uint8_t *in, unsigned int inlen, const uint8_t *iv, const TCAesKeySched_t sched)
 CBC encryption procedure CBC encrypts inlen bytes of the in buffer into the out buffer using the encryption key schedule provided, prepends iv to out. More...
 
int tc_cbc_mode_decrypt (uint8_t *out, unsigned int outlen, const uint8_t *in, unsigned int inlen, const uint8_t *iv, const TCAesKeySched_t sched)
 CBC decryption procedure CBC decrypts inlen bytes of the in buffer into the out buffer using the provided encryption key schedule. More...
 

Function Documentation

◆ tc_cbc_mode_decrypt()

int tc_cbc_mode_decrypt ( uint8_t *  out,
unsigned int  outlen,
const uint8_t *  in,
unsigned int  inlen,
const uint8_t *  iv,
const TCAesKeySched_t  sched 
)

CBC decryption procedure CBC decrypts inlen bytes of the in buffer into the out buffer using the provided encryption key schedule.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: out == NULL or in == NULL or sched == NULL or inlen == 0 or outlen == 0 or (inlen % TC_AES_BLOCK_SIZE) != 0 or (outlen % TC_AES_BLOCK_SIZE) != 0 or outlen != inlen + TC_AES_BLOCK_SIZE
Note
Assumes:- in == iv + ciphertext, i.e. the iv and the ciphertext are contiguous. This allows for a very efficient decryption algorithm that would not otherwise be possible
  • sched was configured by aes_set_decrypt_key
  • out buffer is large enough to hold the decrypted plaintext and is a contiguous buffer
  • inlen gives the number of bytes in the in buffer
Parameters
outIN/OUT – buffer to receive decrypted data
outlenIN – length of plaintext buffer in bytes
inIN – ciphertext to decrypt, including IV
inlenIN – length of ciphertext buffer in bytes
ivIN – the IV for the this encrypt/decrypt
schedIN – AES key schedule for this decrypt

◆ tc_cbc_mode_encrypt()

int tc_cbc_mode_encrypt ( uint8_t *  out,
unsigned int  outlen,
const uint8_t *  in,
unsigned int  inlen,
const uint8_t *  iv,
const TCAesKeySched_t  sched 
)

CBC encryption procedure CBC encrypts inlen bytes of the in buffer into the out buffer using the encryption key schedule provided, prepends iv to out.

Returns
returns TC_CRYPTO_SUCCESS (1) returns TC_CRYPTO_FAIL (0) if: out == NULL or in == NULL or ctr == NULL or sched == NULL or inlen == 0 or (inlen % TC_AES_BLOCK_SIZE) != 0 or (outlen % TC_AES_BLOCK_SIZE) != 0 or outlen != inlen + TC_AES_BLOCK_SIZE
Note
Assumes: - sched has been configured by aes_set_encrypt_key
  • iv contains a 16 byte random string
  • out buffer is large enough to hold the ciphertext + iv
  • out buffer is a contiguous buffer
  • in holds the plaintext and is a contiguous buffer
  • inlen gives the number of bytes in the in buffer
Parameters
outIN/OUT – buffer to receive the ciphertext
outlenIN – length of ciphertext buffer in bytes
inIN – plaintext to encrypt
inlenIN – length of plaintext buffer in bytes
ivIN – the IV for the this encrypt/decrypt
schedIN – AES key schedule for this encrypt