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 #include "tomcrypt_private.h"
12
13 #ifdef LTC_XSALSA20
14
15 /**
16 Encrypt (or decrypt) bytes of ciphertext (or plaintext) with XSalsa20
17 @param key The key
18 @param keylen The key length
19 @param nonce The initial vector
20 @param noncelen The initial vector length
21 @param datain The plaintext (or ciphertext)
22 @param datalen The length of the input and output (octets)
23 @param rounds The number of rounds
24 @param dataout [out] The ciphertext (or plaintext)
25 @return CRYPT_OK if successful
26 */
xsalsa20_memory(const unsigned char * key,unsigned long keylen,unsigned long rounds,const unsigned char * nonce,unsigned long noncelen,const unsigned char * datain,unsigned long datalen,unsigned char * dataout)27 int xsalsa20_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
28 const unsigned char *nonce, unsigned long noncelen,
29 const unsigned char *datain, unsigned long datalen, unsigned char *dataout)
30 {
31 salsa20_state st;
32 int err;
33
34 if ((err = xsalsa20_setup(&st, key, keylen, nonce, noncelen, rounds)) != CRYPT_OK) goto WIPE_KEY;
35 err = salsa20_crypt(&st, datain, datalen, dataout);
36 WIPE_KEY:
37 salsa20_done(&st);
38 return err;
39 }
40
41 #endif /* LTC_XSALSA20 */
42
43 /* ref: $Format:%D$ */
44 /* git commit: $Format:%H$ */
45 /* commit time: $Format:%ai$ */
46