keccak 1
keccak 2
keccak 3
keccak 4
keccak 5
keccak 6
keccak 7
keccak 8 package SMG_Keccak is
keccak 9 pragma Pure(SMG_Keccak);
keccak 10
keccak 11
keccak 12 Keccak_L: constant := 6;
keccak 13
keccak 14
keccak 15
keccak 16 Default_Bitrate: constant := 1344;
keccak 17
keccak 18
keccak 19
keccak 20 XY_Length: constant := 5;
keccak 21 Z_Length: constant := 2**Keccak_L;
keccak 22 Width: constant := XY_Length * XY_Length * Z_Length;
keccak 23 N_Rounds: constant := 12 + 2*Keccak_L;
keccak 24
keccak 25
keccak 26 type XYCoord is mod XY_Length;
keccak 27 type ZCoord is mod Z_Length;
keccak 28 type Round_Index is mod N_Rounds;
keccak 29
keccak 30 type ZWord is mod 2**Z_Length;
keccak 31 type Plane is array(XYCoord) of ZWord;
keccak 32 type State is array(XYCoord, XYCoord) of ZWord;
keccak 33
keccak 34 type Round_Constants is array(Round_Index) of ZWord;
keccak 35
keccak 36
keccak 37
keccak 38
keccak 39 subtype Keccak_Rate is Positive range 1..Width;
keccak 40
keccak 41 type Bit is mod 2;
keccak 42 type Bitstream is array( Natural range <> ) of Bit;
keccak 43 subtype Bitword is Bitstream( 0..Z_Length - 1 );
keccak 44
keccak 45
keccak 46 function BitsToWord( BWord : in Bitword ) return ZWord;
keccak 47 function WordToBits( Word : in ZWord ) return Bitword;
keccak 48
keccak 49
keccak 50 function FlipOctets( BWord : in Bitword ) return Bitword;
keccak 51
keccak 52
keccak 53
keccak 54
keccak 55
keccak 56
keccak 57
keccak 58 procedure Sponge(Input : in Bitstream;
keccak 59 Output : out Bitstream;
keccak 60 Block_Len : in Keccak_Rate := Default_Bitrate );
keccak 61
vdiff_keccak 62
vdiff_keccak 63 type Keccak_Context (Block_Len: Keccak_Rate := Default_Bitrate) is
vdiff_keccak 64 record
vdiff_keccak 65 Internal: State := (others => (others => 0));
vdiff_keccak 66 Block: Bitstream(1..Block_Len) := (others => 0);
vdiff_keccak 67 Pos: Natural;
vdiff_keccak 68 end record;
vdiff_keccak 69
vdiff_keccak 70 procedure KeccakBegin(Ctx: in out Keccak_Context);
vdiff_keccak 71 procedure KeccakHash(Ctx: in out Keccak_Context;
vdiff_keccak 72 Input: Bitstream);
vdiff_keccak 73 procedure KeccakEnd(Ctx: in out Keccak_Context;
vdiff_keccak 74 Output: out Bitstream);
vdiff_keccak 75
keccak 76 private
keccak 77
keccak 78
keccak 79
keccak 80
keccak 81
keccak 82
keccak 83
keccak 84 procedure SqueezeBlock( Block: out Bitstream; S: in State);
keccak 85
keccak 86
keccak 87
keccak 88
keccak 89
keccak 90 procedure AbsorbBlock( Block: in Bitstream; S: in out State );
keccak 91
keccak 92
keccak 93 RC : constant Round_Constants :=
keccak 94 (
keccak 95 16#0000_0000_0000_0001#,
keccak 96 16#0000_0000_0000_8082#,
keccak 97 16#8000_0000_0000_808A#,
keccak 98 16#8000_0000_8000_8000#,
keccak 99 16#0000_0000_0000_808B#,
keccak 100 16#0000_0000_8000_0001#,
keccak 101 16#8000_0000_8000_8081#,
keccak 102 16#8000_0000_0000_8009#,
keccak 103 16#0000_0000_0000_008A#,
keccak 104 16#0000_0000_0000_0088#,
keccak 105 16#0000_0000_8000_8009#,
keccak 106 16#0000_0000_8000_000A#,
keccak 107 16#0000_0000_8000_808B#,
keccak 108 16#8000_0000_0000_008B#,
keccak 109 16#8000_0000_0000_8089#,
keccak 110 16#8000_0000_0000_8003#,
keccak 111 16#8000_0000_0000_8002#,
keccak 112 16#8000_0000_0000_0080#,
keccak 113 16#0000_0000_0000_800A#,
keccak 114 16#8000_0000_8000_000A#,
keccak 115 16#8000_0000_8000_8081#,
keccak 116 16#8000_0000_0000_8080#,
keccak 117 16#0000_0000_8000_0001#,
keccak 118 16#8000_0000_8000_8008#
keccak 119 );
keccak 120
keccak 121
keccak 122 function Rotate_Left( Value : ZWord;
keccak 123 Amount : Natural)
keccak 124 return ZWord;
keccak 125 pragma Import(Intrinsic, Rotate_Left);
keccak 126
keccak 127 function Shift_Right( Value : ZWord;
keccak 128 Amount : Natural)
keccak 129 return ZWord;
keccak 130 pragma Import(Intrinsic, Shift_Right);
keccak 131
keccak 132 function Shift_Left( Value : ZWord;
keccak 133 Amount : Natural)
keccak 134 return ZWord;
keccak 135 pragma Import(Intrinsic, Shift_Left);
keccak 136
keccak 137
keccak 138 function Theta ( Input : in State) return State;
keccak 139 function Rho ( Input : in State) return State;
keccak 140 function Pi ( Input : in State) return State;
keccak 141 function Chi ( Input : in State) return State;
keccak 142 function Iota ( Round_Const : in ZWord; Input : in State) return State;
keccak 143
keccak 144
keccak 145
keccak 146
keccak 147 function Keccak_Function(Input: in State) return State;
keccak 148
keccak 149 end SMG_Keccak;