xref: /netbsd-src/sys/crypto/chacha/chacha_impl.h (revision fa79152618fc8fd4c1019d2f19f11c1e3d1b3013)
1*fa791526Sriastradh /*	$NetBSD: chacha_impl.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_IMPL_H
30*fa791526Sriastradh #define	_SYS_CRYPTO_CHACHA_CHACHA_IMPL_H
31*fa791526Sriastradh 
32*fa791526Sriastradh #ifdef _KERNEL
33*fa791526Sriastradh #include <sys/types.h>
34*fa791526Sriastradh #include <sys/systm.h>
35*fa791526Sriastradh #else
36*fa791526Sriastradh #include <stdint.h>
37*fa791526Sriastradh #include <string.h>
38*fa791526Sriastradh #endif
39*fa791526Sriastradh 
40*fa791526Sriastradh #include <crypto/chacha/chacha.h>
41*fa791526Sriastradh 
42*fa791526Sriastradh struct chacha_impl {
43*fa791526Sriastradh 	const char *ci_name;
44*fa791526Sriastradh 	int	(*ci_probe)(void);
45*fa791526Sriastradh 	void	(*ci_chacha_core)(uint8_t[restrict static CHACHA_CORE_OUTBYTES],
46*fa791526Sriastradh 		    const uint8_t[static CHACHA_CORE_INBYTES],
47*fa791526Sriastradh 		    const uint8_t[static CHACHA_CORE_KEYBYTES],
48*fa791526Sriastradh 		    const uint8_t[static CHACHA_CORE_CONSTBYTES],
49*fa791526Sriastradh 		    unsigned);
50*fa791526Sriastradh 	void	(*ci_hchacha)(uint8_t[restrict static HCHACHA_OUTBYTES],
51*fa791526Sriastradh 		    const uint8_t[static HCHACHA_INBYTES],
52*fa791526Sriastradh 		    const uint8_t[static HCHACHA_KEYBYTES],
53*fa791526Sriastradh 		    const uint8_t[static HCHACHA_CONSTBYTES],
54*fa791526Sriastradh 		    unsigned);
55*fa791526Sriastradh 	void	(*ci_chacha_stream)(uint8_t *restrict, size_t,
56*fa791526Sriastradh 		    uint32_t,
57*fa791526Sriastradh 		    const uint8_t[static CHACHA_STREAM_NONCEBYTES],
58*fa791526Sriastradh 		    const uint8_t[static CHACHA_STREAM_KEYBYTES],
59*fa791526Sriastradh 		    unsigned);
60*fa791526Sriastradh 	void	(*ci_chacha_stream_xor)(uint8_t *, const uint8_t *,
61*fa791526Sriastradh 		    size_t,
62*fa791526Sriastradh 		    uint32_t,
63*fa791526Sriastradh 		    const uint8_t[static CHACHA_STREAM_NONCEBYTES],
64*fa791526Sriastradh 		    const uint8_t[static CHACHA_STREAM_KEYBYTES],
65*fa791526Sriastradh 		    unsigned);
66*fa791526Sriastradh 	void	(*ci_xchacha_stream)(uint8_t *restrict, size_t,
67*fa791526Sriastradh 		    uint32_t,
68*fa791526Sriastradh 		    const uint8_t[static XCHACHA_STREAM_NONCEBYTES],
69*fa791526Sriastradh 		    const uint8_t[static XCHACHA_STREAM_KEYBYTES],
70*fa791526Sriastradh 		    unsigned);
71*fa791526Sriastradh 	void	(*ci_xchacha_stream_xor)(uint8_t *, const uint8_t *,
72*fa791526Sriastradh 		    size_t,
73*fa791526Sriastradh 		    uint32_t,
74*fa791526Sriastradh 		    const uint8_t[static XCHACHA_STREAM_NONCEBYTES],
75*fa791526Sriastradh 		    const uint8_t[static XCHACHA_STREAM_KEYBYTES],
76*fa791526Sriastradh 		    unsigned);
77*fa791526Sriastradh };
78*fa791526Sriastradh 
79*fa791526Sriastradh int	chacha_selftest(const struct chacha_impl *);
80*fa791526Sriastradh 
81*fa791526Sriastradh void	chacha_md_init(const struct chacha_impl *);
82*fa791526Sriastradh 
83*fa791526Sriastradh #endif	/* _SYS_CRYPTO_CHACHA_CHACHA_IMPL_H */
84