Belle II Software
release-08-01-10
SnP-Relaned.h
1
/*
2
Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
3
Joan Daemen, Michaƫl Peeters, Gilles Van Assche and Ronny Van Keer, hereby
4
denoted as "the implementer".
5
6
For more information, feedback or questions, please refer to our websites:
7
http://keccak.noekeon.org/
8
http://keyak.noekeon.org/
9
http://ketje.noekeon.org/
10
11
To the extent possible under law, the implementer has waived all copyright
12
and related or neighboring rights to the source code in this file.
13
http://creativecommons.org/publicdomain/zero/1.0/
14
*/
15
16
#pragma once
17
18
#define SnP_AddBytes(state, data, offset, length, SnP_AddLanes, SnP_AddBytesInLane, SnP_laneLengthInBytes) \
19
{ \
20
if ((offset) == 0) { \
21
SnP_AddLanes(state, data, (length)/SnP_laneLengthInBytes); \
22
SnP_AddBytesInLane(state, \
23
(length)/SnP_laneLengthInBytes, \
24
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
25
0, \
26
(length)%SnP_laneLengthInBytes); \
27
} \
28
else { \
29
unsigned int _sizeLeft = (length); \
30
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
31
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
32
const unsigned char *_curData = (data); \
33
while(_sizeLeft > 0) { \
34
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
35
if (_bytesInLane > _sizeLeft) \
36
_bytesInLane = _sizeLeft; \
37
SnP_AddBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
38
_sizeLeft -= _bytesInLane; \
39
_lanePosition++; \
40
_offsetInLane = 0; \
41
_curData += _bytesInLane; \
42
} \
43
} \
44
}
45
46
#define SnP_OverwriteBytes(state, data, offset, length, SnP_OverwriteLanes, SnP_OverwriteBytesInLane, SnP_laneLengthInBytes) \
47
{ \
48
if ((offset) == 0) { \
49
SnP_OverwriteLanes(state, data, (length)/SnP_laneLengthInBytes); \
50
SnP_OverwriteBytesInLane(state, \
51
(length)/SnP_laneLengthInBytes, \
52
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
53
0, \
54
(length)%SnP_laneLengthInBytes); \
55
} \
56
else { \
57
unsigned int _sizeLeft = (length); \
58
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
59
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
60
const unsigned char *_curData = (data); \
61
while(_sizeLeft > 0) { \
62
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
63
if (_bytesInLane > _sizeLeft) \
64
_bytesInLane = _sizeLeft; \
65
SnP_OverwriteBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
66
_sizeLeft -= _bytesInLane; \
67
_lanePosition++; \
68
_offsetInLane = 0; \
69
_curData += _bytesInLane; \
70
} \
71
} \
72
}
73
74
#define SnP_ExtractBytes(state, data, offset, length, SnP_ExtractLanes, SnP_ExtractBytesInLane, SnP_laneLengthInBytes) \
75
{ \
76
if ((offset) == 0) { \
77
SnP_ExtractLanes(state, data, (length)/SnP_laneLengthInBytes); \
78
SnP_ExtractBytesInLane(state, \
79
(length)/SnP_laneLengthInBytes, \
80
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
81
0, \
82
(length)%SnP_laneLengthInBytes); \
83
} \
84
else { \
85
unsigned int _sizeLeft = (length); \
86
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
87
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
88
unsigned char *_curData = (data); \
89
while(_sizeLeft > 0) { \
90
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
91
if (_bytesInLane > _sizeLeft) \
92
_bytesInLane = _sizeLeft; \
93
SnP_ExtractBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
94
_sizeLeft -= _bytesInLane; \
95
_lanePosition++; \
96
_offsetInLane = 0; \
97
_curData += _bytesInLane; \
98
} \
99
} \
100
}
101
102
#define SnP_ExtractAndAddBytes(state, input, output, offset, length, SnP_ExtractAndAddLanes, SnP_ExtractAndAddBytesInLane, SnP_laneLengthInBytes) \
103
{ \
104
if ((offset) == 0) { \
105
SnP_ExtractAndAddLanes(state, input, output, (length)/SnP_laneLengthInBytes); \
106
SnP_ExtractAndAddBytesInLane(state, \
107
(length)/SnP_laneLengthInBytes, \
108
(input)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
109
(output)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
110
0, \
111
(length)%SnP_laneLengthInBytes); \
112
} \
113
else { \
114
unsigned int _sizeLeft = (length); \
115
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
116
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
117
const unsigned char *_curInput = (input); \
118
unsigned char *_curOutput = (output); \
119
while(_sizeLeft > 0) { \
120
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
121
if (_bytesInLane > _sizeLeft) \
122
_bytesInLane = _sizeLeft; \
123
SnP_ExtractAndAddBytesInLane(state, _lanePosition, _curInput, _curOutput, _offsetInLane, _bytesInLane); \
124
_sizeLeft -= _bytesInLane; \
125
_lanePosition++; \
126
_offsetInLane = 0; \
127
_curInput += _bytesInLane; \
128
_curOutput += _bytesInLane; \
129
} \
130
} \
131
}
132
133
framework
utilities
sha3hash
SnP-Relaned.h
Generated on Mon Sep 23 2024 14:02:34 for Belle II Software by
1.9.1