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 * chacha-ref.c version 20080118
13 * Public domain from D. J. Bernstein
14 */
15
16 #include "tomcrypt_private.h"
17
18 #ifdef LTC_CHACHA
19
20 /**
21 Generate a stream of random bytes via ChaCha
22 @param st The ChaCha20 state
23 @param out [out] The output buffer
24 @param outlen The output length
25 @return CRYPT_OK on success
26 */
chacha_keystream(chacha_state * st,unsigned char * out,unsigned long outlen)27 int chacha_keystream(chacha_state *st, unsigned char *out, unsigned long outlen)
28 {
29 if (outlen == 0) return CRYPT_OK; /* nothing to do */
30 LTC_ARGCHK(out != NULL);
31 XMEMSET(out, 0, outlen);
32 return chacha_crypt(st, out, outlen, out);
33 }
34
35 #endif
36
37 /* ref: $Format:%D$ */
38 /* git commit: $Format:%H$ */
39 /* commit time: $Format:%ai$ */
40