Compare commits

...

5 Commits

Author SHA1 Message Date
zxq9 14cb92e7ab Adding a package prep script
EC Utils Tests / tests (push) Failing after -4m5s
2025-01-23 21:48:28 +09:00
zxq9 eebfedd810 Updating sha3 dep (but dialyzer still can't find it?)
EC Utils Tests / tests (push) Failing after -4m8s
2025-01-23 15:27:13 +09:00
zxq9 4c1af8bbf3 Add tests
EC Utils Tests / tests (push) Failing after -4m8s
2025-01-23 15:01:38 +09:00
zxq9 30944928da Update zx meta 2025-01-23 14:32:20 +09:00
zxq9 0c36c788ed Update deps 2025-01-23 14:29:01 +09:00
17 changed files with 87 additions and 45 deletions
+15
View 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
+1 -1
View File
@@ -3,7 +3,7 @@
{registered,[]},
{included_applications,[]},
{applications,[stdlib,kernel]},
{vsn,"1.0.0"},
{vsn,"1.0.1"},
{modules,[ecu_crypto_eqc,ed25519_eqc,eddsa_eqc,ec_utils,
ecu_crypto,ecu_ecdsa,ecu_ed25519,ecu_eddsa,ecu_misc,
ecu_secp256k1,benchmark_tests,crypto_tests,
+7 -7
View File
@@ -17,12 +17,12 @@ gen_scalar() ->
?LET(N, gen_large_n(), <<N:256/little>>).
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() ->
?FORALL(S, gen_scalar(),
begin
CompP = enacl:crypto_ed25519_scalarmult_base_noclamp(S),
CompP = enacl:curve25519_scalarmult_base_noclamp(S),
DecP = ecu_ed25519:scalar_mul_base_noclamp(S),
equals(CompP, ecu_ed25519:compress(DecP))
end).
@@ -30,7 +30,7 @@ prop_compress() ->
prop_decompress() ->
?FORALL(S, gen_scalar(),
begin
CompP = enacl:crypto_ed25519_scalarmult_base_noclamp(S),
CompP = enacl:curve25519_scalarmult_base_noclamp(S),
DecP = ecu_ed25519:scalar_mul_base_noclamp(S),
equal_pts(DecP, ecu_ed25519:decompress(CompP))
end).
@@ -70,7 +70,7 @@ prop_generate_valid_point() ->
prop_scalar_mul_base() ->
?FORALL(S, gen_scalar(),
begin
E = enacl:crypto_ed25519_scalarmult_base(S),
E = enacl:curve25519_scalarmult_base(S),
P = ecu_ed25519:scalar_mul_base(S),
equals(E, ecu_ed25519:compress(P))
end).
@@ -78,7 +78,7 @@ prop_scalar_mul_base() ->
prop_scalar_mul_base_noclamp() ->
?FORALL(S, gen_scalar(),
begin
E = enacl:crypto_ed25519_scalarmult_base_noclamp(S),
E = enacl:curve25519_scalarmult_base_noclamp(S),
P = ecu_ed25519:scalar_mul_base_noclamp(S),
equals(E, ecu_ed25519:compress(P))
end).
@@ -86,7 +86,7 @@ prop_scalar_mul_base_noclamp() ->
prop_scalar_mul() ->
?FORALL({S, P0}, {gen_scalar(), gen_point()},
begin
E = enacl:crypto_ed25519_scalarmult(S, P0),
E = enacl:curve25519_scalarmult(S, P0),
P = ecu_ed25519:scalar_mul(S, P0),
equals(E, ecu_ed25519:compress(P))
end).
@@ -94,7 +94,7 @@ prop_scalar_mul() ->
prop_scalar_mul_noclamp() ->
?FORALL({S, P0}, {gen_scalar(), gen_point()},
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)),
equals(E, ecu_ed25519:compress(P))
end).
+1 -1
View File
@@ -20,7 +20,7 @@ gen_scalar() ->
?LET(N, gen_large_n(), <<N:256/little>>).
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() ->
?FORALL(Seed, binary(32),
+26 -9
View File
@@ -1,14 +1,31 @@
{erl_opts, [debug_info]}.
{plugins, [
{eqc_rebar, {git, "https://github.com/Quviq/eqc-rebar.git", {branch, "master"}}}
]}.
{plugins, [{eqc_rebar, {git, "https://github.com/Quviq/eqc-rebar.git", {branch, "master"}}}]}.
{deps,
[{sha3, {git, "https://github.com/aeternity/erlang-sha3", {ref, "b5f27a2"}}}]}.
[{sha3,
{git,
"https://git.qpq.swiss/QPQ-AG/erlang-sha3.git",
{ref, "7290fa23664b4134d15da353061ac97aa158b332"}}}]}.
{profiles, [{test, [{deps, [{enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "5bae41c"}}},
{ecrecover, {git, "https://github.com/aeternity/ecrecover.git", {ref, "74b7816"}}}]}]},
{eqc, [{deps, [{enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "38ffc76"}}},
{ecrecover, {git, "https://github.com/aeternity/ecrecover.git", {ref, "74b7816"}}}]}]}
]}.
{profiles,
[{test,
[{deps,
[{enacl,
{git,
"https://git.qpq.swiss/QPQ-AG/enacl.git",
{ref, "4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}}},
{ecrecover,
{git,
"https://git.qpq.swiss/QPQ-AG/ecrecover.git",
{ref, "ce4175eaf2667a07ce41348dc6d4332477e30637"}}}]}]},
{eqc,
[{deps,
[{enacl,
{git,
"https://git.qpq.swiss/QPQ-AG/enacl.git",
{ref, "4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}}},
{ecrecover,
{git,
"https://git.qpq.swiss/QPQ-AG/ecrecover.git",
{ref, "ce4175eaf2667a07ce41348dc6d4332477e30637"}}}]}]}]}.
+3 -2
View File
@@ -1,8 +1,9 @@
{"1.2.0",
[{<<"hex2bin">>,{pkg,<<"hex2bin">>,<<"1.0.0">>},1},
{<<"sha3">>,
{git,"https://github.com/aeternity/erlang-sha3",
{ref,"b5f27a29ba1179e5907c50d7ec7aa79b2857e981"}},
{git,
"https://git.qpq.swiss/QPQ-AG/erlang-sha3.git",
{ref, "7290fa23664b4134d15da353061ac97aa158b332"}},
0}]}.
[
{pkg_hash,[
Executable
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -1,4 +1,4 @@
-module(ec_utils).
-vsn("1.0.0").
-vsn("1.0.1").
-export([]).
+2 -2
View File
@@ -3,7 +3,7 @@
%%% Description :
%%% Created : 13 Jan 2022 by Hans Svensson
-module(ecu_crypto).
-vsn("1.0.0").
-vsn("1.0.1").
-export([private_to_short/2, public_to_short/2,
ec_recover/2,
@@ -12,7 +12,7 @@
keccak256/1]).
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>>) ->
public_to_short(ethereum, ecu_secp256k1:scalar_mul_base(PrivateKey)).
+1 -1
View File
@@ -3,7 +3,7 @@
%%% Description : ecdsa functionality
%%% Created : 13 Jan 2022 by Hans Svensson
-module(ecu_ecdsa).
-vsn("1.0.0").
-vsn("1.0.1").
-export([sign/3, verify/4,
sign_secp256k1/2,
+1 -1
View File
@@ -4,7 +4,7 @@
%%% Just for usage when speed isn't crucial...
%%% Created : 13 Jan 2022 by Hans Svensson
-module(ecu_ed25519).
-vsn("1.0.0").
-vsn("1.0.1").
-define(P, 16#7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED).
-define(N, 16#1000000000000000000000000000000014DEF9DEA2F79CD65812631A5CF5D3ED).
+1 -1
View File
@@ -3,7 +3,7 @@
%%% Description : eddsa functionality - when possible compatible with enacl.
%%% Created : 19 Jan 2022 by Hans Svensson
-module(ecu_eddsa).
-vsn("1.0.0").
-vsn("1.0.1").
-export([sign_keypair/0,
sign_seed_keypair/1,
+1 -1
View File
@@ -3,7 +3,7 @@
%%% Description : Misc. functionality
%%% Created : 13 Jan 2022 by Hans Svensson
-module(ecu_misc).
-vsn("1.0.0").
-vsn("1.0.1").
-export([eea/2, exp_mod/3,
hex_to_bin/1, bin_to_hex/1,
+1 -1
View File
@@ -4,7 +4,7 @@
%%% Just for usage when speed isn't crucial...
%%% Created : 22 Dec 2021 by Hans Svensson
-module(ecu_secp256k1).
-vsn("1.0.0").
-vsn("1.0.1").
-define(P, 16#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F).
-define(A, 16#00).
+3 -3
View File
@@ -13,7 +13,7 @@ gen_scalar() ->
1 + X rem (ecu_ed25519:n() - 1).
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)]),
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)),
{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),
?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,
{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),
?debugFmt("", []),
+11 -11
View File
@@ -1,17 +1,17 @@
{a_email,"hanssv@gmail.com"}.
{name,"Elliptic Curve Utils"}.
{type,lib}.
{modules,[]}.
{prefix,none}.
{desc,"Helper functions for cryptography, mostly related to elliptic curves."}.
{author,"Hans Svensson"}.
{package_id,{"otpr","ec_utils",{1,0,1}}}.
{deps,[{"otpr","sha3",{0,1,5}}]}.
{key_name,none}.
{a_email,"hanssv@gmail.com"}.
{c_email,"hanssv@gmail.com"}.
{copyright,"Hans Svensson"}.
{deps,[{"otpr","sha3",{0,1,3}}]}.
{desc,"Helper functions for cryptography, mostly related to elliptic curves."}.
{file_exts,[]}.
{key_name,none}.
{license,"MIT"}.
{modules,[]}.
{name,"Elliptic Curve Utils"}.
{package_id,{"otpr","ec_utils",{1,0,0}}}.
{prefix,none}.
{repo_url,"https://github.com/hanssv/ec_utils"}.
{repo_url,"https://git.qpq.swiss/QPQ-AG/ec_utils"}.
{tags,["cryptography","elliptic curve","crypto","enacl"]}.
{type,lib}.
{ws_url,"https://github.com/hanssv/ec_utils"}.
{ws_url,"https://git.qpq.swiss/QPQ-AG/ec_utils"}.
Executable
+9
View File
@@ -0,0 +1,9 @@
#! /bin/bash
# This is a small pre-packaging source generation and include correction script that should be
# run before packaging this project for use with ZX/Zomp.
rm -rf _build
rm -f ebin/*.beam
rm -f rebar*
rm -rf quickcheck