From 04b8fa3ecbef2017a14342157c0f3e41afb3a091 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Tue, 12 Jun 2018 14:26:14 +0200 Subject: [PATCH 1/3] Dangerous use of constant --- c_src/enacl_nif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_src/enacl_nif.c b/c_src/enacl_nif.c index 1046af7..29862c3 100644 --- a/c_src/enacl_nif.c +++ b/c_src/enacl_nif.c @@ -131,7 +131,7 @@ ERL_NIF_TERM enif_crypto_curve25519_scalarmult(ErlNifEnv *env, int argc, ERL_NIF memcpy(bp, basepoint.data, crypto_scalarmult_curve25519_BYTES); /* Clear the high-bit. Better safe than sorry. */ - bp[31] &= 0x7f; + bp[crypto_scalarmult_curve25519_BYTES - 1] &= 0x7f; do { From 40fde1807b49e11007112c49186d2afb4cb085d8 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Wed, 13 Jun 2018 07:03:04 +0200 Subject: [PATCH 2/3] Variable is assigned but never used This is just a warning, but elliminating warnings makes the code go cleanly through clang static code analyzer. --- c_src/enacl_nif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_src/enacl_nif.c b/c_src/enacl_nif.c index 29862c3..5b1cf58 100644 --- a/c_src/enacl_nif.c +++ b/c_src/enacl_nif.c @@ -1167,7 +1167,7 @@ void uint64_pack(unsigned char *y, ErlNifUInt64 x) *y++ = x; x >>= 8; *y++ = x; x >>= 8; *y++ = x; x >>= 8; - *y++ = x; x >>= 8; + *y++ = x; } static From b3bbb2a9103d0fd7a58cba4612ec50de0d9ad69e Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Wed, 13 Jun 2018 07:04:01 +0200 Subject: [PATCH 3/3] Add tests for scalarmult There appeared to be no tests for this function. The typical property for it is that scalarmultiplication is commutitative. --- eqc_test/enacl_eqc.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/eqc_test/enacl_eqc.erl b/eqc_test/enacl_eqc.erl index 3bc2987..bc7211e 100644 --- a/eqc_test/enacl_eqc.erl +++ b/eqc_test/enacl_eqc.erl @@ -1,6 +1,6 @@ -module(enacl_eqc). -include_lib("eqc/include/eqc.hrl"). --compile(export_all). +-compile([export_all, nowarn_export_all]). -ifndef(mini). -compile({parse_transform, eqc_parallelize}). @@ -774,6 +774,16 @@ prop_scramble_block() -> ?FORALL({Block, Key}, {binary(16), eqc_gen:largebinary(32)}, is_binary(enacl_ext:scramble_block_16(Block, Key))). +%% Scala multiplication +prop_scalarmult() -> + Bytes = 32, + ?FORALL({S1, S2, Basepoint}, {binary(Bytes), binary(Bytes), binary(Bytes)}, + equals(enacl:curve25519_scalarmult(S1, + enacl:curve25519_scalarmult(S2, Basepoint)), + enacl:curve25519_scalarmult(S2, + enacl:curve25519_scalarmult(S1, Basepoint))) + ). + %% HELPERS badargs(Thunk) -> try