-
Notifications
You must be signed in to change notification settings - Fork 22
/
SnP-FBWL-default.c
96 lines (85 loc) · 3.76 KB
/
SnP-FBWL-default.c
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
/*
Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby
denoted as "the implementer".
For more information, feedback or questions, please refer to our websites:
http://keccak.noekeon.org/
http://keyak.noekeon.org/
http://ketje.noekeon.org/
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/
*/
#include <string.h>
#include "SnP-interface.h"
#ifdef KeccakReference
#include "displayIntermediateValues.h"
#endif
size_t SnP_FBWL_Absorb_Default(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen, unsigned char trailingBits)
{
size_t processed = 0;
while(dataByteLen >= laneCount*SnP_laneLengthInBytes) {
#ifdef KeccakReference
if (trailingBits == 0)
displayBytes(1, "Block to be absorbed", data, laneCount*SnP_laneLengthInBytes);
else {
displayBytes(1, "Block to be absorbed (part)", data, laneCount*SnP_laneLengthInBytes);
displayBytes(1, "Block to be absorbed (trailing bits)", &trailingBits, 1);
}
#endif
SnP_XORBytes(state, data, 0, laneCount*SnP_laneLengthInBytes);
SnP_XORBytes(state, &trailingBits, laneCount*SnP_laneLengthInBytes, 1);
SnP_Permute(state);
data += laneCount*SnP_laneLengthInBytes;
dataByteLen -= laneCount*SnP_laneLengthInBytes;
processed += laneCount*SnP_laneLengthInBytes;
}
return processed;
}
size_t SnP_FBWL_Squeeze_Default(void *state, unsigned int laneCount, unsigned char *data, size_t dataByteLen)
{
size_t processed = 0;
while(dataByteLen >= laneCount*SnP_laneLengthInBytes) {
SnP_Permute(state);
SnP_ExtractBytes(state, data, 0, laneCount*SnP_laneLengthInBytes);
#ifdef KeccakReference
displayBytes(1, "Squeezed block", data, laneCount*SnP_laneLengthInBytes);
#endif
data += laneCount*SnP_laneLengthInBytes;
dataByteLen -= laneCount*SnP_laneLengthInBytes;
processed += laneCount*SnP_laneLengthInBytes;
}
return processed;
}
size_t SnP_FBWL_Wrap_Default(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits)
{
size_t processed = 0;
while(dataByteLen >= laneCount*SnP_laneLengthInBytes) {
SnP_XORBytes(state, dataIn, 0, laneCount*SnP_laneLengthInBytes);
SnP_ExtractBytes(state, dataOut, 0, laneCount*SnP_laneLengthInBytes);
SnP_XORBytes(state, &trailingBits, laneCount*SnP_laneLengthInBytes, 1);
SnP_Permute(state);
dataIn += laneCount*SnP_laneLengthInBytes;
dataOut += laneCount*SnP_laneLengthInBytes;
dataByteLen -= laneCount*SnP_laneLengthInBytes;
processed += laneCount*SnP_laneLengthInBytes;
}
return processed;
}
size_t SnP_FBWL_Unwrap_Default(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits)
{
size_t processed = 0;
if (dataIn != dataOut)
memcpy(dataOut, dataIn, dataByteLen);
while(dataByteLen >= laneCount*SnP_laneLengthInBytes) {
SnP_ExtractAndXORBytes(state, dataOut, 0, laneCount*SnP_laneLengthInBytes);
SnP_XORBytes(state, dataOut, 0, laneCount*SnP_laneLengthInBytes);
SnP_XORBytes(state, &trailingBits, laneCount*SnP_laneLengthInBytes, 1);
SnP_Permute(state);
dataIn += laneCount*SnP_laneLengthInBytes;
dataOut += laneCount*SnP_laneLengthInBytes;
dataByteLen -= laneCount*SnP_laneLengthInBytes;
processed += laneCount*SnP_laneLengthInBytes;
}
return processed;
}