Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
14cb92e7ab | |||
eebfedd810 | |||
4c1af8bbf3 |
15
.gitea/workflows/test.yaml
Normal file
15
.gitea/workflows/test.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
name: EC Utils Tests
|
||||||
|
run-name: ${{ gitea.actor }} testing EC Utils
|
||||||
|
on: [push, workflow_dispatch]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
runs-on: linux_amd64
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: test
|
||||||
|
run: |
|
||||||
|
. /opt/act_runner/erts/27.2/activate
|
||||||
|
./rebar3 dialyzer
|
||||||
|
./rebar3 eunit
|
@ -17,12 +17,12 @@ gen_scalar() ->
|
|||||||
?LET(N, gen_large_n(), <<N:256/little>>).
|
?LET(N, gen_large_n(), <<N:256/little>>).
|
||||||
|
|
||||||
gen_point() ->
|
gen_point() ->
|
||||||
?LET(S, gen_scalar(), enacl:crypto_ed25519_scalarmult_base_noclamp(S)).
|
?LET(S, gen_scalar(), enacl:curve25519_scalarmult_base_noclamp(S)).
|
||||||
|
|
||||||
prop_compress() ->
|
prop_compress() ->
|
||||||
?FORALL(S, gen_scalar(),
|
?FORALL(S, gen_scalar(),
|
||||||
begin
|
begin
|
||||||
CompP = enacl:crypto_ed25519_scalarmult_base_noclamp(S),
|
CompP = enacl:curve25519_scalarmult_base_noclamp(S),
|
||||||
DecP = ecu_ed25519:scalar_mul_base_noclamp(S),
|
DecP = ecu_ed25519:scalar_mul_base_noclamp(S),
|
||||||
equals(CompP, ecu_ed25519:compress(DecP))
|
equals(CompP, ecu_ed25519:compress(DecP))
|
||||||
end).
|
end).
|
||||||
@ -30,7 +30,7 @@ prop_compress() ->
|
|||||||
prop_decompress() ->
|
prop_decompress() ->
|
||||||
?FORALL(S, gen_scalar(),
|
?FORALL(S, gen_scalar(),
|
||||||
begin
|
begin
|
||||||
CompP = enacl:crypto_ed25519_scalarmult_base_noclamp(S),
|
CompP = enacl:curve25519_scalarmult_base_noclamp(S),
|
||||||
DecP = ecu_ed25519:scalar_mul_base_noclamp(S),
|
DecP = ecu_ed25519:scalar_mul_base_noclamp(S),
|
||||||
equal_pts(DecP, ecu_ed25519:decompress(CompP))
|
equal_pts(DecP, ecu_ed25519:decompress(CompP))
|
||||||
end).
|
end).
|
||||||
@ -70,7 +70,7 @@ prop_generate_valid_point() ->
|
|||||||
prop_scalar_mul_base() ->
|
prop_scalar_mul_base() ->
|
||||||
?FORALL(S, gen_scalar(),
|
?FORALL(S, gen_scalar(),
|
||||||
begin
|
begin
|
||||||
E = enacl:crypto_ed25519_scalarmult_base(S),
|
E = enacl:curve25519_scalarmult_base(S),
|
||||||
P = ecu_ed25519:scalar_mul_base(S),
|
P = ecu_ed25519:scalar_mul_base(S),
|
||||||
equals(E, ecu_ed25519:compress(P))
|
equals(E, ecu_ed25519:compress(P))
|
||||||
end).
|
end).
|
||||||
@ -78,7 +78,7 @@ prop_scalar_mul_base() ->
|
|||||||
prop_scalar_mul_base_noclamp() ->
|
prop_scalar_mul_base_noclamp() ->
|
||||||
?FORALL(S, gen_scalar(),
|
?FORALL(S, gen_scalar(),
|
||||||
begin
|
begin
|
||||||
E = enacl:crypto_ed25519_scalarmult_base_noclamp(S),
|
E = enacl:curve25519_scalarmult_base_noclamp(S),
|
||||||
P = ecu_ed25519:scalar_mul_base_noclamp(S),
|
P = ecu_ed25519:scalar_mul_base_noclamp(S),
|
||||||
equals(E, ecu_ed25519:compress(P))
|
equals(E, ecu_ed25519:compress(P))
|
||||||
end).
|
end).
|
||||||
@ -86,7 +86,7 @@ prop_scalar_mul_base_noclamp() ->
|
|||||||
prop_scalar_mul() ->
|
prop_scalar_mul() ->
|
||||||
?FORALL({S, P0}, {gen_scalar(), gen_point()},
|
?FORALL({S, P0}, {gen_scalar(), gen_point()},
|
||||||
begin
|
begin
|
||||||
E = enacl:crypto_ed25519_scalarmult(S, P0),
|
E = enacl:curve25519_scalarmult(S, P0),
|
||||||
P = ecu_ed25519:scalar_mul(S, P0),
|
P = ecu_ed25519:scalar_mul(S, P0),
|
||||||
equals(E, ecu_ed25519:compress(P))
|
equals(E, ecu_ed25519:compress(P))
|
||||||
end).
|
end).
|
||||||
@ -94,7 +94,7 @@ prop_scalar_mul() ->
|
|||||||
prop_scalar_mul_noclamp() ->
|
prop_scalar_mul_noclamp() ->
|
||||||
?FORALL({S, P0}, {gen_scalar(), gen_point()},
|
?FORALL({S, P0}, {gen_scalar(), gen_point()},
|
||||||
begin
|
begin
|
||||||
E = enacl:crypto_ed25519_scalarmult_noclamp(S, P0),
|
E = enacl:curve25519_scalarmult_noclamp(S, P0),
|
||||||
P = ecu_ed25519:scalar_mul_noclamp(S, ecu_ed25519:decompress(P0)),
|
P = ecu_ed25519:scalar_mul_noclamp(S, ecu_ed25519:decompress(P0)),
|
||||||
equals(E, ecu_ed25519:compress(P))
|
equals(E, ecu_ed25519:compress(P))
|
||||||
end).
|
end).
|
||||||
|
@ -20,7 +20,7 @@ gen_scalar() ->
|
|||||||
?LET(N, gen_large_n(), <<N:256/little>>).
|
?LET(N, gen_large_n(), <<N:256/little>>).
|
||||||
|
|
||||||
gen_point() ->
|
gen_point() ->
|
||||||
?LET(S, gen_scalar(), enacl:crypto_ed25519_scalarmult_base_noclamp(S)).
|
?LET(S, gen_scalar(), enacl:curve25519_scalarmult_base_noclamp(S)).
|
||||||
|
|
||||||
prop_keypair_seed() ->
|
prop_keypair_seed() ->
|
||||||
?FORALL(Seed, binary(32),
|
?FORALL(Seed, binary(32),
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
[{sha3,
|
[{sha3,
|
||||||
{git,
|
{git,
|
||||||
"https://git.qpq.swiss/QPQ-AG/erlang-sha3.git",
|
"https://git.qpq.swiss/QPQ-AG/erlang-sha3.git",
|
||||||
{ref, "77c4e048aea75bd0bc2b5ca6cb02b7230d081c71"}}}]}.
|
{ref, "7290fa23664b4134d15da353061ac97aa158b332"}}}]}.
|
||||||
|
|
||||||
{profiles,
|
{profiles,
|
||||||
[{test,
|
[{test,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{<<"sha3">>,
|
{<<"sha3">>,
|
||||||
{git,
|
{git,
|
||||||
"https://git.qpq.swiss/QPQ-AG/erlang-sha3.git",
|
"https://git.qpq.swiss/QPQ-AG/erlang-sha3.git",
|
||||||
{ref,"77c4e048aea75bd0bc2b5ca6cb02b7230d081c71"}},
|
{ref, "7290fa23664b4134d15da353061ac97aa158b332"}},
|
||||||
0}]}.
|
0}]}.
|
||||||
[
|
[
|
||||||
{pkg_hash,[
|
{pkg_hash,[
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
keccak256/1]).
|
keccak256/1]).
|
||||||
|
|
||||||
private_to_short(bitcoin, PrivateKey) ->
|
private_to_short(bitcoin, PrivateKey) ->
|
||||||
public_to_short(bitcoin, aeu_ecdsa:private_to_public(secp256k1, PrivateKey));
|
public_to_short(bitcoin, ecu_ecdsa:private_to_public(secp256k1, PrivateKey));
|
||||||
private_to_short(ethereum, <<PrivateKey:256>>) ->
|
private_to_short(ethereum, <<PrivateKey:256>>) ->
|
||||||
public_to_short(ethereum, ecu_secp256k1:scalar_mul_base(PrivateKey)).
|
public_to_short(ethereum, ecu_secp256k1:scalar_mul_base(PrivateKey)).
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ gen_scalar() ->
|
|||||||
1 + X rem (ecu_ed25519:n() - 1).
|
1 + X rem (ecu_ed25519:n() - 1).
|
||||||
|
|
||||||
bench_point_add_test() ->
|
bench_point_add_test() ->
|
||||||
Pts = [ enacl:crypto_ed25519_scalarmult_base(<<(gen_scalar()):256/little>>) || _ <- lists:seq(1, 100) ],
|
Pts = [ enacl:curve25519_scalarmult_base(<<(gen_scalar()):256/little>>) || _ <- lists:seq(1, 100) ],
|
||||||
|
|
||||||
PtsEnacl0 = lists:zip(Pts, tl(Pts) ++ [hd(Pts)]),
|
PtsEnacl0 = lists:zip(Pts, tl(Pts) ++ [hd(Pts)]),
|
||||||
PtsEd255190 = [ {ecu_ed25519:to_ext_hom(P1), ecu_ed25519:to_ext_hom(P2)} || {P1, P2} <- lists:zip(Pts, tl(Pts) ++ [hd(Pts)]) ],
|
PtsEd255190 = [ {ecu_ed25519:to_ext_hom(P1), ecu_ed25519:to_ext_hom(P2)} || {P1, P2} <- lists:zip(Pts, tl(Pts) ++ [hd(Pts)]) ],
|
||||||
@ -39,7 +39,7 @@ bench_scalar_mul_base_test() ->
|
|||||||
ScalarsEd25519 = lists:append(lists:duplicate(30, Scalars0)),
|
ScalarsEd25519 = lists:append(lists:duplicate(30, Scalars0)),
|
||||||
|
|
||||||
{TimeSecp, _} = timer:tc(fun() -> [ecu_secp256k1:scalar_mul_base(S) || S <- ScalarsSecp], ok end),
|
{TimeSecp, _} = timer:tc(fun() -> [ecu_secp256k1:scalar_mul_base(S) || S <- ScalarsSecp], ok end),
|
||||||
{TimeEnacl, _} = timer:tc(fun() -> [enacl:crypto_ed25519_scalarmult_base(S) || S <- ScalarsEnacl], ok end),
|
{TimeEnacl, _} = timer:tc(fun() -> [enacl:curve25519_scalarmult_base(S) || S <- ScalarsEnacl], ok end),
|
||||||
{TimeEd25519, _} = timer:tc(fun() -> [ecu_ed25519:scalar_mul_base(S) || S <- ScalarsEd25519], ok end),
|
{TimeEd25519, _} = timer:tc(fun() -> [ecu_ed25519:scalar_mul_base(S) || S <- ScalarsEd25519], ok end),
|
||||||
|
|
||||||
?debugFmt("", []),
|
?debugFmt("", []),
|
||||||
@ -58,7 +58,7 @@ bench_scalar_mul_test() ->
|
|||||||
Test = fun(F, P0, Ss) -> lists:foldl(fun(S, P) -> F(S, P) end, P0, Ss) end,
|
Test = fun(F, P0, Ss) -> lists:foldl(fun(S, P) -> F(S, P) end, P0, Ss) end,
|
||||||
|
|
||||||
{TimeSecp, _} = timer:tc(fun() -> Test(fun ecu_secp256k1:scalar_mul/2, ecu_secp256k1:scalar_mul_base(hd(ScalarsSecp)), tl(ScalarsSecp)) end),
|
{TimeSecp, _} = timer:tc(fun() -> Test(fun ecu_secp256k1:scalar_mul/2, ecu_secp256k1:scalar_mul_base(hd(ScalarsSecp)), tl(ScalarsSecp)) end),
|
||||||
{TimeEnacl, _} = timer:tc(fun() -> Test(fun enacl:crypto_ed25519_scalarmult/2, enacl:crypto_ed25519_scalarmult_base(hd(ScalarsEnacl)), tl(ScalarsEnacl)) end),
|
{TimeEnacl, _} = timer:tc(fun() -> Test(fun enacl:curve25519_scalarmult/2, enacl:curve25519_scalarmult_base(hd(ScalarsEnacl)), tl(ScalarsEnacl)) end),
|
||||||
{TimeEd25519, _} = timer:tc(fun() -> Test(fun ecu_ed25519:scalar_mul/2, ecu_ed25519:scalar_mul_base(hd(ScalarsEd25519)), tl(ScalarsEd25519)) end),
|
{TimeEd25519, _} = timer:tc(fun() -> Test(fun ecu_ed25519:scalar_mul/2, ecu_ed25519:scalar_mul_base(hd(ScalarsEd25519)), tl(ScalarsEd25519)) end),
|
||||||
|
|
||||||
?debugFmt("", []),
|
?debugFmt("", []),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user