Path: blob/master/libs/tomcrypt/src/modes/ofb/ofb_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 ofb_start.c12OFB implementation, start chain, Tom St Denis13*/141516#ifdef LTC_OFB_MODE1718/**19Initialize a OFB 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 ofb The OFB state to initialize26@return CRYPT_OK if successful27*/28int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,29int keylen, int num_rounds, symmetric_OFB *ofb)30{31int x, err;3233LTC_ARGCHK(IV != NULL);34LTC_ARGCHK(key != NULL);35LTC_ARGCHK(ofb != NULL);3637if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {38return err;39}4041/* copy details */42ofb->cipher = cipher;43ofb->blocklen = cipher_descriptor[cipher].block_length;44for (x = 0; x < ofb->blocklen; x++) {45ofb->IV[x] = IV[x];46}4748/* init the cipher */49ofb->padlen = ofb->blocklen;50return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ofb->key);51}5253#endif545556