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