xref: /netbsd-src/sys/crypto/chacha/chacha.h (revision fa79152618fc8fd4c1019d2f19f11c1e3d1b3013)
1*fa791526Sriastradh /*	$NetBSD: chacha.h,v 1.1 2020/07/25 22:46:34 riastradh Exp $	*/
2*fa791526Sriastradh 
3*fa791526Sriastradh /*-
4*fa791526Sriastradh  * Copyright (c) 2020 The NetBSD Foundation, Inc.
5*fa791526Sriastradh  * All rights reserved.
6*fa791526Sriastradh  *
7*fa791526Sriastradh  * Redistribution and use in source and binary forms, with or without
8*fa791526Sriastradh  * modification, are permitted provided that the following conditions
9*fa791526Sriastradh  * are met:
10*fa791526Sriastradh  * 1. Redistributions of source code must retain the above copyright
11*fa791526Sriastradh  *    notice, this list of conditions and the following disclaimer.
12*fa791526Sriastradh  * 2. Redistributions in binary form must reproduce the above copyright
13*fa791526Sriastradh  *    notice, this list of conditions and the following disclaimer in the
14*fa791526Sriastradh  *    documentation and/or other materials provided with the distribution.
15*fa791526Sriastradh  *
16*fa791526Sriastradh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17*fa791526Sriastradh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18*fa791526Sriastradh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*fa791526Sriastradh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20*fa791526Sriastradh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*fa791526Sriastradh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*fa791526Sriastradh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*fa791526Sriastradh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*fa791526Sriastradh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*fa791526Sriastradh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*fa791526Sriastradh  * POSSIBILITY OF SUCH DAMAGE.
27*fa791526Sriastradh  */
28*fa791526Sriastradh 
29*fa791526Sriastradh #ifndef	_SYS_CRYPTO_CHACHA_CHACHA_H
30*fa791526Sriastradh #define	_SYS_CRYPTO_CHACHA_CHACHA_H
31*fa791526Sriastradh 
32*fa791526Sriastradh #include <sys/types.h>
33*fa791526Sriastradh 
34*fa791526Sriastradh #define	CHACHA_KEYBYTES			32
35*fa791526Sriastradh 
36*fa791526Sriastradh #define	CHACHA_CORE_KEYBYTES		CHACHA_KEYBYTES
37*fa791526Sriastradh #define	CHACHA_CORE_INBYTES		16
38*fa791526Sriastradh #define	CHACHA_CORE_CONSTBYTES		16
39*fa791526Sriastradh #define	CHACHA_CORE_OUTBYTES		64
40*fa791526Sriastradh 
41*fa791526Sriastradh #define	HCHACHA_KEYBYTES		CHACHA_KEYBYTES
42*fa791526Sriastradh #define	HCHACHA_INBYTES			16
43*fa791526Sriastradh #define	HCHACHA_CONSTBYTES		16
44*fa791526Sriastradh #define	HCHACHA_OUTBYTES		32
45*fa791526Sriastradh 
46*fa791526Sriastradh #define	CHACHA_STREAM_KEYBYTES		CHACHA_KEYBYTES
47*fa791526Sriastradh #define	CHACHA_STREAM_NONCEBYTES	12
48*fa791526Sriastradh 
49*fa791526Sriastradh #define	XCHACHA_STREAM_KEYBYTES		CHACHA_KEYBYTES
50*fa791526Sriastradh #define	XCHACHA_STREAM_NONCEBYTES	24
51*fa791526Sriastradh 
52*fa791526Sriastradh extern const uint8_t chacha_const32[16];
53*fa791526Sriastradh 
54*fa791526Sriastradh void	chacha_core(uint8_t[restrict static CHACHA_CORE_OUTBYTES],
55*fa791526Sriastradh 	    const uint8_t[static CHACHA_CORE_INBYTES],
56*fa791526Sriastradh 	    const uint8_t[static CHACHA_CORE_KEYBYTES],
57*fa791526Sriastradh 	    const uint8_t[static CHACHA_CORE_CONSTBYTES],
58*fa791526Sriastradh 	    unsigned);
59*fa791526Sriastradh void	hchacha(uint8_t[restrict static HCHACHA_OUTBYTES],
60*fa791526Sriastradh 	    const uint8_t[static HCHACHA_INBYTES],
61*fa791526Sriastradh 	    const uint8_t[static HCHACHA_KEYBYTES],
62*fa791526Sriastradh 	    const uint8_t[static HCHACHA_CONSTBYTES],
63*fa791526Sriastradh 	    unsigned);
64*fa791526Sriastradh void	chacha_stream(uint8_t *restrict, size_t,
65*fa791526Sriastradh 	    uint32_t,
66*fa791526Sriastradh 	    const uint8_t[static CHACHA_STREAM_NONCEBYTES],
67*fa791526Sriastradh 	    const uint8_t[static CHACHA_STREAM_KEYBYTES],
68*fa791526Sriastradh 	    unsigned);
69*fa791526Sriastradh void	chacha_stream_xor(uint8_t *, const uint8_t *, size_t,
70*fa791526Sriastradh 	    uint32_t,
71*fa791526Sriastradh 	    const uint8_t[static CHACHA_STREAM_NONCEBYTES],
72*fa791526Sriastradh 	    const uint8_t[static CHACHA_STREAM_KEYBYTES],
73*fa791526Sriastradh 	    unsigned);
74*fa791526Sriastradh void	xchacha_stream(uint8_t *restrict, size_t,
75*fa791526Sriastradh 	    uint32_t,
76*fa791526Sriastradh 	    const uint8_t[static XCHACHA_STREAM_NONCEBYTES],
77*fa791526Sriastradh 	    const uint8_t[static XCHACHA_STREAM_KEYBYTES],
78*fa791526Sriastradh 	    unsigned);
79*fa791526Sriastradh void	xchacha_stream_xor(uint8_t *, const uint8_t *, size_t,
80*fa791526Sriastradh 	    uint32_t,
81*fa791526Sriastradh 	    const uint8_t[static XCHACHA_STREAM_NONCEBYTES],
82*fa791526Sriastradh 	    const uint8_t[static XCHACHA_STREAM_KEYBYTES],
83*fa791526Sriastradh 	    unsigned);
84*fa791526Sriastradh 
85*fa791526Sriastradh #endif	/* _SYS_CRYPTO_CHACHA_CHACHA_H */
86