1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3
4 #include "tomcrypt_private.h"
5
6 #ifdef LTC_XSALSA20
7
8 /**
9 Encrypt (or decrypt) bytes of ciphertext (or plaintext) with XSalsa20
10 @param key The key
11 @param keylen The key length
12 @param nonce The initial vector
13 @param noncelen The initial vector length
14 @param datain The plaintext (or ciphertext)
15 @param datalen The length of the input and output (octets)
16 @param rounds The number of rounds
17 @param dataout [out] The ciphertext (or plaintext)
18 @return CRYPT_OK if successful
19 */
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)20 int xsalsa20_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
21 const unsigned char *nonce, unsigned long noncelen,
22 const unsigned char *datain, unsigned long datalen, unsigned char *dataout)
23 {
24 salsa20_state st;
25 int err;
26
27 if ((err = xsalsa20_setup(&st, key, keylen, nonce, noncelen, rounds)) != CRYPT_OK) goto WIPE_KEY;
28 err = salsa20_crypt(&st, datain, datalen, dataout);
29 WIPE_KEY:
30 salsa20_done(&st);
31 return err;
32 }
33
34 #endif /* LTC_XSALSA20 */
35