xref: /freebsd/sys/contrib/openzfs/include/sys/edonr.h (revision 5d3e7166)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://opensource.org/licenses/CDDL-1.0.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Based on Edon-R implementation for SUPERCOP, based on NIST API.
24  * Copyright (c) 2009, 2010 Jørn Amundsen <jorn.amundsen@ntnu.no>
25  * Copyright (c) 2013 Saso Kiselkov, All rights reserved
26  * Copyright (c) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
27  */
28 
29 #ifndef	_SYS_EDONR_H_
30 #define	_SYS_EDONR_H_
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #ifdef  _KERNEL
37 #include <sys/types.h>
38 #else
39 #include <stdint.h>
40 #include <stdlib.h>
41 #endif
42 
43 /*
44  * EdonR allows to call EdonRUpdate() consecutively only if the total length
45  * of stored unprocessed data and the new supplied data is less than or equal
46  * to the BLOCK_SIZE on which the compression functions operates.
47  * Otherwise an assertion failure is invoked.
48  */
49 
50 /* Specific algorithm definitions */
51 #define	EdonR512_DIGEST_SIZE	64
52 #define	EdonR512_BLOCK_SIZE	128
53 #define	EdonR512_BLOCK_BITSIZE	1024
54 
55 typedef struct {
56 	uint64_t DoublePipe[16];
57 	uint8_t LastPart[EdonR512_BLOCK_SIZE * 2];
58 } EdonRData512;
59 
60 typedef struct {
61 	uint64_t bits_processed;
62 	int unprocessed_bits;
63 	union {
64 		EdonRData512 p512[1];
65 	} pipe[1];
66 } EdonRState;
67 
68 void EdonRInit(EdonRState *state);
69 void EdonRUpdate(EdonRState *state, const uint8_t *data, size_t databitlen);
70 void EdonRFinal(EdonRState *state, uint8_t *hashval);
71 void EdonRHash(const uint8_t *data, size_t databitlen, uint8_t *hashval);
72 
73 #ifdef	__cplusplus
74 }
75 #endif
76 
77 #endif	/* _SYS_EDONR_H_ */
78