-- S.MG implementation of Keccak-f permutations -- (Based on The Keccak Reference, Version 3.0, January 14, 2011, by -- Guido Bertoni, Joan Daemen, Michael Peeters and Gilles Van Assche) -- S.MG, 2018 package SMG_Keccak is pragma Pure(SMG_Keccak); --stateless, no side effects -> can cache calls --knobs (can change as per keccak design but fixed here for S.MG purposes)-- Keccak_L: constant := 6; --gives keccak z (word) dimension of 2^6=64 and --therefore keccak function 1600 with current --constants (5*5*2^6) --constants: dimensions of keccak state and number of rounds XY_Length: constant := 5; Z_Length: constant := 2**Keccak_L; Width: constant := XY_Length * XY_Length * Z_Length; N_Rounds: constant := 12 + 2*Keccak_L; --types type XYCoord is mod XY_Length; type ZCoord is mod Z_Length; type Round_Index is mod N_Rounds; type ZWord is mod 2**Z_Length; --"lane" in keccak ref type Plane is array(XYCoord) of ZWord; --a "horizontal slice" of keccak state type State is array(XYCoord, XYCoord) of ZWord; --the full keccak state type Round_Constants is array(Round_Index) of ZWord; --magic keccak constants private -- these are internals of the keccak implementation, not meant to be directly -- accessed/used --Keccak magic numbers RC : constant Round_Constants := ( 16#0000_0000_0000_0001#, 16#0000_0000_0000_8082#, 16#8000_0000_0000_808A#, 16#8000_0000_8000_8000#, 16#0000_0000_0000_808B#, 16#0000_0000_8000_0001#, 16#8000_0000_8000_8081#, 16#8000_0000_0000_8009#, 16#0000_0000_0000_008A#, 16#0000_0000_0000_0088#, 16#0000_0000_8000_8009#, 16#0000_0000_8000_000A#, 16#0000_0000_8000_808B#, 16#8000_0000_0000_008B#, 16#8000_0000_0000_8089#, 16#8000_0000_0000_8003#, 16#8000_0000_0000_8002#, 16#8000_0000_0000_0080#, 16#0000_0000_0000_800A#, 16#8000_0000_8000_000A#, 16#8000_0000_8000_8081#, 16#8000_0000_0000_8080#, 16#0000_0000_8000_0001#, 16#8000_0000_8000_8008# ); --gnat-specific methods to have bit-ops for modular types function Rotate_Left( Value : ZWord; Amount : Natural) return ZWord; pragma Import(Intrinsic, Rotate_Left); function Shift_Right( Value : ZWord; Amount : Natural) return ZWord; pragma Import(Intrinsic, Shift_Right); --Keccak permutations function Theta ( Input : in State) return State; function Rho ( Input : in State) return State; function Pi ( Input : in State) return State; function Chi ( Input : in State) return State; function Iota ( Round_Const : in ZWord; Input : in State) return State; --Keccak full function with block width currently 1600 (Width constant above) --this simply applies *all* keccak permutations in the correct order and using -- the keccak magic numbers (round constants) as per keccak reference function Keccak_Function(Input: in State) return State; end SMG_Keccak;