1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 *
4 * LibTomCrypt is a library that provides various cryptographic
5 * algorithms in a highly modular and flexible manner.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10
11 /* The implementation is based on:
12 * "Salsa20 specification", http://cr.yp.to/snuffle/spec.pdf
13 * and salsa20-ref.c version 20051118
14 * Public domain from D. J. Bernstein
15 */
16
17 #include "tomcrypt_private.h"
18
19 #ifdef LTC_SALSA20
20
21 /**
22 Set IV + counter data to the Salsa20 state
23 @param st The Salsa20 state
24 @param iv The IV data to add
25 @param ivlen The length of the IV (must be 8)
26 @param counter 64bit (unsigned) initial counter value
27 @return CRYPT_OK on success
28 */
salsa20_ivctr64(salsa20_state * st,const unsigned char * iv,unsigned long ivlen,ulong64 counter)29 int salsa20_ivctr64(salsa20_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 counter)
30 {
31 LTC_ARGCHK(st != NULL);
32 LTC_ARGCHK(iv != NULL);
33 /* Salsa20: 64-bit IV (nonce) + 64-bit counter */
34 LTC_ARGCHK(ivlen == 8);
35
36 LOAD32L(st->input[6], iv + 0);
37 LOAD32L(st->input[7], iv + 4);
38 st->input[8] = (ulong32)(counter & 0xFFFFFFFF);
39 st->input[9] = (ulong32)(counter >> 32);
40 st->ksleft = 0;
41 st->ivlen = ivlen;
42 return CRYPT_OK;
43 }
44
45 #endif
46
47 /* ref: $Format:%D$ */
48 /* git commit: $Format:%H$ */
49 /* commit time: $Format:%ai$ */
50