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 8)
24 @param counter 64bit (unsigned) initial counter value
25 @return CRYPT_OK on success
27 int chacha_ivctr64(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 counter)
29 LTC_ARGCHK(st != NULL);
30 LTC_ARGCHK(iv != NULL);
31 /* 64bit IV + 64bit counter */
32 LTC_ARGCHK(ivlen == 8);
34 st->input[12] = (ulong32)(counter & 0xFFFFFFFF);
35 st->input[13] = (ulong32)(counter >> 32);
36 LOAD32L(st->input[14], iv + 0);
37 LOAD32L(st->input[15], iv + 4);
45 /* ref: $Format:%D$ */
46 /* git commit: $Format:%H$ */
47 /* commit time: $Format:%ai$ */