comparison libtomcrypt/src/modes/ctr/ctr_setiv.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file ctr_setiv.c 12 @file ctr_setiv.c
15 CTR implementation, set IV, Tom St Denis 13 CTR implementation, set IV, Tom St Denis
16 */ 14 */
17 15
18 #ifdef LTC_CTR_MODE 16 #ifdef LTC_CTR_MODE
19 17
20 /** 18 /**
21 Set an initial vector 19 Set an initialization vector
22 @param IV The initial vector 20 @param IV The initialization vector
23 @param len The length of the vector (in octets) 21 @param len The length of the vector (in octets)
24 @param ctr The CTR state 22 @param ctr The CTR state
25 @return CRYPT_OK if successful 23 @return CRYPT_OK if successful
26 */ 24 */
27 int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr) 25 int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
28 { 26 {
29 int err; 27 int err;
30 28
31 LTC_ARGCHK(IV != NULL); 29 LTC_ARGCHK(IV != NULL);
32 LTC_ARGCHK(ctr != NULL); 30 LTC_ARGCHK(ctr != NULL);
33 31
34 /* bad param? */ 32 /* bad param? */
35 if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) { 33 if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
36 return err; 34 return err;
37 } 35 }
38 36
39 if (len != (unsigned long)ctr->blocklen) { 37 if (len != (unsigned long)ctr->blocklen) {
40 return CRYPT_INVALID_ARG; 38 return CRYPT_INVALID_ARG;
41 } 39 }
42 40
43 /* set IV */ 41 /* set IV */
44 XMEMCPY(ctr->ctr, IV, len); 42 XMEMCPY(ctr->ctr, IV, len);
45 43
46 /* force next block */ 44 /* force next block */
47 ctr->padlen = 0; 45 ctr->padlen = 0;
48 return cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key); 46 return cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);
49 } 47 }
50 48
51 #endif 49 #endif
52 50
53 51
54 /* $Source$ */ 52 /* ref: $Format:%D$ */
55 /* $Revision$ */ 53 /* git commit: $Format:%H$ */
56 /* $Date$ */ 54 /* commit time: $Format:%ai$ */