1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3
4 /* The implementation is based on:
5 * chacha-ref.c version 20080118
6 * Public domain from D. J. Bernstein
7 */
8
9 #include "tomcrypt_private.h"
10
11 #ifdef LTC_CHACHA
12
13 /**
14 Generate a stream of random bytes via ChaCha
15 @param st The ChaCha20 state
16 @param out [out] The output buffer
17 @param outlen The output length
18 @return CRYPT_OK on success
19 */
chacha_keystream(chacha_state * st,unsigned char * out,unsigned long outlen)20 int chacha_keystream(chacha_state *st, unsigned char *out, unsigned long outlen)
21 {
22 if (outlen == 0) return CRYPT_OK; /* nothing to do */
23 LTC_ARGCHK(out != NULL);
24 XMEMSET(out, 0, outlen);
25 return chacha_crypt(st, out, outlen, out);
26 }
27
28 #endif
29