Path: blob/master/libs/tomcrypt/src/modes/cfb/cfb_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 cfb_start.c12CFB implementation, start chain, Tom St Denis13*/141516#ifdef LTC_CFB_MODE1718/**19Initialize a CFB context20@param cipher The index of the cipher desired21@param IV The initialization vector22@param key The secret key23@param keylen The length of the secret key (octets)24@param num_rounds Number of rounds in the cipher desired (0 for default)25@param cfb The CFB state to initialize26@return CRYPT_OK if successful27*/28int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,29int keylen, int num_rounds, symmetric_CFB *cfb)30{31int x, err;3233LTC_ARGCHK(IV != NULL);34LTC_ARGCHK(key != NULL);35LTC_ARGCHK(cfb != NULL);3637if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {38return err;39}404142/* copy data */43cfb->cipher = cipher;44cfb->blocklen = cipher_descriptor[cipher].block_length;45for (x = 0; x < cfb->blocklen; x++)46cfb->IV[x] = IV[x];4748/* init the cipher */49if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cfb->key)) != CRYPT_OK) {50return err;51}5253/* encrypt the IV */54cfb->padlen = 0;55return cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->IV, cfb->IV, &cfb->key);56}5758#endif596061