Skip to content

Commit

Permalink
Move some functions from cryptography to mnemonics where it makes mor…
Browse files Browse the repository at this point in the history
…e sense
  • Loading branch information
AntonMeep committed Feb 13, 2022
1 parent ae78e24 commit a45c373
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
12 changes: 0 additions & 12 deletions source/cryptography.adb
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,6 @@ package body Cryptography is
return Result;
end From_Seed;

function Is_Basic_Seed (Entropy : Byte_Array) return Boolean is
(PBKDF2_SHA512
(Entropy, "TON seed version",
Natural'Max
(1, Natural (Float'Floor (Float (PBKDF_ITERATIONS) / 256.0))))
(1) =
0);
function Is_Password_Seed (Entropy : Byte_Array) return Boolean is
(PBKDF2_SHA512 (Entropy, "TON fast seed version", 1) (1) = 1);
function Is_Password_Needed (Entropy : Byte_Array) return Boolean is
(Is_Password_Seed (Entropy) and not Is_Basic_Seed (Entropy));

use Interfaces.C;
type uchar_array is array (Natural range <>) of aliased unsigned_char;

Expand Down
4 changes: 0 additions & 4 deletions source/cryptography.ads
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ package Cryptography is

function From_Seed (Seed : Byte_Array) return Key_Pair;

function Is_Basic_Seed (Entropy : Byte_Array) return Boolean;
function Is_Password_Seed (Entropy : Byte_Array) return Boolean;
function Is_Password_Needed (Entropy : Byte_Array) return Boolean;

function Get_Random return Unsigned_32;
function Get_Random (Length : Positive) return Unsigned_16_Array;
end Cryptography;
12 changes: 12 additions & 0 deletions source/mnemonics.adb
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,16 @@ package body Mnemonics is
function To_Key_Pair
(This : Mnemonic; Password : String := "") return Key_Pair is
(From_Seed (To_Seed (This, Password)));

function Is_Basic_Seed (Entropy : Byte_Array) return Boolean is
(PBKDF2_SHA512
(Entropy, "TON seed version",
Natural'Max
(1, Natural (Float'Floor (Float (PBKDF_ITERATIONS) / 256.0))))
(1) =
0);
function Is_Password_Seed (Entropy : Byte_Array) return Boolean is
(PBKDF2_SHA512 (Entropy, "TON fast seed version", 1) (1) = 1);
function Is_Password_Needed (Entropy : Byte_Array) return Boolean is
(Is_Password_Seed (Entropy) and not Is_Basic_Seed (Entropy));
end Mnemonics;
3 changes: 3 additions & 0 deletions source/mnemonics.ads
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ package Mnemonics is
(This : Mnemonic; Password : String := "") return Byte_Array;
function To_Key_Pair
(This : Mnemonic; Password : String := "") return Key_Pair;
function Is_Basic_Seed (Entropy : Byte_Array) return Boolean;
function Is_Password_Seed (Entropy : Byte_Array) return Boolean;
function Is_Password_Needed (Entropy : Byte_Array) return Boolean;
end Mnemonics;

0 comments on commit a45c373

Please sign in to comment.