More tests

This commit is contained in:
Hans Svensson 2018-03-02 14:25:18 +01:00
parent 4d2af24250
commit 4414c0d7a2
3 changed files with 27 additions and 6 deletions

View File

@ -5,6 +5,23 @@
-module(enoise_crypto_tests).
-include_lib("eunit/include/eunit.hrl").
-include("enoise.hrl").
curve25519_test() ->
KeyPair1 = enoise_crypto:new_key_pair(dh25519),
KeyPair2 = enoise_crypto:new_key_pair(dh25519),
SharedA = enoise_crypto:dh(dh25519, KeyPair1, KeyPair2#key_pair.puk),
SharedB = enoise_crypto:dh(dh25519, KeyPair2, KeyPair1#key_pair.puk),
?assertMatch(SharedA, SharedB),
#{ a_pub := APub, a_priv := APriv,
b_pub := BPub, b_priv := BPriv, shared := Shared } = test_utils:curve25519_data(),
?assertMatch(Shared, enoise_crypto:dh(dh25519, #key_pair{ puk = APub, pik = APriv }, BPub)),
?assertMatch(Shared, enoise_crypto:dh(dh25519, #key_pair{ puk = BPub, pik = BPriv }, APub)),
ok.
chachapoly_test() ->
#{ key := Key, nonce := Nonce, ad := AD, mac := MAC,

View File

@ -8,10 +8,7 @@
-include("enoise.hrl").
noise_XK_25519_ChaChaPoly_Blake2b_test() ->
Protocol = #noise_protocol{ hs_pattern = noiseXK
, dh = dh25519
, cipher = 'ChaChaPoly'
, hash = blake2b },
Protocol = enoise_protocol:from_name("Noise_XK_25519_ChaChaPoly_Blake2b"),
SSE0 = enoise_sym_state:init(Protocol),
SSD0 = enoise_sym_state:init(Protocol),

View File

@ -7,6 +7,14 @@
-compile([export_all, nowarn_export_all]).
%% -- Test data --------------------------------------------------------------
curve25519_data() ->
#{ a_priv => hex_str_to_bin("0x77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"),
a_pub => hex_str_to_bin("0x8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a"),
b_priv => hex_str_to_bin("0x5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb"),
b_pub => hex_str_to_bin("0xde9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f"),
shared => hex_str_to_bin("0x4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742")
}.
chacha_data() ->
#{ key => hex_str_to_bin("0x1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0")
, nonce => 16#0807060504030201
@ -94,5 +102,4 @@ blake2b_hkdf_data() ->
}].
hex_str_to_bin("0x" ++ Rest) ->
<< <<(list_to_integer([C], 16)):4>> || C <- Rest >>.
hex_str_to_bin("0x" ++ Rest) -> << <<(list_to_integer([C], 16)):4>> || C <- Rest >>.