2004-05-31 02:36:47 +00:00
|
|
|
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
|
|
|
*
|
|
|
|
* LibTomCrypt is a library that provides various cryptographic
|
|
|
|
* algorithms in a highly modular and flexible manner.
|
|
|
|
*
|
|
|
|
* The library is free for all purposes without any express
|
|
|
|
* guarantee it works.
|
|
|
|
*
|
2005-04-17 11:37:13 +00:00
|
|
|
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
2004-05-31 02:36:47 +00:00
|
|
|
*/
|
2004-12-30 23:55:53 +00:00
|
|
|
#include "tomcrypt.h"
|
2004-05-31 02:36:47 +00:00
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/**
|
|
|
|
@file ctr_setiv.c
|
|
|
|
CTR implementation, set IV, Tom St Denis
|
|
|
|
*/
|
|
|
|
|
2004-05-31 02:36:47 +00:00
|
|
|
#ifdef CTR
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/**
|
|
|
|
Set an initial vector
|
|
|
|
@param IV The initial vector
|
|
|
|
@param len The length of the vector (in octets)
|
|
|
|
@param ctr The CTR state
|
|
|
|
@return CRYPT_OK if successful
|
|
|
|
*/
|
2004-05-31 02:36:47 +00:00
|
|
|
int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
LTC_ARGCHK(IV != NULL);
|
|
|
|
LTC_ARGCHK(ctr != NULL);
|
2004-05-31 02:36:47 +00:00
|
|
|
|
|
|
|
/* bad param? */
|
|
|
|
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != (unsigned long)ctr->blocklen) {
|
|
|
|
return CRYPT_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set IV */
|
2004-06-20 02:41:49 +00:00
|
|
|
XMEMCPY(ctr->ctr, IV, len);
|
2004-05-31 02:36:47 +00:00
|
|
|
|
|
|
|
/* force next block */
|
|
|
|
ctr->padlen = 0;
|
2005-11-18 05:15:37 +00:00
|
|
|
return cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);
|
2004-05-31 02:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-06-09 00:08:13 +00:00
|
|
|
|
|
|
|
/* $Source$ */
|
|
|
|
/* $Revision$ */
|
|
|
|
/* $Date$ */
|