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