moving, renaming, ...

This commit is contained in:
bg nerilex 2015-08-19 06:57:55 +02:00
parent 5a5dd82907
commit 36aeee3bfb
27 changed files with 1293 additions and 529 deletions

View File

@ -124,21 +124,21 @@ package body AES is
end loop;
end Initialize_Generic;
procedure Initialize_priv is new Initialize_Generic(T_In => Key_128, T_Out => Context_128);
procedure Initialize_priv is new Initialize_Generic(T_In => Key_192, T_Out => Context_192);
procedure Initialize_priv is new Initialize_Generic(T_In => Key_256, T_Out => Context_256);
procedure Initialize_priv is new Initialize_Generic(T_In => Key_128_T, T_Out => Context_128_T);
procedure Initialize_priv is new Initialize_Generic(T_In => Key_192_T, T_Out => Context_192_T);
procedure Initialize_priv is new Initialize_Generic(T_In => Key_256_T, T_Out => Context_256_T);
procedure Initialize(Context : out Context_128; Key : in Key_128) is
procedure Initialize(Context : out Context_128_T; Key : in Key_128_T) is
begin
Initialize_priv(Key, Context);
end Initialize;
procedure Initialize(Context : out Context_192; Key : in Key_192) is
procedure Initialize(Context : out Context_192_T; Key : in Key_192_T) is
begin
Initialize_priv(Key, Context);
end Initialize;
procedure Initialize(Context : out Context_256; Key : in Key_256) is
procedure Initialize(Context : out Context_256_T; Key : in Key_256_T) is
begin
Initialize_priv(Key, Context);
end Initialize;
@ -206,7 +206,7 @@ package body AES is
end InvMixRows;
procedure Encrypt_Generic(Context : in Context_T; Block : in out Block_128_Bit) is
procedure Encrypt_Generic(Context : in Context_T; Block : in out Block_T) is
begin
-- Put("( 1) pre-add: "); print_hex(Block); New_Line;
Block := u8_Array(Block) xor u8_Array(Context.RoundKeys(Context.RoundKeys'First));
@ -225,23 +225,23 @@ package body AES is
Block := u8_Array(Block) xor u8_Array(Context.RoundKeys(Context.RoundKeys'Last));
end Encrypt_Generic;
procedure Encrypt(Context : in Context_128; Block: in out Block_128_Bit) is
procedure Encrypt(Context : in Context_128_T; Block: in out Block_T) is
begin
Encrypt_Generic(Context_T(Context), Block);
end Encrypt;
procedure Encrypt(Context : in Context_192; Block: in out Block_128_Bit) is
procedure Encrypt(Context : in Context_192_T; Block: in out Block_T) is
begin
Encrypt_Generic(Context_T(Context), Block);
end Encrypt;
procedure Encrypt(Context : in Context_256; Block: in out Block_128_Bit) is
procedure Encrypt(Context : in Context_256_T; Block: in out Block_T) is
begin
Encrypt_Generic(Context_T(Context), Block);
end Encrypt;
procedure Decrypt_Generic(Context : in Context_T; Block : in out Block_128_Bit) is
procedure Decrypt_Generic(Context : in Context_T; Block : in out Block_T) is
begin
-- Put("( 1) pre-add: "); print_hex(Block); New_Line;
Block := u8_Array(Block) xor u8_Array(Context.RoundKeys(Context.RoundKeys'Last));
@ -260,27 +260,19 @@ package body AES is
Block := u8_Array(Block) xor u8_Array(Context.RoundKeys(Context.RoundKeys'First));
end Decrypt_Generic;
procedure Decrypt(Context : in Context_128; Block: in out Block_128_Bit) is
procedure Decrypt(Context : in Context_128_T; Block: in out Block_T) is
begin
Decrypt_Generic(Context_T(Context), Block);
end Decrypt;
procedure Decrypt(Context : in Context_192; Block: in out Block_128_Bit) is
procedure Decrypt(Context : in Context_192_T; Block: in out Block_T) is
begin
Decrypt_Generic(Context_T(Context), Block);
end Decrypt;
procedure Decrypt(Context : in Context_256; Block: in out Block_128_Bit) is
procedure Decrypt(Context : in Context_256_T; Block: in out Block_T) is
begin
Decrypt_Generic(Context_T(Context), Block);
end Decrypt;
-- function Encrypt(Ctx : Context_128; Source : Plaintext) return Ciphertext;
-- function Decrypt(Ctx : Context_128; Source : Ciphertext) return Plaintext;
--
-- function Encrypt(Ctx : Context_192; Source : Plaintext) return Ciphertext;
-- function Decrypt(Ctx : Context_192; Source : Ciphertext) return Plaintext;
--
-- function Encrypt(Ctx : Context_256; Source : Plaintext) return Ciphertext;
-- function Decrypt(Ctx : Context_256; Source : Ciphertext) return Plaintext;
end AES;

View File

@ -20,35 +20,32 @@ use Crypto_Types.Crypto_Types_u8;
package AES is
type Key_128 is new Block_128_Bit;
type Key_192 is new Block_192_Bit;
type Key_256 is new Block_256_Bit;
subtype Key_128_T is Block_128_Bit;
subtype Key_192_T is Block_192_Bit;
subtype Key_256_T is Block_256_Bit;
type Context_128 is private;
type Context_192 is private;
type Context_256 is private;
type Context_128_T is private;
type Context_192_T is private;
type Context_256_T is private;
type Plaintext is new Block_128_Bit;
type Ciphertext is new Block_128_Bit;
subtype Block_T is Block_128_Bit;
procedure Initialize(Context : out Context_128_T; Key : in Key_128_T);
procedure Encrypt(Context : in Context_128_T; Block: in out Block_T);
procedure Decrypt(Context : in Context_128_T; Block: in out Block_T);
procedure Initialize(Context : out Context_192_T; Key : in Key_192_T);
procedure Encrypt(Context : in Context_192_T; Block: in out Block_T);
procedure Decrypt(Context : in Context_192_T; Block: in out Block_T);
procedure Initialize(Context : out Context_128; Key : in Key_128);
procedure Encrypt(Context : in Context_128; Block: in out Block_128_Bit);
procedure Decrypt(Context : in Context_128; Block: in out Block_128_Bit);
procedure Initialize(Context : out Context_192; Key : in Key_192);
procedure Encrypt(Context : in Context_192; Block: in out Block_128_Bit);
procedure Decrypt(Context : in Context_192; Block: in out Block_128_Bit);
procedure Initialize(Context : out Context_256; Key : in Key_256);
procedure Encrypt(Context : in Context_256; Block: in out Block_128_Bit);
procedure Decrypt(Context : in Context_256; Block: in out Block_128_Bit);
procedure Initialize(Context : out Context_256_T; Key : in Key_256_T);
procedure Encrypt(Context : in Context_256_T; Block: in out Block_T);
procedure Decrypt(Context : in Context_256_T; Block: in out Block_T);
private
type RoundKey_T is new Block_128_Bit;
subtype RoundKey_T is Block_128_Bit;
type RoundKeys_T is Array (Integer range <>) of RoundKey_T;
subtype Num_RoundKeys_T is Integer range 11 .. 15;
@ -57,9 +54,9 @@ private
RoundKeys : RoundKeys_T(1 .. Num_RoundKeys);
end record;
type Context_128 is new Context_T(11);
type Context_192 is new Context_T(13);
type Context_256 is new Context_T(15);
type Context_128_T is new Context_T(11);
type Context_192_T is new Context_T(13);
type Context_256_T is new Context_T(15);
Nb : constant Integer := 4;
polynom : constant u8 := 16#1B#;

View File

@ -24,11 +24,11 @@ package SHA2_224 is
type Context_T is private;
BlockSize_Bits : constant := 512;
DigestSize_Bits : constant := 224;
Block_Size_Bits : constant := 512;
Digest_Size_Bits : constant := 224;
BlockSize_Bytes : constant := (BlockSize_Bits) / 8;
DigestSize_Bytes : constant := (DigestSize_Bits) / 8;
Block_Size_Bytes : constant := (Block_Size_Bits) / 8;
Digest_Size_Bytes : constant := (Digest_Size_Bits) / 8;
procedure Initialize(Context : out Context_T);
procedure Next_Block(Context : in out Context_T; Block : in Block_512_Bit);

View File

@ -24,14 +24,14 @@ package SHA2_256 is
type Context_T is private;
BlockSize_Bits : constant := 512;
DigestSize_Bits : constant := 256;
Block_Size_Bits : constant := 512;
Digest_Size_Bits : constant := 256;
BlockSize_Bytes : constant := (BlockSize_Bits) / 8;
DigestSize_Bytes : constant := (DigestSize_Bits) / 8;
Block_Size_Bytes : constant := (Block_Size_Bits) / 8;
Digest_Size_Bytes : constant := (Digest_Size_Bits) / 8;
subtype Block_T is u8_Array(1 .. BlockSize_Bytes);
subtype Digest_T is u8_Array(1 .. DigestSize_Bytes);
subtype Block_T is u8_Array(1 .. Block_Size_Bytes);
subtype Digest_T is u8_Array(1 .. Digest_Size_Bytes);
procedure Initialize(Context : out Context_T);
procedure Next_Block(Context : in out Context_T; Block : in Block_T);

View File

@ -24,11 +24,11 @@ package SHA2_384 is
type Context_T is private;
BlockSize_Bits : constant := 1024;
DigestSize_Bits : constant := 384;
Block_Size_Bits : constant := 1024;
Digest_Size_Bits : constant := 384;
BlockSize_Bytes : constant := (BlockSize_Bits) / 8;
DigestSize_Bytes : constant := (DigestSize_Bits) / 8;
Block_Size_Bytes : constant := (Block_Size_Bits) / 8;
Digest_Size_Bytes : constant := (Digest_Size_Bits) / 8;
procedure Initialize(Context : out Context_T);
procedure Next_Block(Context : in out Context_T; Block : in Block_1024_Bit);

View File

@ -24,11 +24,11 @@ package SHA2_512 is
type Context_T is private;
BlockSize_Bits : constant := 1024;
DigestSize_Bits : constant := 512;
Block_Size_Bits : constant := 1024;
Digest_Size_Bits : constant := 512;
BlockSize_Bytes : constant := (BlockSize_Bits) / 8;
DigestSize_Bytes : constant := (DigestSize_Bits) / 8;
Block_Size_Bytes : constant := (Block_Size_Bits) / 8;
Digest_Size_Bytes : constant := (Digest_Size_Bits) / 8;
procedure Initialize(Context : out Context_T);
procedure Next_Block(Context : in out Context_T; Block : in Block_1024_Bit);

View File

@ -30,13 +30,13 @@ package Sha3_Generic is
type Context_T is private;
BlockSize_Bits : constant Natural := b - Capacity_Bits;
DigestSize_Bits : constant Natural := Capacity_Bits / 2;
BlockSize_Bytes : constant Natural := BlockSize_Bits / 8;
DigestSize_Bytes : constant Natural := DigestSize_Bits / 8;
Block_Size_Bits : constant Natural := b - Capacity_Bits;
Digest_Size_Bits : constant Natural := Capacity_Bits / 2;
Block_Size_Bytes : constant Natural := Block_Size_Bits / 8;
Digest_Size_Bytes : constant Natural := Digest_Size_Bits / 8;
subtype Block_T is u8_Array(1 .. BlockSize_Bytes);
subtype Digest_T is u8_Array(1 .. DigestSize_Bytes);
subtype Block_T is u8_Array(1 .. Block_Size_Bytes);
subtype Digest_T is u8_Array(1 .. Digest_Size_Bytes);
procedure Initialize(Context : out Context_T);
procedure Next_Block(Context : in out Context_T; Block : in Block_T);

View File

@ -13,29 +13,42 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
package body Crypto_Core_Types is
function To_Hex(A : u8) return String is
function To_Hex(A : u8; Upper_Case : Boolean := false) return String is
S : String(1 .. 2);
Hex_Table : constant array (0 .. 15) of Character :=
Hex_Table_L : constant array (0 .. 15) of Character :=
( '0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
'c', 'd', 'e', 'f');
Hex_Table_U : constant array (0 .. 15) of Character :=
( '0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F');
begin
S(1) := Hex_Table(Integer(Shift_Right(A, 4)));
S(2) := Hex_Table(Integer(A and 16#0f#));
if Upper_Case then
S(1) := Hex_Table_U(Integer(Shift_Right(A, 4)));
S(2) := Hex_Table_U(Integer(A and 16#0f#));
else
S(1) := Hex_Table_L(Integer(Shift_Right(A, 4)));
S(2) := Hex_Table_L(Integer(A and 16#0f#));
end if;
return S;
end To_Hex;
function To_Hex(A : u8_Array) return String is
S : String(1 .. A'Length * 2);
function To_Hex(A : u8_Array; Upper_Case : Boolean := false; Spacing : Natural := 0) return String is
S : String(1 .. A'Length * (2 + Spacing));
k : Positive := 1;
begin
for i in A'Range loop
S(k .. k + 1) := To_Hex(A(i));
k := k + 2;
S(k .. k + 1) := To_Hex(A(i), Upper_Case);
S(k + 2 .. k + 1 + Spacing) := Spacing * ' ';
k := k + 2 + Spacing;
end loop;
return S;
end To_Hex;
@ -111,35 +124,35 @@ package body Crypto_Core_Types is
return A;
end From_Ascii;
procedure Bit_Clear(Buffer : in out u8_Array; Index : in Positive) is
begin
Buffer(Buffer'First + Integer(Index / 8)) := Buffer(Buffer'First + Integer(Index / 8)) and (not Shift_Left(1, 7 - (Index - 1) mod 8));
end Bit_Clear;
procedure Bit_Set(Buffer : in out u8_Array; Index : in Positive) is
begin
Buffer(Integer(Buffer'First + Index / 8)) := Buffer(Buffer'First + Integer(Index / 8)) or Shift_Left(1, 7 - (Index - 1) mod 8);
end Bit_Set;
procedure Bit_Toggle(Buffer : in out u8_Array; Index : in Positive) is
begin
Buffer(Integer(Buffer'First + Index / 8)) := Buffer(Buffer'First + Integer(Index / 8)) xor Shift_Left(1, 7 - (Index - 1) mod 8);
end Bit_Toggle;
procedure Bit_Set(Buffer : in out u8_Array; Index : in Positive; Value : in Bit) is
begin
if Value = 1 then
Bit_Set(Buffer, Index);
else
Bit_Clear(Buffer, Index);
end if;
end Bit_Set;
function Bit_Get(Buffer : in u8_Array; Index : in Positive) return Bit is
begin
return Bit(Shift_Right(Buffer(Buffer'First + Index / 8), 7 - (Index - 1) mod 8) and 1);
end Bit_Get;
-- procedure Bit_Clear(Buffer : in out u8_Array; Index : in Positive) is
-- begin
-- Buffer(Buffer'First + Integer(Index / 8)) := Buffer(Buffer'First + Integer(Index / 8)) and (not Shift_Left(1, 7 - (Index - 1) mod 8));
-- end Bit_Clear;
--
-- procedure Bit_Set(Buffer : in out u8_Array; Index : in Positive) is
-- begin
-- Buffer(Integer(Buffer'First + Index / 8)) := Buffer(Buffer'First + Integer(Index / 8)) or Shift_Left(1, 7 - (Index - 1) mod 8);
-- end Bit_Set;
--
-- procedure Bit_Toggle(Buffer : in out u8_Array; Index : in Positive) is
-- begin
-- Buffer(Integer(Buffer'First + Index / 8)) := Buffer(Buffer'First + Integer(Index / 8)) xor Shift_Left(1, 7 - (Index - 1) mod 8);
-- end Bit_Toggle;
--
--
-- procedure Bit_Set(Buffer : in out u8_Array; Index : in Positive; Value : in Bit) is
-- begin
-- if Value = 1 then
-- Bit_Set(Buffer, Index);
-- else
-- Bit_Clear(Buffer, Index);
-- end if;
-- end Bit_Set;
--
-- function Bit_Get(Buffer : in u8_Array; Index : in Positive) return Bit is
-- begin
-- return Bit(Shift_Right(Buffer(Buffer'First + Index / 8), 7 - (Index - 1) mod 8) and 1);
-- end Bit_Get;
end Crypto_Core_types;

View File

@ -64,16 +64,11 @@ package Crypto_Core_Types is
Wrong_Opertaion_Order : exception;
Format_Violation : exception;
Invalid_Key_Size : exception;
function To_Hex(A : u8) return String;
function To_Hex(A : u8_Array) return String;
function To_Hex(A : u8; Upper_Case : Boolean := false) return String;
function To_Hex(A : u8_Array; Upper_Case : Boolean := false; Spacing : Natural := 0) return String;
function From_Hex(S : String) return u8_Array;
function From_Ascii(S : String) return u8_Array;
procedure Bit_Clear(Buffer : in out u8_Array; Index : in Positive);
procedure Bit_Set(Buffer : in out u8_Array; Index : in Positive);
procedure Bit_Set(Buffer : in out u8_Array; Index : in Positive; Value : in Bit);
procedure Bit_Toggle(Buffer : in out u8_Array; Index : in Positive);
function Bit_Get(Buffer : in u8_Array; Index : in Positive) return Bit;
end Crypto_Core_Types;

View File

@ -566,6 +566,80 @@ package body Crypto_Generic_Types is
end loop;
end Store_LE;
--
function Bit_Get(A : in T; Bit_Address : Bit_Address_T; Order : in System.Bit_order := System.Default_Bit_Order) return Bit is
use System;
Temp : T;
begin
if Order = High_Order_First then
Temp := Shift_Right(A, T'Size - Bit_Address - 1);
else
Temp := Shift_Right(A, Bit_Address);
end if;
return Bit(Temp and 1);
end Bit_Get;
--
procedure Bit_Clear(A : in out T; Bit_Address : Bit_Address_T; Order : in System.Bit_order := System.Default_Bit_Order) is
use System;
begin
if Order = High_Order_First then
A := A and not Shift_Left(1, T'Size - Bit_Address - 1);
else
A := A and not Shift_Left(1, Bit_Address);
end if;
end Bit_Clear;
--
procedure Bit_Set(A : in out T; Bit_Address : Bit_Address_T; Value : Bit := 1; Order : in System.Bit_order := System.Default_Bit_Order) is
use System;
begin
if Value = 0 then
Bit_Clear(A => A, Bit_Address => Bit_Address, Order => Order);
else
if Order = High_Order_First then
A := A or Shift_Left(1, T'Size - Bit_Address - 1);
else
A := A or Shift_Left(1, Bit_Address);
end if;
end if;
end Bit_Set;
--
procedure Bit_Toggle(A : in out T; Bit_Address : Bit_Address_T; Order : in System.Bit_order := System.Default_Bit_Order) is
use System;
begin
if Order = High_Order_First then
A := A xor Shift_Left(1, T'Size - Bit_Address - 1);
else
A := A xor Shift_Left(1, Bit_Address);
end if;
end Bit_Toggle;
--
function Bit_Get(A : in T_Array; Bit_Address : Natural; Order : in System.Bit_order := System.Default_Bit_Order) return Bit is
begin
return Bit_Get(A => A(A'First + Bit_Address / T'Size), Bit_Address => Bit_Address mod T'Size, Order => Order);
end Bit_Get;
--
procedure Bit_Clear(A : in out T_Array; Bit_Address : Natural; Order : in System.Bit_order := System.Default_Bit_Order) is
begin
Bit_Clear(A => A(A'First + Bit_Address / T'Size), Bit_Address => Bit_Address mod T'Size, Order => Order);
end Bit_Clear;
--
procedure Bit_Set(A : in out T_Array; Bit_Address : Natural; Value : Bit := 1; Order : in System.Bit_order := System.Default_Bit_Order) is
begin
Bit_Set(A => A(A'First + Bit_Address / T'Size), Bit_Address => Bit_Address mod T'Size, Value => Value, Order => Order);
end Bit_Set;
--
procedure Bit_Toggle(A : in out T_Array; Bit_Address : Natural; Order : in System.Bit_order := System.Default_Bit_Order) is
begin
Bit_Set(A => A(A'First + Bit_Address / T'Size), Bit_Address => Bit_Address mod T'Size, Order => Order);
end Bit_Toggle;
-- swap two elements
procedure Swap(A, B : in out T) is
temp : T;
@ -575,5 +649,17 @@ package body Crypto_Generic_Types is
b := temp;
end swap;
-- swap two Arrays
procedure Swap(A, B : in out T_Array) is
begin
if A'Length /= B'Length then
raise Constraint_Error;
end if;
A := A xor B;
B := B xor A;
A := A xor B;
end;
end Crypto_Generic_Types;

View File

@ -14,6 +14,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Crypto_Core_Types; use Crypto_Core_Types;
with System;
-- --------------------------
-- - Generic Functions / Procedures -
@ -47,68 +48,128 @@ generic
-- --------------------------
package Crypto_Generic_Types is
subtype Bit_Address_T is Natural range 0 .. T'Size - 1;
Bytes : constant Positive := T'Size / 8;
-- compare two array with timing independent of content
-- function "="(Left, Right : T_Array ) return Boolean;
-- xor each element on the left with the corresponding element on the right
function "xor"(Left, Right : T_Array ) return T_Array;
-- xor the left element with each element on the right
function "xor"(Left : T; Right : T_Array ) return T;
-- xor each element on the left with the element on the right
function "xor"(Left : T_Array; Right : T ) return T_Array;
-- and each element on the left with the corresponding element on the right
function "and"(Left, Right : T_Array ) return T_Array;
-- and the left element with each element on the right
function "and"(Left : T; Right : T_Array ) return T;
-- and each element on the left with the element on the right
function "and"(Left : T_Array; Right : T ) return T_Array;
-- or each element on the left with the corresponding element on the right
function "or"(Left, Right : T_Array ) return T_Array;
-- or the left element with each element on the right
function "or"(Left : T; Right : T_Array ) return T;
-- or each element on the left with the element on the right
function "or"(Left : T_Array; Right : T ) return T_Array;
-- add each element on the left with the corresponding element on the right
function "+"(Left, Right : T_Array ) return T_Array;
-- add the left element with each element on the right
function "+"(Left : T; Right : T_Array ) return T;
-- add each element on the left with the element on the right
function "+"(Left : T_Array; Right : T ) return T_Array;
-- subtract from each element on the left the corresponding element on the right
function "-"(Left, Right : T_Array ) return T_Array;
-- subtract from the left element each element on the right
function "-"(Left : T; Right : T_Array ) return T;
-- subtract from each element on the left the element on the right
function "-"(Left : T_Array; Right : T ) return T_Array;
-- rotate the whole Array as continues big-endian integer; positive Amount rotates left (towards lower address)
function Rotate_be(A : T_Array; Amount : Integer) return T_Array;
-- rotate the whole Array as continues little-endian integer; positive Amount rotates left (towards higher address)
function Rotate_le(A : T_Array; Amount : Integer) return T_Array;
-- rotate each element by Amount to the left; negative values for Amount rotate to the right
function Rotate_each(A : T_Array; Amount : Integer) return T_Array;
-- shift the whole Array as continues big-endian integer; positive Amount shifts left (towards lower address)
function Shift_be(A : T_Array; Amount : Integer) return T_Array;
-- Shift the whole Array as continues little-endian integer; positive Amount shifts left (towards higher address)
function Shift_le(A : T_Array; Amount : Integer) return T_Array;
-- shift each element by Amount to the left; negative values for Amount shift to the right
function Shift_each(A : T_Array; Amount : Integer) return T_Array;
-- load a value which is stored big-endian in byte Array
function Load_be (A : u8_Array) return T;
-- XXX store a value in big-endian format in a byte Array
function Load_be (A : u8_Array) return T_Array;
-- load a value which is stored little-endian in byte Array
function Load_le(A : u8_Array) return T;
-- XXX load a value which is stored little-endian in byte Array
function Load_le(A : u8_Array) return T_Array;
-- store a value in big-endian format in a byte Array
procedure Store_be(A : out u8_Array; value : in T);
-- store a value in little-endian format in a byte Array
procedure Store_le(A : out u8_Array; value : in T);
-- store a value in big-endian format in a byte Array
procedure Store_be(A : out u8_Array; value : in T_Array);
-- store a value in little-endian format in a byte Array
procedure Store_le(A : out u8_Array; value : in T_Array);
--
function Bit_Get(A : in T; Bit_Address : Bit_Address_T; Order : in System.Bit_order := System.Default_Bit_Order) return Bit;
--
procedure Bit_Clear(A : in out T; Bit_Address : Bit_Address_T; Order : in System.Bit_order := System.Default_Bit_Order);
--
procedure Bit_Set(A : in out T; Bit_Address : Bit_Address_T; Value : Bit := 1; Order : in System.Bit_order := System.Default_Bit_Order);
--
procedure Bit_Toggle(A : in out T; Bit_Address : Bit_Address_T; Order : in System.Bit_order := System.Default_Bit_Order);
--
function Bit_Get(A : in T_Array; Bit_Address : Natural; Order : in System.Bit_order := System.Default_Bit_Order) return Bit;
--
procedure Bit_Clear(A : in out T_Array; Bit_Address : Natural; Order : in System.Bit_order := System.Default_Bit_Order);
--
procedure Bit_Set(A : in out T_Array; Bit_Address : Natural; Value : Bit := 1; Order : in System.Bit_order := System.Default_Bit_Order);
--
procedure Bit_Toggle(A : in out T_Array; Bit_Address : Natural; Order : in System.Bit_order := System.Default_Bit_Order);
-- swap two elements
procedure Swap(A, B : in out T);
-- swap two Arrays
procedure Swap(A, B : in out T_Array);
end Crypto_Generic_Types;

View File

@ -21,17 +21,17 @@ with Ada.Sequential_IO;
package Crypto_Types is
package Crypto_Types_u8 is new Crypto_Generic_Types(T => u8, T_Array => u8_Array, T_Array_Access => u8_Array_Access);
package Crypto_Types_u8 is new Crypto_Generic_Types(T => u8, T_Array => u8_Array, T_Array_Access => u8_Array_Access);
package Crypto_Types_u16 is new Crypto_Generic_Types(T => u16, T_Array => u16_Array, T_Array_Access => u16_Array_Access);
package Crypto_Types_u32 is new Crypto_Generic_Types(T => u32, T_Array => u32_Array, T_Array_Access => u32_Array_Access);
package Crypto_Types_u64 is new Crypto_Generic_Types(T => u64, T_Array => u64_Array, T_Array_Access => u64_Array_Access);
package u8_Direct_IO is new Ada.Direct_IO(u8);
package u8_Direct_IO is new Ada.Direct_IO( u8);
package u16_Direct_IO is new Ada.Direct_IO(u16);
package u32_Direct_IO is new Ada.Direct_IO(u32);
package u64_Direct_IO is new Ada.Direct_IO(u64);
package u8_Sequential_IO is new Ada.Sequential_IO(u8);
package u8_Sequential_IO is new Ada.Sequential_IO( u8);
package u16_Sequential_IO is new Ada.Sequential_IO(u16);
package u32_Sequential_IO is new Ada.Sequential_IO(u32);
package u64_Sequential_IO is new Ada.Sequential_IO(u64);

View File

@ -83,11 +83,11 @@ procedure main is
end test_spritz_hash;
procedure test_aes is
key : AES.Key_256;
block : Block_128_bit;
ctx128 : AES.Context_128;
ctx192 : AES.Context_192;
ctx256 : AES.Context_256;
key : AES.Key_256_T;
block : AES.Block_T;
ctx128 : AES.Context_128_T;
ctx192 : AES.Context_192_T;
ctx256 : AES.Context_256_T;
begin
for i in key'Range loop
key(i) := u8(i - 1);
@ -96,13 +96,13 @@ procedure main is
for i in block'First + 1 .. block'Last loop
block(i) := u8(block(i - 1) + 16#11#);
end loop;
AES.Initialize(ctx128, AES.Key_128(key(1 .. 16)));
AES.Initialize(ctx128, key(1 .. 16));
AES.Encrypt(ctx128, block);
print_hex(block); New_Line;
AES.Decrypt(ctx128, block);
print_hex(block); New_Line;
AES.Initialize(ctx192, AES.Key_192(key(1 .. 24)));
AES.Initialize(ctx192, key(1 .. 24));
AES.Encrypt(ctx192, block);
print_hex(block); New_Line;
AES.Decrypt(ctx192, block);
@ -205,9 +205,9 @@ begin
test_spritz_hash("arcfour");
New_Line;
Put_Line("AES.Context_128'Size: " & Integer'Image(AES.Context_128'Size / 8));
Put_Line("AES.Context_192'Size: " & Integer'Image(AES.Context_192'Size / 8));
Put_Line("AES.Context_256'Size: " & Integer'Image(AES.Context_256'Size / 8));
Put_Line("AES.Context_128'Size: " & Integer'Image(AES.Context_128_T'Size / 8));
Put_Line("AES.Context_192'Size: " & Integer'Image(AES.Context_192_T'Size / 8));
Put_Line("AES.Context_256'Size: " & Integer'Image(AES.Context_256_T'Size / 8));
test_aes;
New_Line;

View File

@ -0,0 +1,322 @@
-- Copyright (C) 2015 Daniel Otte <bg@nerilex.org>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
-- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Crypto_Types; use Crypto_Types;
with System; use System;
use Crypto_Types.Crypto_Types_u8;
-- ********************************************************************************
-- *Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
-- ********************************************************************************
--
-- Primitive Name: Des
-- ===================
-- Key size: 64 bits
-- Block size: 64 bits
--
-- Test vectors -- set 1
-- =====================
--
-- Set 1, vector# 0:
-- key=8000000000000000
-- Plain=0000000000000000
-- cipher=95A8D72813DAA94D
-- decrypted=0000000000000000
-- Iterated 100 times=F749E1F8DEFAF605
-- Iterated 1000 times=F396DD0B33D04244
--
-- Set 1, vector# 1:
-- key=4000000000000000
-- plain=0000000000000000
-- cipher=0EEC1487DD8C26D5
-- decrypted=0000000000000000
-- Iterated 100 times=E5BEE86B600F3B48
-- Iterated 1000 times=1D5931D700EF4E15
package body Nessie_BC_Test_Generator is
Total_Number_Of_Encrypts : constant Natural :=
(Key_Size_Bits + Block_Size_Bits + 256 + 2) * (1 + 1000 + 1);
Total_Number_Of_Decrypts : constant Natural :=
(Key_Size_Bits + Block_Size_Bits + 256 + 2) * (1 + 1000 + 1);
Total_Number_Of_Primitive_Runs : constant Natural :=
Total_Number_Of_Encrypts + Total_Number_Of_Decrypts;
Primitive_Runs_Per_Encrypt_Test : constant := 2002;
Primitive_Runs_Per_Decrypt_Test : constant := 2;
Step : Natural;
Kasumi_Test_Key : constant u8_Array(1 .. 16) :=
(
16#2B#, 16#D6#, 16#45#, 16#9F#, 16#82#, 16#C5#, 16#B3#, 16#00#,
16#95#, 16#2C#, 16#49#, 16#10#, 16#48#, 16#81#, 16#FF#, 16#48#
);
Kasumi_Test_Plain : constant u8_Array(1 .. 8) :=
(
16#EA#, 16#02#, 16#47#, 16#14#, 16#AD#, 16#5C#, 16#4D#, 16#84#
);
procedure Print_Header is
begin
Put_Line("********************************************************************************");
Put_Line("* SteelCrypt - NESSIE TestVectors *");
Put_Line("********************************************************************************");
New_Line;
Put_Line("Primitive Name: " & Name);
Put_Line((16 + Name'Length) * '=');
Put_Line("Key size:" & Integer'Image(Key_Size_Bits) & " bits");
Put_Line("Block size:" & Integer'Image(Block_Size_Bits) & " bits");
New_Line;
end Print_Header;
procedure Print_Set_Header(Set_No : in Positive) is
begin
Put_Line("Test vectors -- set" & Integer'Image(Set_No));
Put_Line("=====================");
New_Line;
end Print_Set_Header;
procedure Print_Vector_Header(Set_No : in Positive; Vector_No : in Natural) is
Vector_No_Str : constant String := Trim(Source => Integer'Image(Vector_No), Side => Both);
begin
Put("Set" & Integer'Image(Set_No) &", vector#");
Put((3 - Vector_No_Str'Length) * ' ');
Put_Line(Vector_No_Str & ":");
end Print_Vector_Header;
procedure Print_Item(Tag : in String; Block : in u8_Array) is
Split : constant Boolean := Block'Length > 24;
j : Integer := Block'First;
begin
if Tag'Length < 30 then
Put((30 - Tag'Length) * ' ');
end if;
if Split then
Put_Line(Tag & "=" & To_Hex(A => Block(j .. j + 15), Upper_Case => True));
j := j + 16;
while j + 16 < Block'Last loop
Put_Line(31 * ' ' & To_Hex(A => Block(j .. j + 15), Upper_Case => True));
j := j + 16;
end loop;
if j <= Block'Last then
Put_Line(31 * ' ' & To_Hex(A => Block(j .. Block'Last), Upper_Case => True));
end if;
else
Put_Line(Tag & "=" & To_Hex(A => Block, Upper_Case => True));
end if;
end Print_Item;
procedure Run_Encrypt_Test(Key : in Key_T; Block : in Block_T) is
Temp : Block_T := Block;
Context : Context_T;
begin
Print_Item("key", Key);
Print_Item("plain", Temp);
Initialize(Context, Key);
Encrypt(Context, Temp);
Print_Item("cipher", Temp);
Decrypt(Context, Temp);
Print_Item("decrypted", Temp);
if Temp /= Block then
Put_Line("!!! decrypted /= plain");
end if;
for i in 1 .. 100 loop
Encrypt(Context, Temp);
end loop;
Print_Item("Iterated 100 times", Temp);
for i in 101 .. 1000 loop
Encrypt(Context, Temp);
end loop;
Print_Item("Iterated 1000 times", Temp);
for i in 1 .. 1000 loop
Decrypt(Context, Temp);
end loop;
if Temp /= Block then
Put_Line("!!! decrypted /= plain");
end if;
end Run_Encrypt_Test;
procedure Run_Decrypt_Test(Key : in Key_T; Block : in Block_T) is
Temp : Block_T := Block;
Context : Context_T;
begin
Print_Item("key", Key);
Print_Item("cipher", Temp);
Initialize(Context, Key);
Decrypt(Context, Temp);
Print_Item("plain", Temp);
Encrypt(Context, Temp);
Print_Item("encrypted", Temp);
if Temp /= Block then
Put_Line("!!! encrypted /= plain");
end if;
end Run_Decrypt_Test;
procedure Initialize_Display is
begin
Step := 0;
if Verbose then
New_Line(File => Standard_Error);
end if;
end Initialize_Display;
procedure Update_Display is
begin
if Verbose then
-- Set_Col(File => Standard_Error, To => 1);
Put(File => Standard_Error,
Item => Character'Val(13) & " ==> " & Name & ": ");
-- Put(File => Standard_Error, Item => Float'Image(100.0 * Float(Step) / Float(Total_Number_Of_Primitive_Runs)) & "%");
Put(File => Standard_Error,
Item => 100.0 * Float(Step) / Float(Total_Number_Of_Primitive_Runs),
Fore => 3,
Aft => 2,
Exp => 0 );
Put(File => Standard_Error,
Item => '%' );
end if;
end Update_Display;
procedure Run_Test(Key : in Key_T; Block : in Block_T; Encrypt_Test : in Boolean := True) is
begin
if Encrypt_Test then
Run_Encrypt_Test(Key, Block);
Step := Step + Primitive_Runs_Per_Encrypt_Test;
else
Run_Decrypt_Test(Key, Block);
Step := Step + Primitive_Runs_Per_Decrypt_Test;
end if;
Update_Display;
end Run_Test;
procedure Set_1(Set_No : in Positive; Encrypt_Test : in Boolean := True) is
Key : Key_T;
Block : constant Block_T := (others => 0);
begin
Print_Set_Header(Set_No);
for i in 0 .. Key_Size_Bits - 1 loop
Print_Vector_Header(Set_No, i);
Key := (others => 0);
Bit_Set(A => Key, Bit_Address => i, Value => 1, Order => High_Order_First);
Run_Test(Key, Block, Encrypt_Test);
New_Line;
end loop;
end Set_1;
procedure Set_2(Set_No : in Positive; Encrypt_Test : in Boolean := True) is
Key : constant Key_T := (others => 0);
Block : Block_T;
begin
Print_Set_Header(Set_No);
for i in 0 .. Block_Size_Bits - 1 loop
Print_Vector_Header(Set_No, i);
Block := (others => 0);
Bit_Set(A => Block, Bit_Address => i, Value => 1, Order => High_Order_First);
Run_Test(Key, Block, Encrypt_Test);
New_Line;
end loop;
end Set_2;
procedure Set_3(Set_No : in Positive; Encrypt_Test : in Boolean := True) is
Key : Key_T;
Block : Block_T;
begin
Print_Set_Header(Set_No);
for i in u8'Range loop
Print_Vector_Header(Set_No, Natural(i));
Block := (others => i);
Key := (others => i);
Run_Test(Key, Block, Encrypt_Test);
New_Line;
end loop;
end Set_3;
procedure Set_4(Set_No : in Positive; Encrypt_Test : in Boolean := True) is
Key : Key_T;
Block : Block_T;
begin
Print_Set_Header(Set_No);
Print_Vector_Header(Set_No, 0);
for i in 0 .. Key'Length - 1 loop
Key(Key'First + i) := u8(i mod 256);
end loop;
for i in 0 .. Block'Length - 1 loop
Block(Block'First + i) := u8((17 * i) mod 256);
end loop;
Run_Test(Key, Block, Encrypt_Test);
New_Line;
Print_Vector_Header(Set_No, 1);
for i in 0 .. Key'Length - 1 loop
Key(Key'First + i) := Kasumi_Test_Key(Kasumi_Test_Key'First + (i mod Kasumi_Test_Key'Length));
end loop;
for i in 0 .. Block'Length - 1 loop
Block(Block'First + i) := Kasumi_Test_Plain(Kasumi_Test_Plain'First + (i mod Kasumi_Test_Plain'Length));
end loop;
Run_Test(Key, Block, Encrypt_Test);
New_Line;
end Set_4;
procedure Run(FileName : String := "") is
File : File_Type;
Redirected : Boolean := False;
begin
Initialize_Display;
if FileName /= "" and FileName /= "-" then
Redirected := True;
Create(File => File, Name => FileName, Mode => Out_File);
Set_Output(File);
end if;
Print_Header;
Set_1(1, True);
Set_2(2, True);
Set_3(3, True);
Set_4(4, True);
Set_1(5, False);
Set_2(6, False);
Set_3(7, False);
Set_4(8, False);
New_Line; New_Line;
Put_Line("End of test vectors");
Flush;
if Redirected then
Close(File);
Set_Output(Standard_Output);
end if;
end Run;
procedure Run_File is
begin
Run(Name & Default_Suffix);
end Run_File;
end Nessie_BC_Test_Generator;

View File

@ -0,0 +1,76 @@
-- Copyright (C) 2015 Daniel Otte <bg@nerilex.org>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Crypto_Core_Types; use Crypto_Core_Types;
--
-- ********************************************************************************
-- *Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
-- ********************************************************************************
--
-- Primitive Name: Des
-- ===================
-- Key size: 64 bits
-- Block size: 64 bits
--
-- Test vectors -- set 1
-- =====================
--
-- Set 1, vector# 0:
-- key=8000000000000000
-- Plain=0000000000000000
-- cipher=95A8D72813DAA94D
-- decrypted=0000000000000000
-- Iterated 100 times=F749E1F8DEFAF605
-- Iterated 1000 times=F396DD0B33D04244
--
-- Set 1, vector# 1:
-- key=4000000000000000
-- plain=0000000000000000
-- cipher=0EEC1487DD8C26D5
-- decrypted=0000000000000000
-- Iterated 100 times=E5BEE86B600F3B48
-- Iterated 1000 times=1D5931D700EF4E15
generic
Name : String;
Key_Size_Bits : Natural;
Block_Size_Bits : Natural;
type Context_T is private;
with procedure Initialize(Context : out Context_T; Key : in u8_Array);
with procedure Encrypt(Context : in Context_T; Block : in out u8_Array);
with procedure Decrypt(Context : in Context_T; Block : in out u8_Array);
package Nessie_BC_Test_Generator is
Verbose : Boolean := True;
procedure Run(FileName : String := "");
procedure Run_File;
Default_Suffix : constant String := ".test-vectors";
private
Key_Size_Bytes : constant Natural := (Key_Size_Bits + 7) / 8;
Block_Size_Bytes : constant Natural := (Block_Size_Bits + 7) / 8;
subtype Key_T is u8_Array( 1 .. Key_Size_Bytes );
subtype Block_T is u8_Array( 1 .. Block_Size_Bytes );
end Nessie_BC_Test_Generator;

View File

@ -0,0 +1,318 @@
-- Copyright (C) 2015 Daniel Otte <bg@nerilex.org>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Crypto_Types; use Crypto_Types;
with System; use System;
use Crypto_Types.Crypto_Types_u8;
-- Test vectors -- set 1
-- =====================
--
-- Set 1, vector# 0:
-- message="" (empty string)
-- hash=E3B0C44298FC1C149AFBF4C8996FB924
-- 27AE41E4649B934CA495991B7852B855
--
-- Set 1, vector# 1:
-- message="a"
-- hash=CA978112CA1BBDCAFAC231B39A23DC4D
-- A786EFF8147C4E72B9807785AFEE48BB
--
-- Set 1, vector# 2:
-- message="abc"
-- hash=BA7816BF8F01CFEA414140DE5DAE2223
-- B00361A396177A9CB410FF61F20015AD
--
-- Set 1, vector# 3:
-- message="message digest"
-- hash=F7846F55CF23E14EEBEAB5B4E1550CAD
-- 5B509E3348FBC4EFA3A1413D393CB650
--
-- Set 1, vector# 4:
-- message="abcdefghijklmnopqrstuvwxyz"
-- hash=71C480DF93D6AE2F1EFAD1447C66C952
-- 5E316218CF51FC8D9ED832F2DAF18B73
--
-- Set 1, vector# 5:
-- message="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
-- hash=248D6A61D20638B8E5C026930C3E6039
-- A33CE45964FF2167F6ECEDD419DB06C1
--
-- Set 1, vector# 6:
-- message="A...Za...z0...9"
-- hash=DB4BFCBD4DA0CD85A60C3C37D3FBD880
-- 5C77F15FC6B1FDFE614EE0A7C8FDB4C0
--
-- Set 1, vector# 7:
-- message=8 times "1234567890"
-- hash=F371BC4A311F2B009EEF952DD83CA80E
-- 2B60026C8E935592D0F9C308453C813E
--
-- Set 1, vector# 8:
-- message=1 million times "a"
-- hash=CDC76E5C9914FB9281A1C7E284D73E67
-- F1809A48A497200E046D39CCC7112CD0
package body Nessie_Hash_Test_Generator is
Set_1_Labels : constant array (1 .. 9) of access constant String :=
(
new String'("""" & """" & " (empty string)"),
new String'("""" & "a" & """"),
new String'("""" & "abc" & """"),
new String'("""" & "message digest" & """"),
new String'("""" & "abcdefghijklmnopqrstuvwxyz" & """"),
new String'("""" & "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" & """"),
new String'("""" & "A...Za...z0...9" & """"),
new String'("8 times " & """" & "1234567890" & """"),
new String'("1 million times " & """" & "a" & """")
);
Set_1_Values : constant array (1 .. 8) of access constant String :=
(
new String'(""),
new String'("a"),
new String'("abc"),
new String'("message digest"),
new String'("abcdefghijklmnopqrstuvwxyz"),
new String'("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
new String'("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
new String'("1234567890123456789012345678901234567890" &
"1234567890123456789012345678901234567890")
);
Step : Natural;
procedure Print_Header is
begin
Put_Line("********************************************************************************");
Put_Line("* SteelCrypt - NESSIE TestVectors *");
Put_Line("********************************************************************************");
New_Line;
Put_Line("Primitive Name: " & Name);
Put_Line((16 + Name'Length) * '=');
Put_Line("Hash size:" & Integer'Image(Digest_Size_Bits) & " bits");
New_Line;
end Print_Header;
procedure Print_Set_Header(Set_No : in Positive; Comment : in String := "") is
begin
Put_Line("Test vectors -- set" & Integer'Image(Set_No));
Put_Line("=====================");
if Comment'Length > 0 then
Put_Line(Comment);
end if;
New_Line;
end Print_Set_Header;
procedure Print_Vector_Header(Set_No : in Positive; Vector_No : in Natural) is
Vector_No_Str : constant String := Trim(Source => Integer'Image(Vector_No), Side => Both);
begin
Put("Set" & Integer'Image(Set_No) &", vector#");
if Vector_No_Str'Length < 3 then Put(' '); end if;
if Vector_No_Str'Length < 2 then Put(' '); end if;
Put_Line(Vector_No_Str & ":");
end Print_Vector_Header;
procedure Print_Item(Tag : in String; Block : in u8_Array) is
Split : constant Boolean := Block'Length > 24;
j : Integer := Block'First;
begin
if Tag'Length < 30 then
Put((30 - Tag'Length) * ' ');
end if;
if Split then
Put_Line(Tag & "=" & To_Hex(A => Block(j .. j + 15), Upper_Case => True));
j := j + 16;
while j + 16 < Block'Last loop
Put_Line(31 * ' ' & To_Hex(A => Block(j .. j + 15), Upper_Case => True));
j := j + 16;
end loop;
if j <= Block'Last then
Put_Line(31 * ' ' & To_Hex(A => Block(j .. Block'Last), Upper_Case => True));
end if;
else
Put_Line(Tag & "=" & To_Hex(A => Block, Upper_Case => True));
end if;
end Print_Item;
procedure Print_Item(Tag : in String; Item : in String) is
begin
if Tag'Length < 30 then
Put((30 - Tag'Length) * ' ');
end if;
Put_Line(Tag & "=" & Item);
end Print_Item;
procedure Hash_Test(Data : in u8_Array; Bits : in Integer := -1) is
Digest : u8_Array(1 .. Digest_Size_Bytes);
begin
Hash(Data => Data, Digest => Digest, Bits => Bits);
Print_Item("hash", Digest);
end Hash_Test;
procedure Hash_Test(Data : in String) is
begin
Hash_Test(From_Ascii(Data));
end;
procedure Initialize_Display is
begin
Step := 0;
if Verbose then
New_Line(File => Standard_Error);
end if;
end Initialize_Display;
procedure Update_Display is
begin
if Verbose then
-- Put(File => Standard_Error,
-- Item => Character'Val(13) & " ==> " & Name & ": ");
-- -- Put(File => Standard_Error, Item => Float'Image(100.0 * Float(Step) / Float(Total_Number_Of_Primitive_Runs)) & "%");
-- Put(File => Standard_Error,
-- Item => 100.0 * Float(Step) / Float(Total_Number_Of_Primitive_Runs),
-- Fore => 3,
-- Aft => 2,
-- Exp => 0 );
-- Put(File => Standard_Error,
-- Item => '%' );
null;
end if;
end Update_Display;
procedure Set_1_Vector_8 is
Block : constant u8_Array(1 .. Block_Size_Bytes) := (others => Character'Pos('a'));
Ctx : Context_T;
Digest : u8_Array(1 .. Digest_Size_Bytes);
c : Natural := 1_000_000;
begin
Print_Vector_Header(1, 8);
Print_Item("message", Set_1_Labels(9).all);
Initialize(Ctx);
while c > Block_Size_Bytes loop
Next_Block(Ctx, Block);
c := c - Block_Size_Bytes;
end loop;
Last_Block(Ctx, Block(1 .. c));
Get_Digest(Ctx, Digest);
Print_Item("hash", Digest);
New_Line;
end;
procedure Set_1 is
begin
Print_Set_Header(1);
for i in 1 .. 8 loop
Print_Vector_Header(1, i - 1);
Print_Item("message", Set_1_Labels(i).all);
Hash_Test(Set_1_Values(i).all);
New_Line;
end loop;
Set_1_Vector_8;
end Set_1;
procedure Set_2 is
Block : constant u8_Array(1 .. 1024 / 8) := (others => 0);
begin
Print_Set_Header(2, "Message digests of strings of 0-bits and variable length:");
for i in 0 .. 1023 loop
Print_Vector_Header(2, i);
Print_Item("message", Trim(Integer'Image(i), Both) & " zero bits");
Hash_Test(Block, i);
New_Line;
end loop;
New_Line;
end Set_2;
procedure Set_3 is
Block : u8_Array(1 .. 512 / 8) := (others => 0);
begin
Print_Set_Header(3, "Message digests of all 512-bit strings S containing a single 1-bit:");
for i in 0 .. 511 loop
Print_Vector_Header(3, i);
Bit_Set(Block, i, 1, High_Order_First);
Put(23 * ' ');
Put("message=512-bit string: ");
Put(Item => i / 8,
Width => 2 );
Put("*00,");
Put(To_Hex(Block(Block'First + i / 8)));
Put(",");
Put(Item => (511 - i) / 8,
Width => 2 );
Put_Line("*00");
Hash_Test(Block);
Bit_Set(Block, i, 0, High_Order_First);
New_Line;
end loop;
New_Line;
end Set_3;
procedure Set_4 is
Digest : u8_Array(1 .. Digest_Size_Bytes) := (others => 0);
begin
Print_Set_Header(4);
Print_Vector_Header(4, 0);
Print_Item("message", Trim(Integer'Image(Digest_Size_Bits), Both) & " zero bits");
Hash_Test(Digest);
for i in 1 .. 100_000 loop
Hash(Digest, Digest);
end loop;
Print_Item("iterated 100000 times", Digest);
New_Line;
end Set_4;
procedure Run(FileName : String := "") is
File : File_Type;
Redirected : Boolean := False;
begin
-- Initialize_Display;
if FileName /= "" and FileName /= "-" then
Redirected := True;
Create(File => File, Name => FileName, Mode => Out_File);
Set_Output(File);
end if;
Print_Header;
Set_1;
Set_2;
Set_3;
Set_4;
New_Line; New_Line;
Put_Line("End of test vectors");
Flush;
if Redirected then
Close(File);
Set_Output(Standard_Output);
end if;
end Run;
procedure Run_File is
begin
Run(Name & Default_Suffix);
end Run_File;
end Nessie_Hash_Test_Generator;

View File

@ -0,0 +1,42 @@
-- Copyright (C) 2015 Daniel Otte <bg@nerilex.org>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Crypto_Core_Types; use Crypto_Core_Types;
generic
Name : String;
Digest_Size_Bits : Natural;
Block_Size_Bits : Natural;
type Context_T is private;
with procedure Initialize(Context : out Context_T);
with procedure Next_Block(Context : in out Context_T; Block : in u8_Array);
with procedure Last_Block(Context : in out Context_T; Block : in u8_Array; Bits : in Integer := -1);
with procedure Get_Digest(Context : in out Context_T; Digest : out u8_Array);
with procedure Hash(Data : in u8_Array; Digest : out u8_Array; Bits : in Integer := -1);
package Nessie_Hash_Test_Generator is
Verbose : Boolean := True;
procedure Run(FileName : String := "");
procedure Run_File;
Default_Suffix : constant String := ".test-vectors";
private
Digest_Size_Bytes : constant Natural := (Digest_Size_Bits + 7) / 8;
Block_Size_Bytes : constant Natural := (Block_Size_Bits + 7) / 8;
end Nessie_Hash_Test_Generator;

View File

@ -139,12 +139,12 @@ package body Sha_Test_IO is
f : Context_T;
nt : Next_Type;
count_val : Integer;
dlen : Integer := DigestSize_Bits / 8;
dlen : Integer := Digest_Size_Bits / 8;
len, lenb : Integer;
DigestSize_Bytes : constant Natural := (DigestSize_Bits + 7 ) / 8;
digest, ref_Digest : u8_Array(1 .. DigestSize_Bytes) := (others => 0);
Digest_Size_Bytes : constant Natural := (Digest_Size_Bits + 7 ) / 8;
digest, ref_Digest : u8_Array(1 .. Digest_Size_Bytes) := (others => 0);
ok_test, fail_test, num : Natural := 0;
seed_val : u8_Array(1 .. DigestSize_Bytes) := (others => 0);
seed_val : u8_Array(1 .. Digest_Size_Bytes) := (others => 0);
begin
New_Line;
Put("== " & FileName &" ==");
@ -171,15 +171,15 @@ package body Sha_Test_IO is
end if;
num := num + 1;
declare
blob : u8_Array(1 .. 3 * DigestSize_Bytes);
blob : u8_Array(1 .. 3 * Digest_Size_Bytes);
begin
blob(1 + 0 * DigestSize_Bytes .. 1 * DigestSize_Bytes) := Seed_Val;
blob(1 + 1 * DigestSize_Bytes .. 2 * DigestSize_Bytes) := Seed_Val;
blob(1 + 2 * DigestSize_Bytes .. 3 * DigestSize_Bytes) := Seed_Val;
blob(1 + 0 * Digest_Size_Bytes .. 1 * Digest_Size_Bytes) := Seed_Val;
blob(1 + 1 * Digest_Size_Bytes .. 2 * Digest_Size_Bytes) := Seed_Val;
blob(1 + 2 * Digest_Size_Bytes .. 3 * Digest_Size_Bytes) := Seed_Val;
for i in 1 .. 1000 loop
Hash(blob, Digest);
blob(1 .. 2 * DigestSize_Bytes) := blob(1 + 1 * DigestSize_Bytes .. 3 * DigestSize_Bytes);
blob(1 + 2 * DigestSize_Bytes .. 3 * DigestSize_Bytes) := Digest;
blob(1 .. 2 * Digest_Size_Bytes) := blob(1 + 1 * Digest_Size_Bytes .. 3 * Digest_Size_Bytes);
blob(1 + 2 * Digest_Size_Bytes .. 3 * Digest_Size_Bytes) := Digest;
end loop;
Seed_Val := Digest;
end;

View File

@ -53,7 +53,7 @@ package Sha_Test_IO is
generic
DigestSize_Bits : Natural;
Digest_Size_Bits : Natural;
with procedure Hash(Data : in u8_Array; Digest : out u8_Array; Bits : in Integer := -1);
procedure Test_With_File(FileName : in String);

61
src/tests/test_aes.adb Normal file
View File

@ -0,0 +1,61 @@
-- Copyright (C) 2015 Daniel Otte <bg@nerilex.org>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Crypto_Core_Types; use Crypto_Core_Types;
with Crypto_Types; use Crypto_Types;
use Crypto_Types.Crypto_Types_u8;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Nessie_BC_Test_Generator;
with AES;
procedure Test_AES is
package Nessie_Test_128 is new Nessie_BC_Test_Generator(
Name => "AES-128",
Key_Size_Bits => AES.Key_128_T'Length * 8,
Block_Size_Bits => AES.Block_T'Length * 8,
Context_T => AES.Context_128_T,
Initialize => AES.Initialize,
Encrypt => AES.Encrypt,
Decrypt => AES.Decrypt );
package Nessie_Test_192 is new Nessie_BC_Test_Generator(
Name => "AES-192",
Key_Size_Bits => AES.Key_192_T'Length * 8,
Block_Size_Bits => AES.Block_T'Length * 8,
Context_T => AES.Context_192_T,
Initialize => AES.Initialize,
Encrypt => AES.Encrypt,
Decrypt => AES.Decrypt );
package Nessie_Test_256 is new Nessie_BC_Test_Generator(
Name => "AES-256",
Key_Size_Bits => AES.Key_256_T'Length * 8,
Block_Size_Bits => AES.Block_T'Length * 8,
Context_T => AES.Context_256_T,
Initialize => AES.Initialize,
Encrypt => AES.Encrypt,
Decrypt => AES.Decrypt );
begin
Nessie_Test_128.Run_File;
Nessie_Test_192.Run_File;
Nessie_Test_256.Run_File;
end Test_AES;

40
src/tests/test_des.adb Normal file
View File

@ -0,0 +1,40 @@
-- Copyright (C) 2015 Daniel Otte <bg@nerilex.org>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- with Ada.Text_IO; use Ada.Text_IO;
-- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Crypto_Core_Types; use Crypto_Core_Types;
with Crypto_Types; use Crypto_Types;
use Crypto_Types.Crypto_Types_u8;
with Nessie_BC_Test_Generator;
with DES;
procedure Test_DES is
package Nessie_Test is new Nessie_BC_Test_Generator(
Name => "DES",
Key_Size_Bits => DES.Key_T'Length * 8,
Block_Size_Bits => DES.Block_T'Length * 8,
Context_T => DES.Context_T,
Initialize => DES.Initialize,
Encrypt => DES.Encrypt,
Decrypt => DES.Decrypt );
begin
Nessie_Test.Run_File;
end Test_DES;

View File

@ -19,6 +19,8 @@ with Crypto_Types; use Crypto_Types;
with Sha_Test_IO;
with Nessie_Hash_Test_Generator;
with SHA2_224;
with SHA2_256;
with SHA2_384;
@ -28,43 +30,90 @@ use Crypto_Types.Crypto_Types_u8;
procedure Test_SHA2 is
procedure test_sha224_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA2_224.DigestSize_Bits, Hash => SHA2_224.Hash);
procedure test_sha256_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA2_256.DigestSize_Bits, Hash => SHA2_256.Hash);
procedure test_sha384_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA2_384.DigestSize_Bits, Hash => SHA2_384.Hash);
procedure test_sha512_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA2_512.DigestSize_Bits, Hash => SHA2_512.Hash);
procedure test_sha224_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA2_224.Digest_Size_Bits, Hash => SHA2_224.Hash);
procedure test_sha256_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA2_256.Digest_Size_Bits, Hash => SHA2_256.Hash);
procedure test_sha384_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA2_384.Digest_Size_Bits, Hash => SHA2_384.Hash);
procedure test_sha512_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA2_512.Digest_Size_Bits, Hash => SHA2_512.Hash);
package Nessie_Test_Sha224 is new Nessie_Hash_Test_Generator(
Name => "SHA-224",
Digest_Size_Bits => SHA2_224.Digest_Size_Bits,
Block_Size_Bits => SHA2_224.Block_Size_Bits,
Context_T => SHA2_224.Context_T,
Initialize => SHA2_224.Initialize,
Next_Block => SHA2_224.Next_Block,
Last_Block => SHA2_224.Last_Block,
Get_Digest => SHA2_224.Get_Digest,
Hash => SHA2_224.Hash);
package Nessie_Test_Sha256 is new Nessie_Hash_Test_Generator(
Name => "SHA-256",
Digest_Size_Bits => SHA2_256.Digest_Size_Bits,
Block_Size_Bits => SHA2_256.Block_Size_Bits,
Context_T => SHA2_256.Context_T,
Initialize => SHA2_256.Initialize,
Next_Block => SHA2_256.Next_Block,
Last_Block => SHA2_256.Last_Block,
Get_Digest => SHA2_256.Get_Digest,
Hash => SHA2_256.Hash);
package Nessie_Test_Sha384 is new Nessie_Hash_Test_Generator(
Name => "SHA-384",
Digest_Size_Bits => SHA2_384.Digest_Size_Bits,
Block_Size_Bits => SHA2_384.Block_Size_Bits,
Context_T => SHA2_384.Context_T,
Initialize => SHA2_384.Initialize,
Next_Block => SHA2_384.Next_Block,
Last_Block => SHA2_384.Last_Block,
Get_Digest => SHA2_384.Get_Digest,
Hash => SHA2_384.Hash);
package Nessie_Test_Sha512 is new Nessie_Hash_Test_Generator(
Name => "SHA-512",
Digest_Size_Bits => SHA2_512.Digest_Size_Bits,
Block_Size_Bits => SHA2_512.Block_Size_Bits,
Context_T => SHA2_512.Context_T,
Initialize => SHA2_512.Initialize,
Next_Block => SHA2_512.Next_Block,
Last_Block => SHA2_512.Last_Block,
Get_Digest => SHA2_512.Get_Digest,
Hash => SHA2_512.Hash);
begin
New_Line;
test_sha224_with_File("testvectors/sha2/bit/SHA224ShortMsg.rsp");
test_sha224_with_File("testvectors/sha2/bit/SHA224LongMsg.rsp");
test_sha224_with_File("testvectors/sha2/bit/SHA224Monte.rsp");
test_sha224_with_File("testvectors/sha2/byte/SHA224ShortMsg.rsp");
test_sha224_with_File("testvectors/sha2/byte/SHA224LongMsg.rsp");
test_sha224_with_File("testvectors/sha2/byte/SHA224Monte.rsp");
New_Line;
test_sha256_with_File("testvectors/sha2/bit/SHA256ShortMsg.rsp");
test_sha256_with_File("testvectors/sha2/bit/SHA256LongMsg.rsp");
test_sha256_with_File("testvectors/sha2/bit/SHA256Monte.rsp");
test_sha256_with_File("testvectors/sha2/byte/SHA256ShortMsg.rsp");
test_sha256_with_File("testvectors/sha2/byte/SHA256LongMsg.rsp");
test_sha256_with_File("testvectors/sha2/byte/SHA256Monte.rsp");
Nessie_Test_Sha224.Run_File;
Nessie_Test_Sha256.Run_File;
Nessie_Test_Sha384.Run_File;
Nessie_Test_Sha512.Run_File;
New_Line;
test_sha384_with_File("testvectors/sha2/bit/SHA384ShortMsg.rsp");
test_sha384_with_File("testvectors/sha2/bit/SHA384LongMsg.rsp");
test_sha384_with_File("testvectors/sha2/bit/SHA384Monte.rsp");
test_sha384_with_File("testvectors/sha2/byte/SHA384ShortMsg.rsp");
test_sha384_with_File("testvectors/sha2/byte/SHA384LongMsg.rsp");
test_sha384_with_File("testvectors/sha2/byte/SHA384Monte.rsp");
New_Line;
test_sha512_with_File("testvectors/sha2/bit/SHA512ShortMsg.rsp");
test_sha512_with_File("testvectors/sha2/bit/SHA512LongMsg.rsp");
test_sha512_with_File("testvectors/sha2/bit/SHA512Monte.rsp");
test_sha512_with_File("testvectors/sha2/byte/SHA512ShortMsg.rsp");
test_sha512_with_File("testvectors/sha2/byte/SHA512LongMsg.rsp");
test_sha512_with_File("testvectors/sha2/byte/SHA512Monte.rsp");
-- New_Line;
-- test_sha224_with_File("testvectors/sha2/bit/SHA224ShortMsg.rsp");
-- test_sha224_with_File("testvectors/sha2/bit/SHA224LongMsg.rsp");
-- test_sha224_with_File("testvectors/sha2/bit/SHA224Monte.rsp");
-- test_sha224_with_File("testvectors/sha2/byte/SHA224ShortMsg.rsp");
-- test_sha224_with_File("testvectors/sha2/byte/SHA224LongMsg.rsp");
-- test_sha224_with_File("testvectors/sha2/byte/SHA224Monte.rsp");
--
-- New_Line;
-- test_sha256_with_File("testvectors/sha2/bit/SHA256ShortMsg.rsp");
-- test_sha256_with_File("testvectors/sha2/bit/SHA256LongMsg.rsp");
-- test_sha256_with_File("testvectors/sha2/bit/SHA256Monte.rsp");
-- test_sha256_with_File("testvectors/sha2/byte/SHA256ShortMsg.rsp");
-- test_sha256_with_File("testvectors/sha2/byte/SHA256LongMsg.rsp");
-- test_sha256_with_File("testvectors/sha2/byte/SHA256Monte.rsp");
--
-- New_Line;
-- test_sha384_with_File("testvectors/sha2/bit/SHA384ShortMsg.rsp");
-- test_sha384_with_File("testvectors/sha2/bit/SHA384LongMsg.rsp");
-- test_sha384_with_File("testvectors/sha2/bit/SHA384Monte.rsp");
-- test_sha384_with_File("testvectors/sha2/byte/SHA384ShortMsg.rsp");
-- test_sha384_with_File("testvectors/sha2/byte/SHA384LongMsg.rsp");
-- test_sha384_with_File("testvectors/sha2/byte/SHA384Monte.rsp");
--
-- New_Line;
-- test_sha512_with_File("testvectors/sha2/bit/SHA512ShortMsg.rsp");
-- test_sha512_with_File("testvectors/sha2/bit/SHA512LongMsg.rsp");
-- test_sha512_with_File("testvectors/sha2/bit/SHA512Monte.rsp");
-- test_sha512_with_File("testvectors/sha2/byte/SHA512ShortMsg.rsp");
-- test_sha512_with_File("testvectors/sha2/byte/SHA512LongMsg.rsp");
-- test_sha512_with_File("testvectors/sha2/byte/SHA512Monte.rsp");
New_Line;

View File

@ -50,7 +50,7 @@ procedure Test_SHA256 is
-- New_Line;
-- end test_sha256;
procedure test_sha256_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA2_256.DigestSize_Bits, Hash => SHA2_256.Hash);
procedure test_sha256_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA2_256.Digest_Size_Bits, Hash => SHA2_256.Hash);
begin
Put_Line("SHA2_256.Context_T'Size: " & Integer'Image(SHA2_256.Context_T'Size / 8));

View File

@ -25,10 +25,10 @@ use Crypto_Types.Crypto_Types_u8;
procedure Test_SHA3 is
procedure test_sha3_224_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA3_224.DigestSize_Bits, Hash => SHA3_224.Hash);
procedure test_sha3_256_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA3_256.DigestSize_Bits, Hash => SHA3_256.Hash);
procedure test_sha3_384_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA3_384.DigestSize_Bits, Hash => SHA3_384.Hash);
procedure test_sha3_512_with_File is new Sha_Test_IO.Test_With_File(DigestSize_Bits => SHA3_512.DigestSize_Bits, Hash => SHA3_512.Hash);
procedure test_sha3_224_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA3_224.Digest_Size_Bits, Hash => SHA3_224.Hash);
procedure test_sha3_256_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA3_256.Digest_Size_Bits, Hash => SHA3_256.Hash);
procedure test_sha3_384_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA3_384.Digest_Size_Bits, Hash => SHA3_384.Hash);
procedure test_sha3_512_with_File is new Sha_Test_IO.Test_With_File(Digest_Size_Bits => SHA3_512.Digest_Size_Bits, Hash => SHA3_512.Hash);
begin
New_Line;

52
src/tests/test_tdes.adb Normal file
View File

@ -0,0 +1,52 @@
-- Copyright (C) 2015 Daniel Otte <bg@nerilex.org>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- with Ada.Text_IO; use Ada.Text_IO;
-- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Crypto_Core_Types; use Crypto_Core_Types;
with Crypto_Types; use Crypto_Types;
use Crypto_Types.Crypto_Types_u8;
with Nessie_BC_Test_Generator;
with TDES;
procedure Test_TDES is
package Nessie_Test_2 is new Nessie_BC_Test_Generator(
Name => "Triple-DES (two keys)",
Key_Size_Bits => TDES.Key_128_T'Length * 8,
Block_Size_Bits => TDES.Block_T'Length * 8,
Context_T => TDES.Context_T,
Initialize => TDES.Initialize,
Encrypt => TDES.Encrypt,
Decrypt => TDES.Decrypt );
package Nessie_Test_3 is new Nessie_BC_Test_Generator(
Name => "Triple-DES (three keys)",
Key_Size_Bits => TDES.Key_192_T'Length * 8,
Block_Size_Bits => TDES.Block_T'Length * 8,
Context_T => TDES.Context_T,
Initialize => TDES.Initialize,
Encrypt => TDES.Encrypt,
Decrypt => TDES.Decrypt );
begin
Nessie_Test_2.Verbose := True;
Nessie_Test_2.Run_File;
Nessie_Test_3.Verbose := True;
Nessie_Test_3.Run_File;
end Test_TDES;

View File

@ -1,351 +0,0 @@
function "xor"(Left, Right : u16_Array) return u16_Array;
function "xor"(Left, Right : u32_Array) return u32_Array;
function "xor"(Left, Right : u64_Array) return u64_Array;
-- xor the left element with each element on the right
function "xor"(Left : u8; Right : u8_Array ) return u8;
function "xor"(Left : u16; Right : u16_Array) return u16;
function "xor"(Left : u32; Right : u32_Array) return u32;
function "xor"(Left : u64; Right : u64_Array) return u64;
-- xor each element on the left with the element on the right
function "xor"(Left : u8_Array; Right : u8 ) return u8_Array;
function "xor"(Left : u16_Array; Right : u16) return u16_Array;
function "xor"(Left : u32_Array; Right : u32) return u32_Array;
function "xor"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- and each element on the left with the corresponding element on the right
function "and"(Left, Right : u8_Array ) return u8_Array;
function "and"(Left, Right : u16_Array) return u16_Array;
function "and"(Left, Right : u32_Array) return u32_Array;
function "and"(Left, Right : u64_Array) return u64_Array;
-- and the left element with each element on the right
function "and"(Left : u8; Right : u8_Array ) return u8;
function "and"(Left : u16; Right : u16_Array) return u16;
function "and"(Left : u32; Right : u32_Array) return u32;
function "and"(Left : u64; Right : u64_Array) return u64;
-- and each element on the left with the element on the right
function "and"(Left : u8_Array; Right : u8 ) return u8_Array;
function "and"(Left : u16_Array; Right : u16) return u16_Array;
function "and"(Left : u32_Array; Right : u32) return u32_Array;
function "and"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- or each element on the left with the corresponding element on the right
function "or"(Left, Right : u8_Array ) return u8_Array;
function "or"(Left, Right : u16_Array) return u16_Array;
function "or"(Left, Right : u32_Array) return u32_Array;
function "or"(Left, Right : u64_Array) return u64_Array;
-- or the left element with each element on the right
function "or"(Left : u8; Right : u8_Array ) return u8;
function "or"(Left : u16; Right : u16_Array) return u16;
function "or"(Left : u32; Right : u32_Array) return u32;
function "or"(Left : u64; Right : u64_Array) return u64;
-- or each element on the left with the element on the right
function "or"(Left : u8_Array; Right : u8 ) return u8_Array;
function "or"(Left : u16_Array; Right : u16) return u16_Array;
function "or"(Left : u32_Array; Right : u32) return u32_Array;
function "or"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- add each element on the left with the corresponding element on the right
function "+"(Left, Right : u8_Array ) return u8_Array;
function "+"(Left, Right : u16_Array) return u16_Array;
function "+"(Left, Right : u32_Array) return u32_Array;
function "+"(Left, Right : u64_Array) return u64_Array;
-- add the left element with each element on the right
function "+"(Left : u8; Right : u8_Array ) return u8;
function "+"(Left : u16; Right : u16_Array) return u16;
function "+"(Left : u32; Right : u32_Array) return u32;
function "+"(Left : u64; Right : u64_Array) return u64;
-- add each element on the left with the element on the right
function "+"(Left : u8_Array; Right : u8 ) return u8_Array;
function "+"(Left : u16_Array; Right : u16) return u16_Array;
function "+"(Left : u32_Array; Right : u32) return u32_Array;
function "+"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- subtract from each element on the left the corresponding element on the right
function "-"(Left, Right : u8_Array ) return u8_Array;
function "-"(Left, Right : u16_Array) return u16_Array;
function "-"(Left, Right : u32_Array) return u32_Array;
function "-"(Left, Right : u64_Array) return u64_Array;
-- subtract from the left element each element on the right
function "-"(Left : u8; Right : u8_Array ) return u8;
function "-"(Left : u16; Right : u16_Array) return u16;
function "-"(Left : u32; Right : u32_Array) return u32;
function "-"(Left : u64; Right : u64_Array) return u64;
-- subtract from each element on the left the element on the right
function "-"(Left : u8_Array; Right : u8 ) return u8_Array;
function "-"(Left : u16_Array; Right : u16) return u16_Array;
function "-"(Left : u32_Array; Right : u32) return u32_Array;
function "-"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- rotate the whole Array as continues big-endian integer; positive Amount rotates left (towards lower address)
function Rotate_be is new Rotate_be(u8, u8_Array, u8_Array_Access);
--function Rotate_be(A : u8_Array; Amount : Integer) return u8_Array;
function Rotate_be(A : u16_Array; Amount : Integer) return u16_Array;
function Rotate_be(A : u32_Array; Amount : Integer) return u32_Array;
function Rotate_be(A : u64_Array; Amount : Integer) return u64_Array;
-- rotate the whole Array as continues little-endian integer; positive Amount rotates left (towards higher address)
function Rotate_le(A : u8_Array; Amount : Integer) return u8_Array;
function Rotate_le(A : u16_Array; Amount : Integer) return u16_Array;
function Rotate_le(A : u32_Array; Amount : Integer) return u32_Array;
function Rotate_le(A : u64_Array; Amount : Integer) return u64_Array;
-- rotate each element by Amount to the left; negative values for Amount rotate to the right
function Rotate_each(A : u8_Array; Amount : Integer) return u8_Array;
function Rotate_each(A : u16_Array; Amount : Integer) return u16_Array;
function Rotate_each(A : u32_Array; Amount : Integer) return u32_Array;
function Rotate_each(A : u64_Array; Amount : Integer) return u64_Array;
-- -----
-- shift the whole Array as continues big-endian integer; positive Amount shifts left (towards lower address)
function Shift_be(A : u8_Array; Amount : Integer) return u8_Array;
function Shift_be(A : u16_Array; Amount : Integer) return u16_Array;
function Shift_be(A : u32_Array; Amount : Integer) return u32_Array;
function Shift_be(A : u64_Array; Amount : Integer) return u64_Array;
-- -----
-- Shift the whole Array as continues little-endian integer; positive Amount shifts left (towards higher address)
function Shift_le(A : u8_Array; Amount : Integer) return u8_Array;
function Shift_le(A : u16_Array; Amount : Integer) return u16_Array;
function Shift_le(A : u32_Array; Amount : Integer) return u32_Array;
function Shift_le(A : u64_Array; Amount : Integer) return u64_Array;
-- -----
-- shift each element by Amount to the left; negative values for Amount shift to the right
function Shift_each(A : u8_Array; Amount : Integer) return u8_Array;
function Shift_each(A : u16_Array; Amount : Integer) return u16_Array;
function Shift_each(A : u32_Array; Amount : Integer) return u32_Array;
function Shift_each(A : u64_Array; Amount : Integer) return u64_Array;
-- -----
-- load a value which is stored big-endian in byte Array
function Load_be(a : u8_Array) return u8;
function Load_be(a : u8_Array) return u16;
function Load_be(a : u8_Array) return u32;
function Load_be(a : u8_Array) return u64;
-- load a value which is stored little-endian in byte Array
function Load_le(a : u8_Array) return u8;
function Load_le(a : u8_Array) return u16;
function Load_le(a : u8_Array) return u32;
function Load_le(a : u8_Array) return u64;
-- -----
-- store a value in big-endian format in a byte Array
procedure Store_be(a : in out u8_Array; value : in u8);
procedure Store_be(a : in out u8_Array; value : in u16);
procedure Store_be(a : in out u8_Array; value : in u32);
procedure Store_be(a : in out u8_Array; value : in u64);
-- store a value in little-endian format in a byte Array
procedure Store_le(a : in out u8_Array; value : in u8);
procedure Store_le(a : in out u8_Array; value : in u16);
procedure Store_le(a : in out u8_Array; value : in u32);
procedure Store_le(a : in out u8_Array; value : in u64);
#################################################################################################################################
#################################################################################################################################
#################################################################################################################################
#################################################################################################################################
#################################################################################################################################
-- --------------------------
-- - Functions / Procedures -
-- --------------------------
-- xor each element on the left with the corresponding element on the right
function "xor"(Left, Right : u8_Array ) return u8_Array;
function "xor"(Left, Right : u16_Array) return u16_Array;
function "xor"(Left, Right : u32_Array) return u32_Array;
function "xor"(Left, Right : u64_Array) return u64_Array;
-- xor the left element with each element on the right
function "xor"(Left : u8; Right : u8_Array ) return u8;
function "xor"(Left : u16; Right : u16_Array) return u16;
function "xor"(Left : u32; Right : u32_Array) return u32;
function "xor"(Left : u64; Right : u64_Array) return u64;
-- xor each element on the left with the element on the right
function "xor"(Left : u8_Array; Right : u8 ) return u8_Array;
function "xor"(Left : u16_Array; Right : u16) return u16_Array;
function "xor"(Left : u32_Array; Right : u32) return u32_Array;
function "xor"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- and each element on the left with the corresponding element on the right
function "and"(Left, Right : u8_Array ) return u8_Array;
function "and"(Left, Right : u16_Array) return u16_Array;
function "and"(Left, Right : u32_Array) return u32_Array;
function "and"(Left, Right : u64_Array) return u64_Array;
-- and the left element with each element on the right
function "and"(Left : u8; Right : u8_Array ) return u8;
function "and"(Left : u16; Right : u16_Array) return u16;
function "and"(Left : u32; Right : u32_Array) return u32;
function "and"(Left : u64; Right : u64_Array) return u64;
-- and each element on the left with the element on the right
function "and"(Left : u8_Array; Right : u8 ) return u8_Array;
function "and"(Left : u16_Array; Right : u16) return u16_Array;
function "and"(Left : u32_Array; Right : u32) return u32_Array;
function "and"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- or each element on the left with the corresponding element on the right
function "or"(Left, Right : u8_Array ) return u8_Array;
function "or"(Left, Right : u16_Array) return u16_Array;
function "or"(Left, Right : u32_Array) return u32_Array;
function "or"(Left, Right : u64_Array) return u64_Array;
-- or the left element with each element on the right
function "or"(Left : u8; Right : u8_Array ) return u8;
function "or"(Left : u16; Right : u16_Array) return u16;
function "or"(Left : u32; Right : u32_Array) return u32;
function "or"(Left : u64; Right : u64_Array) return u64;
-- or each element on the left with the element on the right
function "or"(Left : u8_Array; Right : u8 ) return u8_Array;
function "or"(Left : u16_Array; Right : u16) return u16_Array;
function "or"(Left : u32_Array; Right : u32) return u32_Array;
function "or"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- add each element on the left with the corresponding element on the right
function "+"(Left, Right : u8_Array ) return u8_Array;
function "+"(Left, Right : u16_Array) return u16_Array;
function "+"(Left, Right : u32_Array) return u32_Array;
function "+"(Left, Right : u64_Array) return u64_Array;
-- add the left element with each element on the right
function "+"(Left : u8; Right : u8_Array ) return u8;
function "+"(Left : u16; Right : u16_Array) return u16;
function "+"(Left : u32; Right : u32_Array) return u32;
function "+"(Left : u64; Right : u64_Array) return u64;
-- add each element on the left with the element on the right
function "+"(Left : u8_Array; Right : u8 ) return u8_Array;
function "+"(Left : u16_Array; Right : u16) return u16_Array;
function "+"(Left : u32_Array; Right : u32) return u32_Array;
function "+"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- subtract from each element on the left the corresponding element on the right
function "-"(Left, Right : u8_Array ) return u8_Array;
function "-"(Left, Right : u16_Array) return u16_Array;
function "-"(Left, Right : u32_Array) return u32_Array;
function "-"(Left, Right : u64_Array) return u64_Array;
-- subtract from the left element each element on the right
function "-"(Left : u8; Right : u8_Array ) return u8;
function "-"(Left : u16; Right : u16_Array) return u16;
function "-"(Left : u32; Right : u32_Array) return u32;
function "-"(Left : u64; Right : u64_Array) return u64;
-- subtract from each element on the left the element on the right
function "-"(Left : u8_Array; Right : u8 ) return u8_Array;
function "-"(Left : u16_Array; Right : u16) return u16_Array;
function "-"(Left : u32_Array; Right : u32) return u32_Array;
function "-"(Left : u64_Array; Right : u64) return u64_Array;
-- -----
-- rotate the whole Array as continues big-endian integer; positive Amount rotates left (towards lower address)
function Rotate_be(A : u8_Array; Amount : Integer) return u8_Array;
function Rotate_be(A : u16_Array; Amount : Integer) return u16_Array;
function Rotate_be(A : u32_Array; Amount : Integer) return u32_Array;
function Rotate_be(A : u64_Array; Amount : Integer) return u64_Array;
-- rotate the whole Array as continues little-endian integer; positive Amount rotates left (towards higher address)
function Rotate_le(A : u8_Array; Amount : Integer) return u8_Array;
function Rotate_le(A : u16_Array; Amount : Integer) return u16_Array;
function Rotate_le(A : u32_Array; Amount : Integer) return u32_Array;
function Rotate_le(A : u64_Array; Amount : Integer) return u64_Array;
-- rotate each element by Amount to the left; negative values for Amount rotate to the right
function Rotate_each(A : u8_Array; Amount : Integer) return u8_Array;
function Rotate_each(A : u16_Array; Amount : Integer) return u16_Array;
function Rotate_each(A : u32_Array; Amount : Integer) return u32_Array;
function Rotate_each(A : u64_Array; Amount : Integer) return u64_Array;
-- -----
-- shift the whole Array as continues big-endian integer; positive Amount shifts left (towards lower address)
function Shift_be(A : u8_Array; Amount : Integer) return u8_Array;
function Shift_be(A : u16_Array; Amount : Integer) return u16_Array;
function Shift_be(A : u32_Array; Amount : Integer) return u32_Array;
function Shift_be(A : u64_Array; Amount : Integer) return u64_Array;
-- -----
-- Shift the whole Array as continues little-endian integer; positive Amount shifts left (towards higher address)
function Shift_le(A : u8_Array; Amount : Integer) return u8_Array;
function Shift_le(A : u16_Array; Amount : Integer) return u16_Array;
function Shift_le(A : u32_Array; Amount : Integer) return u32_Array;
function Shift_le(A : u64_Array; Amount : Integer) return u64_Array;
-- -----
-- shift each element by Amount to the left; negative values for Amount shift to the right
function Shift_each(A : u8_Array; Amount : Integer) return u8_Array;
function Shift_each(A : u16_Array; Amount : Integer) return u16_Array;
function Shift_each(A : u32_Array; Amount : Integer) return u32_Array;
function Shift_each(A : u64_Array; Amount : Integer) return u64_Array;
-- -----
-- load a value which is stored big-endian in byte Array
function Load_be(a : u8_Array) return u8;
function Load_be(a : u8_Array) return u16;
function Load_be(a : u8_Array) return u32;
function Load_be(a : u8_Array) return u64;
-- load a value which is stored little-endian in byte Array
function Load_le(a : u8_Array) return u8;
function Load_le(a : u8_Array) return u16;
function Load_le(a : u8_Array) return u32;
function Load_le(a : u8_Array) return u64;
-- -----
-- store a value in big-endian format in a byte Array
procedure Store_be(a : in out u8_Array; value : in u8);
procedure Store_be(a : in out u8_Array; value : in u16);
procedure Store_be(a : in out u8_Array; value : in u32);
procedure Store_be(a : in out u8_Array; value : in u64);
-- store a value in little-endian format in a byte Array
procedure Store_le(a : in out u8_Array; value : in u8);
procedure Store_le(a : in out u8_Array; value : in u16);
procedure Store_le(a : in out u8_Array; value : in u32);
procedure Store_le(a : in out u8_Array; value : in u64);

View File

@ -3,7 +3,18 @@ project Steelcrypt is
type Build_Modes is
("Release", "Debug");
Mode : Build_Modes := external ("BUILD", "Debug");
for Main use ("main.adb", "test_sha2.adb", "test_sha3.adb", "test_sha224.adb", "test_sha256.adb", "test_sha384.adb", "test_sha512.adb", "test_keccak.adb");
for Main use (
"main.adb",
"test_aes.adb",
"test_des.adb",
"test_tdes.adb",
"test_sha2.adb",
"test_sha3.adb",
"test_sha224.adb",
"test_sha256.adb",
"test_sha384.adb",
"test_sha512.adb",
"test_keccak.adb");
case Mode is