xref: /titanic_50/usr/src/common/crypto/chacha/chacha.h (revision 9bc2928da4128bbbe0feaaa43090efe2ea01abe2)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright (c) 2015, Joyent, Inc.
14  */
15 
16 #ifndef _CHACHA_H
17 #define	_CHACHA_H
18 
19 /*
20  * ChaCha cipher implementation header
21  *
22  * Note, the chacha C files that we have, have a compile time option for
23  * generating a keystream only. eg. in other words -DKEYSTREAM_ONLY. If using
24  * chacha, for something like arc4random, where you aren't doing encryption,
25  * then you should pass -DKEYSTREAM_ONLY. If encryption is being done, then it
26  * should not be defined. The main difference is basically doing another pass
27  * over the data and xoring it with the generated cipher.
28  */
29 
30 #include <inttypes.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct chacha_ctx {
37 	uint32_t chacha_input[16];
38 } chacha_ctx_t;
39 
40 extern void chacha_keysetup(chacha_ctx_t *, const uint8_t *, uint32_t,
41     uint32_t);
42 extern void chacha_ivsetup(chacha_ctx_t *, const uint8_t *);
43 extern void chacha_encrypt_bytes(chacha_ctx_t *, const uint8_t *, uint8_t *,
44     uint32_t);
45 
46 #ifdef __cplusplus
47 }
48 #endif
49 
50 #endif /* _CHACHA_H */
51