1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3
4 /* The implementation is based on:
5 * "Salsa20 specification", http://cr.yp.to/snuffle/spec.pdf
6 * and salsa20-ref.c version 20051118
7 * Public domain from D. J. Bernstein
8 */
9
10 #include "tomcrypt_private.h"
11
12 #ifdef LTC_SALSA20
13
14 /**
15 Set IV + counter data to the Salsa20 state
16 @param st The Salsa20 state
17 @param iv The IV data to add
18 @param ivlen The length of the IV (must be 8)
19 @param counter 64bit (unsigned) initial counter value
20 @return CRYPT_OK on success
21 */
salsa20_ivctr64(salsa20_state * st,const unsigned char * iv,unsigned long ivlen,ulong64 counter)22 int salsa20_ivctr64(salsa20_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 counter)
23 {
24 LTC_ARGCHK(st != NULL);
25 LTC_ARGCHK(iv != NULL);
26 /* Salsa20: 64-bit IV (nonce) + 64-bit counter */
27 LTC_ARGCHK(ivlen == 8);
28
29 LOAD32L(st->input[6], iv + 0);
30 LOAD32L(st->input[7], iv + 4);
31 st->input[8] = (ulong32)(counter & 0xFFFFFFFF);
32 st->input[9] = (ulong32)(counter >> 32);
33 st->ksleft = 0;
34 st->ivlen = ivlen;
35 return CRYPT_OK;
36 }
37
38 #endif
39