-
+ 1E1EAA78ECCAFFA4235EC739A63D20EE3F399BDD94386915B44CE58212032988CE67481EB2E558C846DFCDCDD8748BDA6E276D20512B487F5A3B86C44C946A40
eucrypt/smg_keccak/smg_keccak.ads
(0 . 0)(1 . 89)
117 -- S.MG implementation of Keccak-f permutations
118
119 -- (Based on The Keccak Reference, Version 3.0, January 14, 2011, by
120 -- Guido Bertoni, Joan Daemen, Michael Peeters and Gilles Van Assche)
121
122 -- S.MG, 2018
123
124 package SMG_Keccak is
125 pragma Pure(SMG_Keccak); --stateless, no side effects -> can cache calls
126
127 --knobs (can change as per keccak design but fixed here for S.MG purposes)--
128 Keccak_L: constant := 6; --gives keccak z (word) dimension of 2^6=64 and
129 --therefore keccak function 1600 with current
130 --constants (5*5*2^6)
131
132 --constants: dimensions of keccak state and number of rounds
133 XY_Length: constant := 5;
134 Z_Length: constant := 2**Keccak_L;
135 Width: constant := XY_Length * XY_Length * Z_Length;
136 N_Rounds: constant := 12 + 2*Keccak_L;
137
138 --types
139 type XYCoord is mod XY_Length;
140 type ZCoord is mod Z_Length;
141 type Round_Index is mod N_Rounds;
142
143 type ZWord is mod 2**Z_Length; --"lane" in keccak ref
144 type Plane is array(XYCoord) of ZWord; --a "horizontal slice" of keccak state
145 type State is array(XYCoord, XYCoord) of ZWord; --the full keccak state
146
147 type Round_Constants is array(Round_Index) of ZWord; --magic keccak constants
148
149 private
150 -- these are internals of the keccak implementation, not meant to be directly
151 -- accessed/used
152
153 --Keccak magic numbers
154 RC : constant Round_Constants :=
155 (
156 16#0000_0000_0000_0001#,
157 16#0000_0000_0000_8082#,
158 16#8000_0000_0000_808A#,
159 16#8000_0000_8000_8000#,
160 16#0000_0000_0000_808B#,
161 16#0000_0000_8000_0001#,
162 16#8000_0000_8000_8081#,
163 16#8000_0000_0000_8009#,
164 16#0000_0000_0000_008A#,
165 16#0000_0000_0000_0088#,
166 16#0000_0000_8000_8009#,
167 16#0000_0000_8000_000A#,
168 16#0000_0000_8000_808B#,
169 16#8000_0000_0000_008B#,
170 16#8000_0000_0000_8089#,
171 16#8000_0000_0000_8003#,
172 16#8000_0000_0000_8002#,
173 16#8000_0000_0000_0080#,
174 16#0000_0000_0000_800A#,
175 16#8000_0000_8000_000A#,
176 16#8000_0000_8000_8081#,
177 16#8000_0000_0000_8080#,
178 16#0000_0000_8000_0001#,
179 16#8000_0000_8000_8008#
180 );
181
182 --gnat-specific methods to have bit-ops for modular types
183 function Rotate_Left( Value : ZWord;
184 Amount : Natural)
185 return ZWord;
186 pragma Import(Intrinsic, Rotate_Left);
187
188 function Shift_Right( Value : ZWord;
189 Amount : Natural)
190 return ZWord;
191 pragma Import(Intrinsic, Shift_Right);
192
193 --Keccak permutations
194 function Theta ( Input : in State) return State;
195 function Rho ( Input : in State) return State;
196 function Pi ( Input : in State) return State;
197 function Chi ( Input : in State) return State;
198 function Iota ( Round_Const : in ZWord; Input : in State) return State;
199
200 --Keccak full function with block width currently 1600 (Width constant above)
201 --this simply applies *all* keccak permutations in the correct order and using
202 -- the keccak magic numbers (round constants) as per keccak reference
203 function Keccak_Function(Input: in State) return State;
204
205 end SMG_Keccak;