Path: blob/master/libs/tomcrypt/src/modes/cbc/cbc_start.c
5972 views
/* LibTomCrypt, modular cryptographic library -- Tom St Denis1*2* LibTomCrypt is a library that provides various cryptographic3* algorithms in a highly modular and flexible manner.4*5* The library is free for all purposes without any express6* guarantee it works.7*/8#include "tomcrypt.h"910/**11@file cbc_start.c12CBC implementation, start chain, Tom St Denis13*/1415#ifdef LTC_CBC_MODE1617/**18Initialize a CBC context19@param cipher The index of the cipher desired20@param IV The initialization vector21@param key The secret key22@param keylen The length of the secret key (octets)23@param num_rounds Number of rounds in the cipher desired (0 for default)24@param cbc The CBC state to initialize25@return CRYPT_OK if successful26*/27int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,28int keylen, int num_rounds, symmetric_CBC *cbc)29{30int x, err;3132LTC_ARGCHK(IV != NULL);33LTC_ARGCHK(key != NULL);34LTC_ARGCHK(cbc != NULL);3536/* bad param? */37if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {38return err;39}4041/* setup cipher */42if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cbc->key)) != CRYPT_OK) {43return err;44}4546/* copy IV */47cbc->blocklen = cipher_descriptor[cipher].block_length;48cbc->cipher = cipher;49for (x = 0; x < cbc->blocklen; x++) {50cbc->IV[x] = IV[x];51}52return CRYPT_OK;53}5455#endif565758