forked from XKCP/XKCP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Xoofff.h
147 lines (126 loc) · 5.46 KB
/
Xoofff.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
The eXtended Keccak Code Package (XKCP)
https://github.com/XKCP/XKCP
Xoofff, designed by Joan Daemen, Seth Hoffert, Gilles Van Assche and Ronny Van Keer.
Implementation by Ronny Van Keer, hereby denoted as "the implementer".
For more information, feedback or questions, please refer to the Keccak Team website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef _Xoofff_h_
#define _Xoofff_h_
#include "config.h"
#ifdef XKCP_has_Xoodoo
#include <stddef.h>
#include <stdint.h>
#include "align.h"
#include "Xoodoo-SnP.h"
#define SnP_widthInBytes (3*4*4)
#define Xoofff_RollSizeInBytes SnP_widthInBytes
#define Xoofff_RollOffset 0
#define Xoofff_FlagNone 0
#define Xoofff_FlagInit 1 /* If set, initialize a new Xoofff_Compress session */
#define Xoofff_FlagLastPart 2 /* If set, indicates the last part of input/output */
#define Xoofff_FlagXoofffie 4 /* If set, indicates Xoofffie will be performed */
#ifndef _Keccak_BitTypes_
#define _Keccak_BitTypes_
typedef uint8_t BitSequence;
typedef size_t BitLength;
#endif
typedef enum
{
NOT_INITIALIZED_YET,
COMPRESSING,
EXPANDING,
EXPANDED,
} Xoofff_Phases;
#ifdef XKCP_has_Xoodootimes16
#include "Xoodoo-times16-SnP.h"
#endif
#ifdef XKCP_has_Xoodootimes8
#include "Xoodoo-times8-SnP.h"
#endif
#ifdef XKCP_has_Xoodootimes4
#include "Xoodoo-times4-SnP.h"
#endif
#include "Xoodoo-SnP.h"
#if defined(XKCP_has_Xoodootimes16) && !defined(Xoodootimes16_isFallback)
#define XoodooMaxParallellism 16
#define Xoofff_Alignment Xoodootimes16_statesAlignment
#if defined(Xoodootimes16_FastXoofff_supported)
#define Xoofff_AddIs Xooffftimes16_AddIs
#endif
#elif defined(XKCP_has_Xoodootimes8) && !defined(Xoodootimes8_isFallback)
#define XoodooMaxParallellism 8
#define Xoofff_Alignment Xoodootimes8_statesAlignment
#if defined(Xoodootimes8_FastXoofff_supported)
#define Xoofff_AddIs Xooffftimes8_AddIs
#endif
#elif defined(XKCP_has_Xoodootimes4) && !defined(Xoodootimes4_isFallback)
#define XoodooMaxParallellism 4
#define Xoofff_Alignment Xoodootimes4_statesAlignment
#if defined(Xoodootimes4_FastXoofff_supported)
#define Xoofff_AddIs Xooffftimes4_AddIs
#endif
#else
#define XoodooMaxParallellism 1
#define Xoofff_Alignment Xoodoo_stateAlignment
#endif
ALIGN(Xoofff_Alignment) typedef struct
{
unsigned char a[SnP_widthInBytes];
} Xoofff_AlignedArray;
typedef struct {
Xoofff_AlignedArray k;
Xoofff_AlignedArray kRoll;
Xoofff_AlignedArray xAccu;
Xoofff_AlignedArray yAccu;
Xoofff_AlignedArray queue; /* input/output queue buffer */
BitLength queueOffset; /* current offset in queue */
Xoofff_Phases phase;
} Xoofff_Instance;
/**
* Function to initialize a Xoofff instance with given key.
* @param xpInstance Pointer to the instance to be initialized.
* @param Key Pointer to the key (K).
* @param KeyBitLen The length of the key in bits.
* @return 0 if successful, 1 otherwise.
*/
int Xoofff_MaskDerivation(Xoofff_Instance *xpInstance, const BitSequence *Key, BitLength KeyBitLen);
/**
* Function to handle input data to be compressed.
* @param xpInstance Pointer to the instance initialized by Xoofff_MaskDerivation().
* @param input Pointer to the input message data (M).
* @param inputBitLen The number of bits provided in the input message data.
* This must be a multiple of 8 if Xoofff_FlagLastPart flag not set.
* @param flags Bitwise or combination of Xoofff_FlagNone, Xoofff_FlagInit, Xoofff_FlagLastPart.
* @return 0 if successful, 1 otherwise.
*/
int Xoofff_Compress(Xoofff_Instance *xpInstance, const BitSequence *input, BitLength inputBitLen, int flags);
/**
* Function to expand output data.
* @param xpInstance Pointer to the hash instance initialized by Xoofff_MaskDerivation().
* @param output Pointer to the buffer where to store the output data.
* @param outputBitLen The number of output bits desired.
* This must be a multiple of 8 if Xoofff_FlagLastPart flag not set.
* @param flags Bitwise or combination of Xoofff_FlagNone, Xoofff_FlagXoofffie, Xoofff_FlagLastPart.
* @return 0 if successful, 1 otherwise.
*/
int Xoofff_Expand(Xoofff_Instance *xpInstance, BitSequence *output, BitLength outputBitLen, int flags);
/** Function to compress input data and expand output data.
* @param xpInstance Pointer to the instance initialized by Xoofff_MaskDerivation().
* @param input Pointer to the input message (M).
* @param inputBitLen The number of bits provided in the input message data.
* @param output Pointer to the output buffer.
* @param outputBitLen The number of output bits desired.
* @param flags Bitwise or combination of Xoofff_FlagNone, Xoofff_FlagInit, Xoofff_FlagXoofffie, Xoofff_FlagLastPart.
* Xoofff_FlagLastPart is internally forced to true for input and output.
* @return 0 if successful, 1 otherwise.
*/
int Xoofff(Xoofff_Instance *xpInstance, const BitSequence *input, BitLength inputBitLen, BitSequence *output, BitLength outputBitLen, int flags);
#else
#error This requires an implementation of Xoodoo
#endif
#endif