From e963bef6536e71036b1b1642219d75c43590e625 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Sat, 6 Aug 2016 19:33:06 +1200 Subject: [PATCH 1/4] Add hexhash/2 --- rebar.config | 3 +++ rebar.lock | 2 +- src/sha3.app.src | 3 ++- src/sha3.erl | 8 ++++++++ test/sha3_tests.erl | 16 ++++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/rebar.config b/rebar.config index 1b456c9..90c08c0 100644 --- a/rebar.config +++ b/rebar.config @@ -1,8 +1,11 @@ {erl_opts, [{i, "src"}, warnings_as_errors, + debug_info, {w, all}, warn_export_all]}. +{deps, [{hex2bin, "1.0.0"}]}. + {clean_files, [".eunit", "ebin/*.beam"]}. diff --git a/rebar.lock b/rebar.lock index 57afcca..d6faa9e 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1 +1 @@ -[]. +[{<<"hex2bin">>,{pkg,<<"hex2bin">>,<<"1.0.0">>},0}]. diff --git a/src/sha3.app.src b/src/sha3.app.src index 5d0848c..d18de89 100644 --- a/src/sha3.app.src +++ b/src/sha3.app.src @@ -5,7 +5,8 @@ {registered, []}, {applications, [ kernel, - stdlib + stdlib, + hex2bin ]}, {modules, [sha3]}, {env, []} diff --git a/src/sha3.erl b/src/sha3.erl index c8f46ed..64ae999 100644 --- a/src/sha3.erl +++ b/src/sha3.erl @@ -2,6 +2,8 @@ -export([hash_init/1, hash_update/2, hash_final/1, hash/2]). +-export([hexhash/2]). + -on_load(init/0). -type bitlen() :: 224 | 256 | 384 | 512. @@ -11,6 +13,8 @@ -type digest() :: <<_:224>> | <<_:256>> | <<_:384>> | <<_:512>>. +-export_type([bitlen/0, context/0, digest/0]). + -define(nif_stub, nif_stub_error(?LINE)). nif_stub_error(Line) -> erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}). @@ -55,3 +59,7 @@ hash_final(_Context) -> hash(_BitLen, _Binary) -> ?nif_stub. +-spec hexhash(bitlen(), binary()) -> binary(). +hexhash(Bitlen, Binary) -> + Hash = hash(Bitlen, Binary), + list_to_binary(hex2bin:bin_to_hexstr(Hash)). diff --git a/test/sha3_tests.erl b/test/sha3_tests.erl index c8b262f..893b69d 100644 --- a/test/sha3_tests.erl +++ b/test/sha3_tests.erl @@ -46,3 +46,19 @@ hash_512_test() -> ?assertEqual(<<16#94EE7851163C39C3489373AA0BF885D95925EAD7484C586D2E0D01D9C8069D3C30E2EEA2DC63A91B517FE53E43A31D764A2154A2DA92876366B138ABC4406805:512>>, sha3:hash(512, <<16#00112233445566778899AABBCCDDEEFF:128>>)). +hexhash_224_test() -> + ?assertEqual(<<"038907E89C919CD8F90A7FBC5A88FF9278108DAEF3EBCDA0CEB383E1">>, + sha3:hexhash(224, <<16#00112233445566778899AABBCCDDEEFF:128>>)). + +hexhash_256_test() -> + ?assertEqual(<<"22BCE46032802AF0ABFACF3768F7BE04A34F5F01DF60F44FFD52D3CA937350C0">>, + sha3:hexhash(256, <<16#00112233445566778899AABBCCDDEEFF:128>>)). + +hexhash_384_test() -> + ?assertEqual(<<"25FAC1ADECBE1B254976FE32C2FE78829B23D7D84316141ECD208D6806A9DB4352A014ADA4106BA0D210DDA0FD18E150">>, + sha3:hexhash(384, <<16#00112233445566778899AABBCCDDEEFF:128>>)). + +hexhash_512_test() -> + ?assertEqual(<<"94EE7851163C39C3489373AA0BF885D95925EAD7484C586D2E0D01D9C8069D3C30E2EEA2DC63A91B517FE53E43A31D764A2154A2DA92876366B138ABC4406805">>, + sha3:hexhash(512, <<16#00112233445566778899AABBCCDDEEFF:128>>)). + From b89e8e27c3637d63d15b412cf7928512beab6546 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Sat, 6 Aug 2016 19:38:10 +1200 Subject: [PATCH 2/4] Fix Travis build --- .travis.yml | 10 ++++++---- Makefile | 41 ++++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index f39fff3..b3451ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,12 @@ language: erlang + +install: wget https://github.com/erlang/rebar3/releases/download/3.1.0/rebar3 && chmod 755 rebar3 + +script: PATH=.:$PATH make update test dialyzer + notifications: disabled: true -branches: - only: - - develop - - 0.1.0 + otp_release: - R15B02 - R15B01 diff --git a/Makefile b/Makefile index 3e8b822..6ea1c18 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,30 @@ -.PHONY: doc +REBAR?=rebar3 + +.PHONY: \ + all \ + clean \ + nuke \ + test \ + update \ + dialyzer all: - ./rebar compile - ./rebar doc - ./rebar xref - ./rebar eunit - -compile: - ./rebar compile - -doc: - ./rebar doc - -xref: compile - ./rebar xref + @$(REBAR) compile clean: - ./rebar clean + @$(REBAR) clean -test: xref - ./rebar eunit +nuke: clean + @rm -rf _build +test: + @$(REBAR) eunit + +update: + @$(REBAR) update + +dialyzer: + @$(REBAR) dialyzer + +coveralls: + @${REBAR} coveralls send From b80fa2d97af46b7732db6d09aab2dba396990e0c Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Sat, 6 Aug 2016 19:42:31 +1200 Subject: [PATCH 3/4] Cache $HOME/.cache/rebar3/ in Travis CI --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index b3451ca..8562db1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,3 +14,8 @@ otp_release: - 18.0 - 18.1 - 18.2 + +cache: + directories: + - $HOME/.cache/rebar3/ + From b10f9f7327036d12892cb4c7ac744501c6a93abc Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Sat, 6 Aug 2016 19:48:55 +1200 Subject: [PATCH 4/4] Ditch old OTP releases --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8562db1..f9e5faf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,6 @@ notifications: disabled: true otp_release: - - R15B02 - - R15B01 - - R15B - 18.0 - 18.1 - 18.2