1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
10 /* The implementation is based on:
11 * chacha-ref.c version 20080118
12 * Public domain from D. J. Bernstein
20 Set IV + counter data to the ChaCha state
21 @param st The ChaCha20 state
22 @param iv The IV data to add
23 @param ivlen The length of the IV (must be 12)
24 @param counter 32bit (unsigned) initial counter value
25 @return CRYPT_OK on success
27 int chacha_ivctr32(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong32 counter)
29 LTC_ARGCHK(st != NULL);
30 LTC_ARGCHK(iv != NULL);
31 /* 96bit IV + 32bit counter */
32 LTC_ARGCHK(ivlen == 12);
34 st->input[12] = counter;
35 LOAD32L(st->input[13], iv + 0);
36 LOAD32L(st->input[14], iv + 4);
37 LOAD32L(st->input[15], iv + 8);
45 /* ref: $Format:%D$ */
46 /* git commit: $Format:%H$ */
47 /* commit time: $Format:%ai$ */