Browse Source

initial commit - types seem to work to some degree

master
bg nerilex 5 years ago
commit
5bf74b29d2
10 changed files with 1138 additions and 0 deletions
  1. +37
    -0
      Makefile
  2. +21
    -0
      src/block_cipher/aes/aes.adb
  3. +8
    -0
      src/block_cipher/aes/aes.ads
  4. +27
    -0
      src/crypto_core_types.ads
  5. +482
    -0
      src/crypto_generic_types.adb
  6. +85
    -0
      src/crypto_generic_types.ads
  7. +18
    -0
      src/crypto_types.ads
  8. +64
    -0
      src/main.adb
  9. +351
    -0
      src/tmp.txt
  10. +45
    -0
      steelcrypt.gpr

+ 37
- 0
Makefile View File

@@ -0,0 +1,37 @@
# You may edit this makefile as long as you keep these original
# target names defined. You can change the recipes and/or add new targets.

# Not intended for manual invocation.
# Invoked if automatic builds are enabled.
# Analyzes only on those sources that have changed.
# Does not build executables.
autobuild:
$(GNATMAKE) -gnatc -c -k -d -P "$(GPRPATH)"

# Clean the root project of all build products.
clean:
$(GNATCLEAN) -P "$(GPRPATH)"

# Clean root project and all imported projects too.
clean_tree:
$(GNATCLEAN) -P "$(GPRPATH)" -r

# Check project sources for errors.
# Does not build executables.
analyze:
$(GNATMAKE) -d -gnatc -c -k -P "$(GPRPATH)"

# Build executables for all mains defined by the project.
build:
$(GNATMAKE) -d -P "$(GPRPATH)"

# Clean, then build executables for all mains defined by the project.
rebuild: clean build

# Compile individual file.
compile_file:
$(GNATMAKE) -d -ws -c -u -P "$(GPRPATH)" "$(FILE)"

# Analyze individual file (no object code generated).
analyze_file:
$(GNATMAKE) -d -q -c -gnatc -u -P "$(GPRPATH)" "$(FILE)"

+ 21
- 0
src/block_cipher/aes/aes.adb View File

@@ -0,0 +1,21 @@
package body AES is

function gf256mul(a, b : u8) return u8 is
r : u8 := 0;
t1 : u8 := a;
t2 : u8 := b;
begin
for i in 1 .. 8 loop
if (t1 and 1) = 1 then
r := r xor t2;
end if;
t1 := Shift_Right(t1, 1);
if (t2 and 16#80#) = 16#80# then
t2 := t2 xor polynom;
end if;
t2 := Shift_Left(t2, 1);
end loop;
return r;
end gf256mul;

end AES;

+ 8
- 0
src/block_cipher/aes/aes.ads View File

@@ -0,0 +1,8 @@
with Crypto_Types; use Crypto_Types;

package AES is

private
polynom : constant u8 := 16#1B#;
function gf256mul(a, b : u8) return u8;
end AES;

+ 27
- 0
src/crypto_core_types.ads View File

@@ -0,0 +1,27 @@
with Interfaces; use Interfaces;

package Crypto_Core_Types is

type u8 is new Unsigned_8;
for u8'Size use 8;

type u16 is new Unsigned_16;
for u16'Size use 16;

type u32 is new Unsigned_32;
for u32'Size use 32;

type u64 is new Unsigned_64;
for u64'Size use 64;

type u8_Array is Array (Integer range <>) of u8;
type u16_Array is Array (Integer range <>) of u16;
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;

end Crypto_Core_Types;

+ 482
- 0
src/crypto_generic_types.adb View File

@@ -0,0 +1,482 @@
with Crypto_Core_Types; use Crypto_Core_Types;

-- --------------------------
-- - Generic Functions / Procedures -
-- --------------------------

-- --------------------------
-- - Functions / Procedures -
-- --------------------------
package body Crypto_Generic_Types is

-- 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);
begin
if Left'Length /= Right'Length then
raise Constraint_Error;
end if;
for i in r'Range loop
r(i) := Left(i) xor Right(Right'First - Left'First + i);
end loop;
return r;
end "xor";

-- xor the left element with each element on the right
function "xor"(Left : T; Right : T_Array ) return T is
r : T := Left;
begin
for i in Right'Range loop
r := r xor Right(i);
end loop;
return r;
end "xor";

-- xor each element on the left with the element on the right
function "xor"(Left : T_Array; Right : T ) return T_Array is
r : T_Array(Left'Range);
begin
for i in r'Range loop
r(i) := Left(i) xor Right;
end loop;
return r;
end "xor";

-- and each element on the left with the corresponding element on the right
function "and"(Left, Right : T_Array ) return T_Array is
r : T_Array(Left'Range);
begin
if Left'Length /= Right'Length then
raise Constraint_Error;
end if;
for i in r'Range loop
r(i) := Left(i) and Right(Right'First - Left'First + i);
end loop;
return r;
end "and";

-- and the left element with each element on the right
function "and"(Left : T; Right : T_Array ) return T is
r : T := Left;
begin
for i in Right'Range loop
r := r and Right(i);
end loop;
return r;
end "and";

-- and each element on the left with the element on the right
function "and"(Left : T_Array; Right : T ) return T_Array is
r : T_Array(Left'Range);
begin
for i in r'Range loop
r(i) := Left(i) and Right;
end loop;
return r;
end "and";

-- or each element on the left with the corresponding element on the right
function "or"(Left, Right : T_Array ) return T_Array is
r : T_Array(Left'Range);
begin
if Left'Length /= Right'Length then
raise Constraint_Error;
end if;
for i in r'Range loop
r(i) := Left(i) or Right(Right'First - Left'First + i);
end loop;
return r;
end "or";

-- or the left element with each element on the right
function "or"(Left : T; Right : T_Array ) return T is
r : T := Left;
begin
for i in Right'Range loop
r := r or Right(i);
end loop;
return r;
end "or";

-- or each element on the left with the element on the right
function "or"(Left : T_Array; Right : T ) return T_Array is
r : T_Array(Left'Range);
begin
for i in r'Range loop
r(i) := Left(i) or Right;
end loop;
return r;
end "or";

-- add each element on the left with the corresponding element on the right
function "+"(Left, Right : T_Array ) return T_Array is
r : T_Array(Left'Range);
begin
if Left'Length /= Right'Length then
raise Constraint_Error;
end if;
for i in r'Range loop
r(i) := Left(i) + Right(Right'First - Left'First + i);
end loop;
return r;
end "+";

-- add the left element with each element on the right
function "+"(Left : T; Right : T_Array ) return T is
r : T := Left;
begin
for i in Right'Range loop
r := r + Right(i);
end loop;
return r;
end "+";

-- add each element on the left with the element on the right
function "+"(Left : T_Array; Right : T ) return T_Array is
r : T_Array(Left'Range);
begin
for i in r'Range loop
r(i) := Left(i) + Right;
end loop;
return r;
end "+";

-- subtract from each element on the left the corresponding element on the right
function "-"(Left, Right : T_Array ) return T_Array is
r : T_Array(Left'Range);
begin
if Left'Length /= Right'Length then
raise Constraint_Error;
end if;
for i in r'Range loop
r(i) := Left(i) - Right(Right'First - Left'First + i);
end loop;
return r;
end "-";

-- subtract from the left element each element on the right
function "-"(Left : T; Right : T_Array ) return T is
r : T := Left;
begin
for i in Right'Range loop
r := r - Right(i);
end loop;
return r;
end "-";

-- subtract from each element on the left the element on the right
function "-"(Left : T_Array; Right : T ) return T_Array is
r : T_Array(Left'Range);
begin
for i in r'Range loop
r(i) := Left(i) - Right;
end loop;
return r;
end "-";

function Rotate_Array_Left(A : T_Array; Amount : Natural) return T_Array is
r : T_Array(A'Range);
x : Integer;
begin
x := Amount mod r'Length;
if A'Length < 1 then
raise Constraint_Error;
end if;
r(r'First .. r'Last - x) := A(A'First + x .. A'Last);
r(r'Last - x + 1 .. r'Last) := A(A'First .. A'First + x - 1);
return r;
end Rotate_Array_Left;

function Rotate_Array_Right(A : T_Array; Amount : Natural) return T_Array is
r : T_Array(A'Range);
x : Integer;
begin
x := Amount mod r'Length;
if A'Length < 1 then
raise Constraint_Error;
end if;
r(r'First + x .. r'Last) := A(A'First .. A'Last - x);
r(r'First .. r'First + x - 1) := A(A'Last - x + 1 .. A'Last);
return r;
end Rotate_Array_Right;

function Shift_Array_Left(A : T_Array; Amount : Natural) return T_Array is
r : T_Array(A'Range);
x : Integer;
begin
x := Amount mod r'Length;
if A'Length < 1 then
raise Constraint_Error;
end if;
r(r'First .. r'Last - x) := A(A'First + x .. A'Last);
for i in (r'Last - x + 1) .. r'Last loop
r(i) := 0;
end loop;
return r;
end Shift_Array_Left;

function Shift_Array_Right(A : T_Array; Amount : Natural) return T_Array is
r : T_Array(A'Range);
x : Integer;
begin
x := Amount mod r'Length;
if A'Length < 1 then
raise Constraint_Error;
end if;
r(r'First + x .. r'Last) := A(A'First .. A'Last - x);
for i in r'First .. (r'First + x - 1) loop
r(i) := 0;
end loop;
return r;
end Shift_Array_Right;

-- 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 is
r : T_Array(A'Range);
c1, c2, tmp : T;
x : Integer;
word_rot : Integer;
bit_rot : Integer;
reverse_bit_rot : Integer;
begin
x := Amount mod (A'Length * T'Size);
word_rot := x / T'Size;
bit_rot := x mod T'Size;
if word_rot > 0 then
r := Rotate_Array_Left(A => A, Amount => Natural(abs word_rot));
else
r := Rotate_Array_Right(A => A, Amount => Natural(word_rot));
end if;
-- if bit rotation goes to the left
if bit_rot > 0 then
reverse_bit_rot := T'Size - bit_rot;
c1 := Shift_Right(r(r'First), reverse_bit_rot);
for i in reverse r'Range loop
c2 := Shift_Right(r(i), reverse_bit_rot);
tmp := Shift_Left(r(i), bit_rot);
r(i) := tmp or c1;
c1 := c2;
end loop;
end if;
-- if bit rotation goes to the right
if bit_rot < 0 then
bit_rot := -bit_rot;
reverse_bit_rot := T'Size - bit_rot;
c1 := Shift_Left(r(r'Last), reverse_bit_rot);
for i in r'Range loop
c2 := Shift_Left(r(i), reverse_bit_rot);
tmp := Shift_Right(r(i), bit_rot);
r(i) := tmp or c1;
c1 := c2;
end loop;
end if;
return r;
end Rotate_be;

-- 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 is
r : T_Array(A'Range);
c1, c2, tmp : T;
x : Integer;
word_rot : Integer;
bit_rot : Integer;
reverse_bit_rot : Integer;
begin
x := Amount mod (A'Length * T'Size);
word_rot := x / T'Size;
bit_rot := x mod T'Size;
if word_rot < 0 then
r := Rotate_Array_Left(A => A, Amount => Natural(abs word_rot));
else
r := Rotate_Array_Right(A => A, Amount => Natural(word_rot));
end if;
-- if bit rotation goes to the left
if bit_rot > 0 then
reverse_bit_rot := T'Size - bit_rot;
c1 := Shift_Right(r(r'Last), reverse_bit_rot);
for i in r'Range loop
c2 := Shift_Right(r(i), reverse_bit_rot);
tmp := Shift_Left(r(i), bit_rot);
r(i) := tmp or c1;
c1 := c2;
end loop;
end if;
-- if bit rotation goes to the right
if bit_rot < 0 then
bit_rot := -bit_rot;
reverse_bit_rot := T'Size - bit_rot;
c1 := Shift_Left(r(r'First), reverse_bit_rot);
for i in reverse r'Range loop
c2 := Shift_Left(r(i), reverse_bit_rot);
tmp := Shift_Right(r(i), bit_rot);
r(i) := tmp or c1;
c1 := c2;
end loop;
end if;
return r;
end Rotate_le;

-- 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 is
r : T_Array(A'Range);
begin
if Amount > 0 then
for i in r'Range loop
r(i) := Rotate_Left(A(i), Natural(Amount));
end loop;
end if;
if Amount < 0 then
for i in r'Range loop
r(i) := Rotate_Right(A(i), Natural(-Amount));
end loop;
end if;
if Amount = 0 then
r := A;
end if;
return r;
end Rotate_each;


-- 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 is
r : T_Array(A'Range);
word_shift : Integer;
bit_shift : Integer;
reverse_bit_shift : Integer;
c1, c2 : T := 0;
begin
-- left shift
if Amount > 0 then
word_shift := Amount / T'Size;
bit_shift := Amount mod T'Size;
reverse_bit_shift := T'Size - bit_shift;
r := Shift_Array_Left(A => A, Amount => word_shift);
for i in reverse r'Range loop
c2 := Shift_Right(Value => r(i), Amount => reverse_bit_shift);
r(i) := Shift_Left(Value => r(i), Amount => bit_shift) or c1;
c1 := c2;
end loop;
end if;
-- right shift
if Amount < 0 then
word_shift := (-Amount) / T'Size;
bit_shift := (-Amount) mod T'Size;
reverse_bit_shift := T'Size - bit_shift;
r := Shift_Array_Right(A => A, Amount => word_shift);
for i in r'Range loop
c2 := Shift_Left(Value => r(i), Amount => reverse_bit_shift);
r(i) := Shift_Right(Value => r(i), Amount => bit_shift) or c1;
c1 := c2;
end loop;
end if;
if Amount = 0 then
r := A;
end if;
return r;
end Shift_be;


-- 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 is
r : T_Array(A'Range);
word_shift : Integer;
bit_shift : Integer;
reverse_bit_shift : Integer;
c1, c2 : T := 0;
begin
-- left shift
if Amount > 0 then
word_shift := Amount / T'Size;
bit_shift := Amount mod T'Size;
reverse_bit_shift := T'Size - bit_shift;
r := Shift_Array_Right(A => A, Amount => word_shift);
for i in r'Range loop
c2 := Shift_Right(Value => r(i), Amount => reverse_bit_shift);
r(i) := Shift_Left(Value => r(i), Amount => bit_shift) or c1;
c1 := c2;
end loop;
end if;
-- right shift
if Amount < 0 then
word_shift := (-Amount) / T'Size;
bit_shift := (-Amount) mod T'Size;
reverse_bit_shift := T'Size - bit_shift;
r := Shift_Array_Left(A => A, Amount => word_shift);
for i in reverse r'Range loop
c2 := Shift_Left(Value => r(i), Amount => reverse_bit_shift);
r(i) := Shift_Right(Value => r(i), Amount => bit_shift) or c1;
c1 := c2;
end loop;
end if;
if Amount = 0 then
r := A;
end if;
return r;
end Shift_le;

-- 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 is
r : T_Array(A'Range);
begin
if Amount > 0 then
for i in r'Range loop
r(i) := Shift_Left(A(i), Natural(Amount));
end loop;
end if;
if Amount < 0 then
for i in r'Range loop
r(i) := Shift_Right(A(i), Natural(-Amount));
end loop;
end if;
if Amount = 0 then
r := A;
end if;
return r;
end Shift_each;

-- load a value which is stored big-endian in byte Array
function Load_be(A : u8_Array) return T is
r : T := 0;
begin
for i in 0 .. (T'Size / 8 - 1) loop
r := Shift_left(r, 8) or T(A(A'First + i));
end loop;
return r;
end Load_be;

-- load a value which is stored little-endian in byte Array
function Load_le (A : u8_Array) return T is
r : T := 0;
begin
for i in reverse 0 .. (T'Size / 8 - 1) loop
r := Shift_left(r, 8) or T(A(A'First + i));
end loop;
return r;
end Load_le;

-- store a value in big-endian format in a byte Array
procedure Store_be(A : out u8_Array; value : in T) is
x : T := value;
b : u8;
begin
for i in reverse 0 .. (T'Size / 8 - 1) loop
b := u8(x and 16#FF#);
A(A'FIrst + i) := b;
x := Shift_Right(x, 8);
end loop;
end Store_be;

-- store a value in little-endian format in a byte Array
procedure Store_le(A : out u8_Array; value : in T) is
x : T := value;
b : u8;
begin
for i in 0 .. (T'Size / 8 - 1) loop
b := u8(x and 16#FF#);
A(A'FIrst + i) := b;
x := Shift_Right(x, 8);
end loop;
end Store_le;

end Crypto_Generic_Types;


+ 85
- 0
src/crypto_generic_types.ads View File

@@ -0,0 +1,85 @@
with Crypto_Core_Types; use Crypto_Core_Types;

-- --------------------------
-- - Generic Functions / Procedures -
-- --------------------------

generic
type T is mod <>;

with function Shift_Left
(Value : T;
Amount : Natural) return T is <>;

with function Shift_Right
(Value : T;
Amount : Natural) return T is <>;

with function Rotate_Left
(Value : T;
Amount : Natural) return T is <>;

with function Rotate_Right
(Value : T;
Amount : Natural) return T is <>;

type T_Array is Array (Integer range <>) of T;

type T_Array_Access is access T_Array;

-- --------------------------
-- - Functions / Procedures -
-- --------------------------
package Crypto_Generic_Types is

-- 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;
-- load a value which is stored little-endian in byte Array
function Load_le(A : u8_Array) return T;
-- 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);
end Crypto_Generic_Types;

+ 18
- 0
src/crypto_types.ads View File

@@ -0,0 +1,18 @@
with Crypto_Generic_Types;
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_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);

-- use Crypto_Core_Types;
-- use Crypto_Types_u8;
-- use Crypto_Types_u16;
-- use Crypto_Types_u32;
-- use Crypto_Types_u64;


end Crypto_Types;

+ 64
- 0
src/main.adb View File

@@ -0,0 +1,64 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Crypto_Types; use Crypto_Types;
with Crypto_Core_Types; use Crypto_Core_Types;

use Crypto_Types.Crypto_Types_u8;


procedure main is

procedure print_hex(value : in u8) is
hex_table : constant array (0 .. 15) of Character :=
( '0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F');
begin
Put(hex_table(Integer(Shift_Right(value, 4))));
Put(hex_table(Integer(value and 16#F#)));
end;

procedure print_array_hex(A : in u8_Array) is
begin
for i in A'Range loop
print_hex(A(i));
Put(' ');
end loop;
end;

a, b : u8_Array(0 .. 255);
begin
for i in a'Range loop
a(i) := u8(i);
b(i) := u8(i);
end loop;

print_array_hex(a);
New_Line;
print_array_hex(b);
New_Line;
New_Line;

for i in 1 .. a'Length * u8'Size loop
a := Rotate_be(A => a, Amount => 1);
Put("a: ");
print_array_hex(a);
New_Line;
b := Rotate_be(A => b, Amount => i);
Put("b: ");
print_array_hex(b);
New_Line;
if (a /= b) then
Put("Error @ i=");
Put(i);
New_Line;
end if;
b := Rotate_be(A => b, Amount => -i);
Put("b': ");
print_array_hex(b);
New_Line;
end loop;

New_Line;
end main;

+ 351
- 0
src/tmp.txt View File

@@ -0,0 +1,351 @@
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);

+ 45
- 0
steelcrypt.gpr View File

@@ -0,0 +1,45 @@
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/**");

case Mode is

when "Debug" =>
for Object_Dir use "obj_debug";

when "Release" =>
for Object_Dir use "obj_release";
end case;

package Compiler is

case Mode is

when "Debug" =>
for Default_Switches ("ada") use ("-g", "-gnato", "-gnatwa", "-gnatQ", "-gnat05");

when "Release" =>
for Default_Switches ("ada") use ("-gnatQ", "-gnatn", "-O2", "-gnat05");
end case;
end Compiler;

package Builder is

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;

end Steelcrypt;

Loading…
Cancel
Save