Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/tomcrypt/src/modes/ctr/ctr_setiv.c
5972 views
1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2
*
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
5
*
6
* The library is free for all purposes without any express
7
* guarantee it works.
8
*/
9
#include "tomcrypt.h"
10
11
/**
12
@file ctr_setiv.c
13
CTR implementation, set IV, Tom St Denis
14
*/
15
16
#ifdef LTC_CTR_MODE
17
18
/**
19
Set an initialization vector
20
@param IV The initialization vector
21
@param len The length of the vector (in octets)
22
@param ctr The CTR state
23
@return CRYPT_OK if successful
24
*/
25
int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
26
{
27
int err;
28
29
LTC_ARGCHK(IV != NULL);
30
LTC_ARGCHK(ctr != NULL);
31
32
/* bad param? */
33
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
34
return err;
35
}
36
37
if (len != (unsigned long)ctr->blocklen) {
38
return CRYPT_INVALID_ARG;
39
}
40
41
/* set IV */
42
XMEMCPY(ctr->ctr, IV, len);
43
44
/* force next block */
45
ctr->padlen = 0;
46
return cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);
47
}
48
49
#endif
50
51