xref: /freebsd/sys/crypto/openssl/ossl.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1ba610be9SJohn Baldwin /*
2ba610be9SJohn Baldwin  * Copyright (c) 2020 Netflix, Inc
3ba610be9SJohn Baldwin  *
4ba610be9SJohn Baldwin  * Redistribution and use in source and binary forms, with or without
5ba610be9SJohn Baldwin  * modification, are permitted provided that the following conditions
6ba610be9SJohn Baldwin  * are met:
7ba610be9SJohn Baldwin  * 1. Redistributions of source code must retain the above copyright
8ba610be9SJohn Baldwin  *    notice, this list of conditions and the following disclaimer,
9ba610be9SJohn Baldwin  *    without modification.
10ba610be9SJohn Baldwin  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
11ba610be9SJohn Baldwin  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
12ba610be9SJohn Baldwin  *    redistribution must be conditioned upon including a substantially
13ba610be9SJohn Baldwin  *    similar Disclaimer requirement for further binary redistribution.
14ba610be9SJohn Baldwin  *
15ba610be9SJohn Baldwin  * NO WARRANTY
16ba610be9SJohn Baldwin  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17ba610be9SJohn Baldwin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18ba610be9SJohn Baldwin  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
19ba610be9SJohn Baldwin  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20ba610be9SJohn Baldwin  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
21ba610be9SJohn Baldwin  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22ba610be9SJohn Baldwin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23ba610be9SJohn Baldwin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24ba610be9SJohn Baldwin  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25ba610be9SJohn Baldwin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26ba610be9SJohn Baldwin  * THE POSSIBILITY OF SUCH DAMAGES.
27ba610be9SJohn Baldwin  */
28ba610be9SJohn Baldwin 
29ba610be9SJohn Baldwin #ifndef __OSSL_H__
30ba610be9SJohn Baldwin #define	__OSSL_H__
31ba610be9SJohn Baldwin 
32ba610be9SJohn Baldwin /* Compatibility shims. */
33ba610be9SJohn Baldwin #define	OPENSSL_cleanse		explicit_bzero
34ba610be9SJohn Baldwin 
3592aecd1eSJohn Baldwin struct cryptop;
3692aecd1eSJohn Baldwin struct crypto_session_params;
37197ff4c3SKornel Duleba struct ossl_softc;
38197ff4c3SKornel Duleba struct ossl_session;
3992aecd1eSJohn Baldwin 
4078991a93SJohn Baldwin int	ossl_chacha20_poly1305_decrypt(struct cryptop *crp,
4178991a93SJohn Baldwin 	    const struct crypto_session_params *csp);
4278991a93SJohn Baldwin int	ossl_chacha20_poly1305_encrypt(struct cryptop *crp,
4378991a93SJohn Baldwin 	    const struct crypto_session_params *csp);
44197ff4c3SKornel Duleba void ossl_cpuid(struct ossl_softc *sc);
45197ff4c3SKornel Duleba 
46197ff4c3SKornel Duleba struct ossl_softc {
47197ff4c3SKornel Duleba 	int32_t sc_cid;
48197ff4c3SKornel Duleba 	bool has_aes;
49*9a3444d9SMark Johnston 	bool has_aes_gcm;
50197ff4c3SKornel Duleba };
51ba610be9SJohn Baldwin 
52ba610be9SJohn Baldwin /* Needs to be big enough to hold any hash context. */
53ba610be9SJohn Baldwin struct ossl_hash_context {
54*9a3444d9SMark Johnston 	uint32_t	dummy[196];
55ba610be9SJohn Baldwin } __aligned(32);
56ba610be9SJohn Baldwin 
57197ff4c3SKornel Duleba struct ossl_cipher_context {
58*9a3444d9SMark Johnston 	uint32_t	dummy[196];
59197ff4c3SKornel Duleba } __aligned(32);
60197ff4c3SKornel Duleba 
61197ff4c3SKornel Duleba struct ossl_session_hash {
62197ff4c3SKornel Duleba 	struct ossl_hash_context ictx;
63197ff4c3SKornel Duleba 	struct ossl_hash_context octx;
64197ff4c3SKornel Duleba 	struct auth_hash *axf;
65197ff4c3SKornel Duleba 	u_int mlen;
66197ff4c3SKornel Duleba };
67197ff4c3SKornel Duleba 
68197ff4c3SKornel Duleba struct ossl_session_cipher {
69197ff4c3SKornel Duleba 	struct ossl_cipher_context dec_ctx;
70197ff4c3SKornel Duleba 	struct ossl_cipher_context enc_ctx;
71197ff4c3SKornel Duleba 	struct ossl_cipher *cipher;
72197ff4c3SKornel Duleba };
73197ff4c3SKornel Duleba 
74197ff4c3SKornel Duleba struct ossl_session {
75197ff4c3SKornel Duleba 	struct ossl_session_cipher cipher;
76197ff4c3SKornel Duleba 	struct ossl_session_hash hash;
77197ff4c3SKornel Duleba };
78197ff4c3SKornel Duleba 
79a079e38bSJohn Baldwin extern struct auth_hash ossl_hash_poly1305;
80ba610be9SJohn Baldwin extern struct auth_hash ossl_hash_sha1;
81ba610be9SJohn Baldwin extern struct auth_hash ossl_hash_sha224;
82ba610be9SJohn Baldwin extern struct auth_hash ossl_hash_sha256;
83ba610be9SJohn Baldwin extern struct auth_hash ossl_hash_sha384;
84ba610be9SJohn Baldwin extern struct auth_hash ossl_hash_sha512;
85ba610be9SJohn Baldwin 
86197ff4c3SKornel Duleba extern struct ossl_cipher ossl_cipher_aes_cbc;
87*9a3444d9SMark Johnston extern struct ossl_cipher ossl_cipher_aes_gcm;
88197ff4c3SKornel Duleba extern struct ossl_cipher ossl_cipher_chacha20;
89197ff4c3SKornel Duleba 
90ba610be9SJohn Baldwin #endif /* !__OSSL_H__ */
91