inital commit of type system

This commit is contained in:
bg nerilex 2015-06-10 19:46:28 +02:00
parent 5bf74b29d2
commit 71b0945e0e
5 changed files with 98 additions and 38 deletions

View File

@ -19,9 +19,9 @@ package Crypto_Core_Types is
type u32_Array is Array (Integer range <>) of u32;
type u64_Array is Array (Integer range <>) of u64;
type u8_Array_Access is access u8_Array;
type u16_Array_Access is access u16_Array;
type u32_Array_Access is access u32_Array;
type u64_Array_Access is access u64_Array;
type u8_Array_Access is access all u8_Array;
type u16_Array_Access is access all u16_Array;
type u32_Array_Access is access all u32_Array;
type u64_Array_Access is access all u64_Array;
end Crypto_Core_Types;

View File

@ -1,5 +1,3 @@
with Crypto_Core_Types; use Crypto_Core_Types;
-- --------------------------
-- - Generic Functions / Procedures -
-- --------------------------
@ -9,6 +7,23 @@ with Crypto_Core_Types; use Crypto_Core_Types;
-- --------------------------
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
function "xor"(Left, Right : T_Array ) return T_Array is
r : T_Array(Left'Range);
@ -174,6 +189,18 @@ package body Crypto_Generic_Types is
return r;
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
r : T_Array(A'Range);
x : Integer;
@ -478,5 +505,14 @@ package body Crypto_Generic_Types is
end loop;
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;

View File

@ -32,6 +32,9 @@ generic
-- --------------------------
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
function "xor"(Left, Right : T_Array ) return T_Array;
-- 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);
-- store a value in little-endian format in a byte Array
procedure Store_le(A : out u8_Array; value : in T);
-- swap two elements
procedure Swap(A, B : in out T);
end Crypto_Generic_Types;

View File

@ -3,11 +3,28 @@ with Crypto_Core_Types; use Crypto_Core_Types;
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);
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_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);
-- 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_Types_u8;
-- use Crypto_Types_u16;

View File

@ -1,45 +1,46 @@
project Steelcrypt is
type Build_Modes is
("Release", "Debug");
Mode : Build_Modes := external ("BUILD", "Debug");
for Main use ("main.adb");
for Source_Dirs use ("src/**");
type Build_Modes is
("Release", "Debug");
Mode : Build_Modes := external ("BUILD", "Debug");
for Main use ("main.adb");
case Mode is
case Mode is
when "Debug" =>
for Object_Dir use "obj_debug";
when "Release" =>
for Source_Dirs use ("src/**", "/home/bg/workspace_steelcrypt/steelcrypt/src/sponge/spritz");
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;
package Compiler is
case Mode is
when "Release" =>
for Object_Dir use "obj_release";
end case;
for Default_Switches ("ada") use ("-gnatQ", "-gnatn", "-O2", "-gnat05");
package Compiler is
when "Debug" =>
for Default_Switches ("ada") use ("-g", "-gnato", "-gnatwa", "-gnatQ", "-gnat05");
end case;
end Compiler;
case Mode is
package Builder is
when "Debug" =>
for Default_Switches ("ada") use ("-g", "-gnato", "-gnatwa", "-gnatQ", "-gnat05");
case Mode is
when "Release" =>
for Default_Switches ("ada") use ("-gnatQ", "-gnatn", "-O2", "-gnat05");
end case;
end Compiler;
when "Release" =>
for Default_Switches ("ada") use ();
package Builder is
when "Debug" =>
for Default_Switches ("ada") use ("-g");
end case;
end Builder;
case Mode is
when "Debug" =>
for Default_Switches ("ada") use ("-g");
when "Release" =>
for Default_Switches ("ada") use ();
end case;
end Builder;
package Ide is
end Ide;
package Ide is
end Ide;
end Steelcrypt;