inital commit of type system
This commit is contained in:
parent
5bf74b29d2
commit
71b0945e0e
|
@ -19,9 +19,9 @@ package Crypto_Core_Types is
|
||||||
type u32_Array is Array (Integer range <>) of u32;
|
type u32_Array is Array (Integer range <>) of u32;
|
||||||
type u64_Array is Array (Integer range <>) of u64;
|
type u64_Array is Array (Integer range <>) of u64;
|
||||||
|
|
||||||
type u8_Array_Access is access u8_Array;
|
type u8_Array_Access is access all u8_Array;
|
||||||
type u16_Array_Access is access u16_Array;
|
type u16_Array_Access is access all u16_Array;
|
||||||
type u32_Array_Access is access u32_Array;
|
type u32_Array_Access is access all u32_Array;
|
||||||
type u64_Array_Access is access u64_Array;
|
type u64_Array_Access is access all u64_Array;
|
||||||
|
|
||||||
end Crypto_Core_Types;
|
end Crypto_Core_Types;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
with Crypto_Core_Types; use Crypto_Core_Types;
|
|
||||||
|
|
||||||
-- --------------------------
|
-- --------------------------
|
||||||
-- - Generic Functions / Procedures -
|
-- - Generic Functions / Procedures -
|
||||||
-- --------------------------
|
-- --------------------------
|
||||||
|
@ -9,6 +7,23 @@ with Crypto_Core_Types; use Crypto_Core_Types;
|
||||||
-- --------------------------
|
-- --------------------------
|
||||||
package body Crypto_Generic_Types is
|
package body Crypto_Generic_Types is
|
||||||
|
|
||||||
|
-- compare two array with timing independent of content
|
||||||
|
-- function "="(Left, Right : T_Array ) return Boolean is
|
||||||
|
-- x : T := 0;
|
||||||
|
-- begin
|
||||||
|
-- if Left'Length /= Right'Length then
|
||||||
|
-- return false;
|
||||||
|
-- end if;
|
||||||
|
-- for i in Left'Range loop
|
||||||
|
-- x := x or (Left(i) xor Right(i));
|
||||||
|
-- end loop;
|
||||||
|
-- if x = 0 then
|
||||||
|
-- return true;
|
||||||
|
-- else
|
||||||
|
-- return false;
|
||||||
|
-- end if;
|
||||||
|
-- end "=";
|
||||||
|
|
||||||
-- xor each element on the left with the corresponding element on the right
|
-- xor each element on the left with the corresponding element on the right
|
||||||
function "xor"(Left, Right : T_Array ) return T_Array is
|
function "xor"(Left, Right : T_Array ) return T_Array is
|
||||||
r : T_Array(Left'Range);
|
r : T_Array(Left'Range);
|
||||||
|
@ -174,6 +189,18 @@ package body Crypto_Generic_Types is
|
||||||
return r;
|
return r;
|
||||||
end "-";
|
end "-";
|
||||||
|
|
||||||
|
procedure Rotate_Array_Left(A : T_Array_Access; Amount : Natural) is
|
||||||
|
b : T;
|
||||||
|
begin
|
||||||
|
for i in 1 .. Amount loop
|
||||||
|
b := A(A'First);
|
||||||
|
for j in A'First .. A'Last - 1 loop
|
||||||
|
A(j) := A(j + 1);
|
||||||
|
end loop;
|
||||||
|
A(A'Last) := b;
|
||||||
|
end loop;
|
||||||
|
end;
|
||||||
|
|
||||||
function Rotate_Array_Left(A : T_Array; Amount : Natural) return T_Array is
|
function Rotate_Array_Left(A : T_Array; Amount : Natural) return T_Array is
|
||||||
r : T_Array(A'Range);
|
r : T_Array(A'Range);
|
||||||
x : Integer;
|
x : Integer;
|
||||||
|
@ -478,5 +505,14 @@ package body Crypto_Generic_Types is
|
||||||
end loop;
|
end loop;
|
||||||
end Store_le;
|
end Store_le;
|
||||||
|
|
||||||
|
-- swap two elements
|
||||||
|
procedure Swap(A, B : in out T) is
|
||||||
|
temp : T;
|
||||||
|
begin
|
||||||
|
temp := A;
|
||||||
|
A := B;
|
||||||
|
b := temp;
|
||||||
|
end swap;
|
||||||
|
|
||||||
end Crypto_Generic_Types;
|
end Crypto_Generic_Types;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@ generic
|
||||||
-- --------------------------
|
-- --------------------------
|
||||||
package Crypto_Generic_Types is
|
package Crypto_Generic_Types is
|
||||||
|
|
||||||
|
|
||||||
|
-- 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
|
-- xor each element on the left with the corresponding element on the right
|
||||||
function "xor"(Left, Right : T_Array ) return T_Array;
|
function "xor"(Left, Right : T_Array ) return T_Array;
|
||||||
-- xor the left element with each element on the right
|
-- xor the left element with each element on the right
|
||||||
|
@ -82,4 +85,7 @@ package Crypto_Generic_Types is
|
||||||
procedure Store_be(A : out u8_Array; value : in T);
|
procedure Store_be(A : out u8_Array; value : in T);
|
||||||
-- store a value in little-endian format in a byte Array
|
-- store a value in little-endian format in a byte Array
|
||||||
procedure Store_le(A : out u8_Array; value : in T);
|
procedure Store_le(A : out u8_Array; value : in T);
|
||||||
|
-- swap two elements
|
||||||
|
procedure Swap(A, B : in out T);
|
||||||
|
|
||||||
end Crypto_Generic_Types;
|
end Crypto_Generic_Types;
|
||||||
|
|
|
@ -3,11 +3,28 @@ with Crypto_Core_Types; use Crypto_Core_Types;
|
||||||
|
|
||||||
package Crypto_Types is
|
package Crypto_Types is
|
||||||
|
|
||||||
|
-- package Crypto_Types_u8 is new Crypto_Generic_Types(T => u8);
|
||||||
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);
|
||||||
|
|
||||||
|
-- subtype u8_Array is Crypto_Types_u8.T_Array;
|
||||||
package Crypto_Types_u16 is new Crypto_Generic_Types(T => u16, T_Array => u16_Array, T_Array_Access => u16_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_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 Crypto_Types_u64 is new Crypto_Generic_Types(T => u64, T_Array => u64_Array, T_Array_Access => u64_Array_Access);
|
||||||
|
|
||||||
|
-- subtype u8 is Crypto_Core_Types.u8;
|
||||||
|
-- subtype u16 is Crypto_Core_Types.u16;
|
||||||
|
-- subtype u32 is Crypto_Core_Types.u32;
|
||||||
|
-- subtype u64 is Crypto_Core_Types.u64;
|
||||||
|
--
|
||||||
|
-- subtype u8_Array is Crypto_Core_Types.u8_Array;
|
||||||
|
-- subtype u16_Array is Crypto_Core_Types.u16_Array;
|
||||||
|
-- subtype u32_Array is Crypto_Core_Types.u32_Array;
|
||||||
|
-- subtype u64_Array is Crypto_Core_Types.u64_Array;
|
||||||
|
--
|
||||||
|
-- subtype u8_Array_Access is Crypto_Core_Types.u8_Array_Access;
|
||||||
|
-- subtype u16_Array_Access is Crypto_Core_Types.u16_Array_Access;
|
||||||
|
-- subtype u32_Array_Access is Crypto_Core_Types.u32_Array_Access;
|
||||||
|
-- subtype u64_Array_Access is Crypto_Core_Types.u64_Array_Access;
|
||||||
-- use Crypto_Core_Types;
|
-- use Crypto_Core_Types;
|
||||||
-- use Crypto_Types_u8;
|
-- use Crypto_Types_u8;
|
||||||
-- use Crypto_Types_u16;
|
-- use Crypto_Types_u16;
|
||||||
|
|
|
@ -4,26 +4,27 @@ project Steelcrypt is
|
||||||
("Release", "Debug");
|
("Release", "Debug");
|
||||||
Mode : Build_Modes := external ("BUILD", "Debug");
|
Mode : Build_Modes := external ("BUILD", "Debug");
|
||||||
for Main use ("main.adb");
|
for Main use ("main.adb");
|
||||||
for Source_Dirs use ("src/**");
|
|
||||||
|
|
||||||
case Mode is
|
case Mode is
|
||||||
|
|
||||||
when "Debug" =>
|
|
||||||
for Object_Dir use "obj_debug";
|
|
||||||
|
|
||||||
when "Release" =>
|
when "Release" =>
|
||||||
|
for Source_Dirs use ("src/**", "/home/bg/workspace_steelcrypt/steelcrypt/src/sponge/spritz");
|
||||||
for Object_Dir use "obj_release";
|
for Object_Dir use "obj_release";
|
||||||
|
|
||||||
|
when "Debug" =>
|
||||||
|
for Source_Dirs use ("src/**", "/home/bg/workspace_steelcrypt/steelcrypt/src/sponge/spritz");
|
||||||
|
for Object_Dir use "obj_debug";
|
||||||
end case;
|
end case;
|
||||||
|
|
||||||
package Compiler is
|
package Compiler is
|
||||||
|
|
||||||
case Mode is
|
case Mode is
|
||||||
|
|
||||||
when "Debug" =>
|
|
||||||
for Default_Switches ("ada") use ("-g", "-gnato", "-gnatwa", "-gnatQ", "-gnat05");
|
|
||||||
|
|
||||||
when "Release" =>
|
when "Release" =>
|
||||||
for Default_Switches ("ada") use ("-gnatQ", "-gnatn", "-O2", "-gnat05");
|
for Default_Switches ("ada") use ("-gnatQ", "-gnatn", "-O2", "-gnat05");
|
||||||
|
|
||||||
|
when "Debug" =>
|
||||||
|
for Default_Switches ("ada") use ("-g", "-gnato", "-gnatwa", "-gnatQ", "-gnat05");
|
||||||
end case;
|
end case;
|
||||||
end Compiler;
|
end Compiler;
|
||||||
|
|
||||||
|
@ -31,11 +32,11 @@ project Steelcrypt is
|
||||||
|
|
||||||
case Mode is
|
case Mode is
|
||||||
|
|
||||||
when "Debug" =>
|
|
||||||
for Default_Switches ("ada") use ("-g");
|
|
||||||
|
|
||||||
when "Release" =>
|
when "Release" =>
|
||||||
for Default_Switches ("ada") use ();
|
for Default_Switches ("ada") use ();
|
||||||
|
|
||||||
|
when "Debug" =>
|
||||||
|
for Default_Switches ("ada") use ("-g");
|
||||||
end case;
|
end case;
|
||||||
end Builder;
|
end Builder;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue