xref: /freebsd/sys/compat/linuxkpi/common/include/crypto/hash.h (revision d544b53cb0b6bc25f2ba078bd9c07e611095bf29)
1*d544b53cSBjoern A. Zeeb /*-
2*d544b53cSBjoern A. Zeeb  * SPDX-License-Identifier: BSD-2-Clause
3*d544b53cSBjoern A. Zeeb  *
4*d544b53cSBjoern A. Zeeb  * Copyright (c) 2022 Bjoern A. Zeeb
5*d544b53cSBjoern A. Zeeb  *
6*d544b53cSBjoern A. Zeeb  * Redistribution and use in source and binary forms, with or without
7*d544b53cSBjoern A. Zeeb  * modification, are permitted provided that the following conditions
8*d544b53cSBjoern A. Zeeb  * are met:
9*d544b53cSBjoern A. Zeeb  * 1. Redistributions of source code must retain the above copyright
10*d544b53cSBjoern A. Zeeb  *    notice, this list of conditions and the following disclaimer.
11*d544b53cSBjoern A. Zeeb  * 2. Redistributions in binary form must reproduce the above copyright
12*d544b53cSBjoern A. Zeeb  *    notice, this list of conditions and the following disclaimer in the
13*d544b53cSBjoern A. Zeeb  *    documentation and/or other materials provided with the distribution.
14*d544b53cSBjoern A. Zeeb  *
15*d544b53cSBjoern A. Zeeb  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*d544b53cSBjoern A. Zeeb  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*d544b53cSBjoern A. Zeeb  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*d544b53cSBjoern A. Zeeb  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*d544b53cSBjoern A. Zeeb  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*d544b53cSBjoern A. Zeeb  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*d544b53cSBjoern A. Zeeb  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*d544b53cSBjoern A. Zeeb  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*d544b53cSBjoern A. Zeeb  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*d544b53cSBjoern A. Zeeb  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*d544b53cSBjoern A. Zeeb  * SUCH DAMAGE.
26*d544b53cSBjoern A. Zeeb  */
27*d544b53cSBjoern A. Zeeb 
28*d544b53cSBjoern A. Zeeb #ifndef _LINUXKPI_CRYPTO_HASH_H
29*d544b53cSBjoern A. Zeeb #define _LINUXKPI_CRYPTO_HASH_H
30*d544b53cSBjoern A. Zeeb 
31*d544b53cSBjoern A. Zeeb #include <linux/kernel.h>	/* for pr_debug */
32*d544b53cSBjoern A. Zeeb 
33*d544b53cSBjoern A. Zeeb struct crypto_shash {
34*d544b53cSBjoern A. Zeeb };
35*d544b53cSBjoern A. Zeeb 
36*d544b53cSBjoern A. Zeeb struct shash_desc {
37*d544b53cSBjoern A. Zeeb 	struct crypto_shash	*tfm;
38*d544b53cSBjoern A. Zeeb };
39*d544b53cSBjoern A. Zeeb 
40*d544b53cSBjoern A. Zeeb static inline struct crypto_shash *
crypto_alloc_shash(const char * algostr,int x,int y)41*d544b53cSBjoern A. Zeeb crypto_alloc_shash(const char *algostr, int x, int y)
42*d544b53cSBjoern A. Zeeb {
43*d544b53cSBjoern A. Zeeb 
44*d544b53cSBjoern A. Zeeb 	pr_debug("%s: TODO\n", __func__);
45*d544b53cSBjoern A. Zeeb 	return (NULL);
46*d544b53cSBjoern A. Zeeb }
47*d544b53cSBjoern A. Zeeb 
48*d544b53cSBjoern A. Zeeb static inline void
crypto_free_shash(struct crypto_shash * csh)49*d544b53cSBjoern A. Zeeb crypto_free_shash(struct crypto_shash *csh)
50*d544b53cSBjoern A. Zeeb {
51*d544b53cSBjoern A. Zeeb 	pr_debug("%s: TODO\n", __func__);
52*d544b53cSBjoern A. Zeeb }
53*d544b53cSBjoern A. Zeeb 
54*d544b53cSBjoern A. Zeeb static inline int
crypto_shash_init(struct shash_desc * desc)55*d544b53cSBjoern A. Zeeb crypto_shash_init(struct shash_desc *desc)
56*d544b53cSBjoern A. Zeeb {
57*d544b53cSBjoern A. Zeeb 	pr_debug("%s: TODO\n", __func__);
58*d544b53cSBjoern A. Zeeb 	return (-ENXIO);
59*d544b53cSBjoern A. Zeeb }
60*d544b53cSBjoern A. Zeeb 
61*d544b53cSBjoern A. Zeeb static inline int
crypto_shash_final(struct shash_desc * desc,uint8_t * mic)62*d544b53cSBjoern A. Zeeb crypto_shash_final(struct shash_desc *desc, uint8_t *mic)
63*d544b53cSBjoern A. Zeeb {
64*d544b53cSBjoern A. Zeeb 	pr_debug("%s: TODO\n", __func__);
65*d544b53cSBjoern A. Zeeb 	return (-ENXIO);
66*d544b53cSBjoern A. Zeeb }
67*d544b53cSBjoern A. Zeeb 
68*d544b53cSBjoern A. Zeeb static inline int
crypto_shash_setkey(struct crypto_shash * csh,const uint8_t * key,size_t keylen)69*d544b53cSBjoern A. Zeeb crypto_shash_setkey(struct crypto_shash *csh, const uint8_t *key, size_t keylen)
70*d544b53cSBjoern A. Zeeb {
71*d544b53cSBjoern A. Zeeb 	pr_debug("%s: TODO\n", __func__);
72*d544b53cSBjoern A. Zeeb 	return (-ENXIO);
73*d544b53cSBjoern A. Zeeb }
74*d544b53cSBjoern A. Zeeb 
75*d544b53cSBjoern A. Zeeb static inline int
crypto_shash_update(struct shash_desc * desc,uint8_t * data,size_t datalen)76*d544b53cSBjoern A. Zeeb crypto_shash_update(struct shash_desc *desc, uint8_t *data, size_t datalen)
77*d544b53cSBjoern A. Zeeb {
78*d544b53cSBjoern A. Zeeb 	pr_debug("%s: TODO\n", __func__);
79*d544b53cSBjoern A. Zeeb 	return (-ENXIO);
80*d544b53cSBjoern A. Zeeb }
81*d544b53cSBjoern A. Zeeb 
82*d544b53cSBjoern A. Zeeb static inline void
shash_desc_zero(struct shash_desc * desc)83*d544b53cSBjoern A. Zeeb shash_desc_zero(struct shash_desc *desc)
84*d544b53cSBjoern A. Zeeb {
85*d544b53cSBjoern A. Zeeb 
86*d544b53cSBjoern A. Zeeb 	explicit_bzero(desc, sizeof(*desc));
87*d544b53cSBjoern A. Zeeb }
88*d544b53cSBjoern A. Zeeb 
89*d544b53cSBjoern A. Zeeb /* XXX review this. */
90*d544b53cSBjoern A. Zeeb #define	SHASH_DESC_ON_STACK(desc, tfm)					\
91*d544b53cSBjoern A. Zeeb 	uint8_t ___ ## desc ## _desc[sizeof(struct shash_desc)];	\
92*d544b53cSBjoern A. Zeeb 	struct shash_desc *desc = (struct shash_desc *)___ ## desc ## _desc
93*d544b53cSBjoern A. Zeeb 
94*d544b53cSBjoern A. Zeeb #endif /* _LINUXKPI_CRYPTO_HASH_H */
95