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