Path: blob/master/libs/tomcrypt/src/modes/ctr/ctr_setiv.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 ctr_setiv.c12CTR implementation, set IV, Tom St Denis13*/1415#ifdef LTC_CTR_MODE1617/**18Set an initialization vector19@param IV The initialization vector20@param len The length of the vector (in octets)21@param ctr The CTR state22@return CRYPT_OK if successful23*/24int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)25{26int err;2728LTC_ARGCHK(IV != NULL);29LTC_ARGCHK(ctr != NULL);3031/* bad param? */32if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {33return err;34}3536if (len != (unsigned long)ctr->blocklen) {37return CRYPT_INVALID_ARG;38}3940/* set IV */41XMEMCPY(ctr->ctr, IV, len);4243/* force next block */44ctr->padlen = 0;45return cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);46}4748#endif495051