From 89d80ea005baf7b7d84ee6831ef051f936faa7f2 Mon Sep 17 00:00:00 2001 From: Peter Lemenkov Date: Mon, 7 Dec 2015 15:34:48 +0300 Subject: [PATCH 1/2] Lift R14 restriction Signed-off-by: Peter Lemenkov --- rebar.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index f7e80c7..fff31e5 100644 --- a/rebar.config +++ b/rebar.config @@ -5,4 +5,4 @@ ]}. {erl_opts, [debug_info, fail_on_warning]}. -{require_otp_vsn, "R14"}. +{require_otp_vsn, "R16|17|18"}. From 4fb7b4c3d6e90035d181160b5cdf335b9d7b7917 Mon Sep 17 00:00:00 2001 From: Peter Lemenkov Date: Mon, 7 Dec 2015 15:54:59 +0300 Subject: [PATCH 2/2] Remove obsolete ersha2 library Signed-off-by: Peter Lemenkov --- apps/biten/src/b_crypto.erl | 2 +- apps/biten/src/sha2.erl | 506 ------------ apps/erlsha2/.gitignore | 7 - apps/erlsha2/AUTHORS | 1 - apps/erlsha2/LICENSE | 27 - apps/erlsha2/Makefile | 34 - apps/erlsha2/README.md | 46 -- apps/erlsha2/c_src/config.sh | 32 - apps/erlsha2/c_src/erlsha2_nif.c | 785 ------------------- apps/erlsha2/doc/README.md | 12 - apps/erlsha2/doc/edoc-info | 3 - apps/erlsha2/doc/erlsha2.md | 204 ----- apps/erlsha2/doc/hmac.md | 93 --- apps/erlsha2/edown.config | 11 - apps/erlsha2/rebar.config | 16 - apps/erlsha2/src/erlsha2.app.src | 14 - apps/erlsha2/src/erlsha2.erl | 494 ------------ apps/erlsha2/src/hmac.erl | 110 --- apps/erlsha2/test/erlsha2_test.erl | 471 ----------- apps/erlsha2/test/hmac_test.erl | 132 ---- apps/erlsha2/test/testvectors/LICENSE | 30 - apps/erlsha2/test/testvectors/vector001.dat | 1 - apps/erlsha2/test/testvectors/vector001.info | 21 - apps/erlsha2/test/testvectors/vector002.dat | 1 - apps/erlsha2/test/testvectors/vector002.info | 21 - apps/erlsha2/test/testvectors/vector003.dat | 1 - apps/erlsha2/test/testvectors/vector003.info | 22 - apps/erlsha2/test/testvectors/vector004.dat | 1 - apps/erlsha2/test/testvectors/vector004.info | 22 - apps/erlsha2/test/testvectors/vector005.dat | 0 apps/erlsha2/test/testvectors/vector005.info | 23 - apps/erlsha2/test/testvectors/vector006.dat | 1 - apps/erlsha2/test/testvectors/vector006.info | 22 - apps/erlsha2/test/testvectors/vector007.dat | 1 - apps/erlsha2/test/testvectors/vector007.info | 22 - apps/erlsha2/test/testvectors/vector008.dat | 1 - apps/erlsha2/test/testvectors/vector008.info | 22 - apps/erlsha2/test/testvectors/vector009.dat | 1 - apps/erlsha2/test/testvectors/vector009.info | 22 - apps/erlsha2/test/testvectors/vector010.dat | Bin 320 -> 0 bytes apps/erlsha2/test/testvectors/vector010.info | 22 - apps/erlsha2/test/testvectors/vector011.dat | Bin 447 -> 0 bytes apps/erlsha2/test/testvectors/vector011.info | 22 - apps/erlsha2/test/testvectors/vector012.dat | Bin 640 -> 0 bytes apps/erlsha2/test/testvectors/vector012.info | 22 - apps/erlsha2/test/testvectors/vector013.dat | Bin 2175 -> 0 bytes apps/erlsha2/test/testvectors/vector013.info | 22 - apps/erlsha2/test/testvectors/vector014.dat | Bin 16384 -> 0 bytes apps/erlsha2/test/testvectors/vector014.info | 22 - apps/erlsha2/test/testvectors/vector015.dat | 1 - apps/erlsha2/test/testvectors/vector015.info | 21 - apps/erlsha2/test/testvectors/vector016.dat | 1 - apps/erlsha2/test/testvectors/vector016.info | 23 - apps/erlsha2/test/testvectors/vector017.dat | Bin 12271 -> 0 bytes apps/erlsha2/test/testvectors/vector017.info | 32 - apps/erlsha2/test/testvectors/vector018.dat | Bin 1079 -> 0 bytes apps/erlsha2/test/testvectors/vector018.info | 26 - rebar.config | 1 - 58 files changed, 1 insertion(+), 3449 deletions(-) delete mode 100644 apps/biten/src/sha2.erl delete mode 100644 apps/erlsha2/.gitignore delete mode 100644 apps/erlsha2/AUTHORS delete mode 100644 apps/erlsha2/LICENSE delete mode 100644 apps/erlsha2/Makefile delete mode 100644 apps/erlsha2/README.md delete mode 100755 apps/erlsha2/c_src/config.sh delete mode 100644 apps/erlsha2/c_src/erlsha2_nif.c delete mode 100644 apps/erlsha2/doc/README.md delete mode 100644 apps/erlsha2/doc/edoc-info delete mode 100644 apps/erlsha2/doc/erlsha2.md delete mode 100644 apps/erlsha2/doc/hmac.md delete mode 100644 apps/erlsha2/edown.config delete mode 100644 apps/erlsha2/rebar.config delete mode 100644 apps/erlsha2/src/erlsha2.app.src delete mode 100644 apps/erlsha2/src/erlsha2.erl delete mode 100644 apps/erlsha2/src/hmac.erl delete mode 100644 apps/erlsha2/test/erlsha2_test.erl delete mode 100644 apps/erlsha2/test/hmac_test.erl delete mode 100644 apps/erlsha2/test/testvectors/LICENSE delete mode 100644 apps/erlsha2/test/testvectors/vector001.dat delete mode 100644 apps/erlsha2/test/testvectors/vector001.info delete mode 100644 apps/erlsha2/test/testvectors/vector002.dat delete mode 100644 apps/erlsha2/test/testvectors/vector002.info delete mode 100644 apps/erlsha2/test/testvectors/vector003.dat delete mode 100644 apps/erlsha2/test/testvectors/vector003.info delete mode 100644 apps/erlsha2/test/testvectors/vector004.dat delete mode 100644 apps/erlsha2/test/testvectors/vector004.info delete mode 100644 apps/erlsha2/test/testvectors/vector005.dat delete mode 100644 apps/erlsha2/test/testvectors/vector005.info delete mode 100644 apps/erlsha2/test/testvectors/vector006.dat delete mode 100644 apps/erlsha2/test/testvectors/vector006.info delete mode 100644 apps/erlsha2/test/testvectors/vector007.dat delete mode 100644 apps/erlsha2/test/testvectors/vector007.info delete mode 100644 apps/erlsha2/test/testvectors/vector008.dat delete mode 100644 apps/erlsha2/test/testvectors/vector008.info delete mode 100644 apps/erlsha2/test/testvectors/vector009.dat delete mode 100644 apps/erlsha2/test/testvectors/vector009.info delete mode 100644 apps/erlsha2/test/testvectors/vector010.dat delete mode 100644 apps/erlsha2/test/testvectors/vector010.info delete mode 100644 apps/erlsha2/test/testvectors/vector011.dat delete mode 100644 apps/erlsha2/test/testvectors/vector011.info delete mode 100644 apps/erlsha2/test/testvectors/vector012.dat delete mode 100644 apps/erlsha2/test/testvectors/vector012.info delete mode 100644 apps/erlsha2/test/testvectors/vector013.dat delete mode 100644 apps/erlsha2/test/testvectors/vector013.info delete mode 100644 apps/erlsha2/test/testvectors/vector014.dat delete mode 100644 apps/erlsha2/test/testvectors/vector014.info delete mode 100644 apps/erlsha2/test/testvectors/vector015.dat delete mode 100644 apps/erlsha2/test/testvectors/vector015.info delete mode 100644 apps/erlsha2/test/testvectors/vector016.dat delete mode 100644 apps/erlsha2/test/testvectors/vector016.info delete mode 100644 apps/erlsha2/test/testvectors/vector017.dat delete mode 100644 apps/erlsha2/test/testvectors/vector017.info delete mode 100644 apps/erlsha2/test/testvectors/vector018.dat delete mode 100644 apps/erlsha2/test/testvectors/vector018.info diff --git a/apps/biten/src/b_crypto.erl b/apps/biten/src/b_crypto.erl index 8a371fc..68db218 100644 --- a/apps/biten/src/b_crypto.erl +++ b/apps/biten/src/b_crypto.erl @@ -9,7 +9,7 @@ -compile(export_all). hash(Bin) -> - erlsha2:sha256(erlsha2:sha256(Bin)). + crypto:hash(sha256, crypto:hash(sha256, Bin)). crc(Bin) -> <> = hash(Bin), diff --git a/apps/biten/src/sha2.erl b/apps/biten/src/sha2.erl deleted file mode 100644 index 53b2447..0000000 --- a/apps/biten/src/sha2.erl +++ /dev/null @@ -1,506 +0,0 @@ -%%% -%%% OBSOLETE OBSOLETE OBSOLETE OBSOLETE OBSOLETE -%%% -%%% Please see https://github.com/vinoski/erlsha2 instead! -%%% -%%% OBSOLETE OBSOLETE OBSOLETE OBSOLETE OBSOLETE -%%% -%%% @author Steve Vinoski [http://steve.vinoski.net/] -%%% @doc Implementations of SHA-224, SHA-256, SHA-384, SHA-512 in Erlang. -%%% @reference See -%%% the Secure Hash Standard and the Wikipedia -%%% SHA1 article. Find the code here. -%%% @since 03 Jan 2009 -%%% -%%% @copyright 2009 Stephen B. Vinoski, All rights reserved. Open source, BSD License -%%% @version 1.1 -%%% - -%%% -%%% Copyright (c) 2009 Stephen B. Vinoski -%%% All rights reserved. -%%% -%%% Redistribution and use in source and binary forms, with or without -%%% modification, are permitted provided that the following conditions -%%% are met: -%%% 1. Redistributions of source code must retain the above copyright -%%% notice, this list of conditions and the following disclaimer. -%%% 2. Redistributions in binary form must reproduce the above copyright -%%% notice, this list of conditions and the following disclaimer in the -%%% documentation and/or other materials provided with the distribution. -%%% 3. Neither the name of the copyright holder nor the names of contributors -%%% may be used to endorse or promote products derived from this software -%%% without specific prior written permission. -%%% -%%% THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND -%%% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%%% ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE -%%% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -%%% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -%%% OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -%%% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -%%% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -%%% SUCH DAMAGE. -%%% - --module(sha2). --export([hexdigest224/1, hexdigest256/1, hexdigest384/1, hexdigest512/1]). --export([test/0, test224/0, test256/0, test384/0, test512/0]). --version(1.1). - --define(H224, [16#C1059ED8, 16#367CD507, 16#3070DD17, 16#F70E5939, - 16#FFC00B31, 16#68581511, 16#64F98FA7, 16#BEFA4FA4]). - --define(H256, [16#6A09E667, 16#BB67AE85, 16#3C6EF372, 16#A54FF53A, - 16#510E527F, 16#9B05688C, 16#1F83D9AB, 16#5BE0CD19]). - --define(H384, [16#CBBB9D5DC1059ED8, 16#629A292A367CD507, 16#9159015A3070DD17, - 16#152FECD8F70E5939, 16#67332667FFC00B31, 16#8EB44A8768581511, - 16#DB0C2E0D64F98FA7, 16#47B5481DBEFA4FA4]). - --define(H512, [16#6A09E667F3BCC908, 16#BB67AE8584CAA73B, 16#3C6EF372FE94F82B, - 16#A54FF53A5F1D36F1, 16#510E527FADE682D1, 16#9B05688C2B3E6C1F, - 16#1F83D9ABFB41BD6B, 16#5BE0CD19137E2179]). - --define(K256, <<16#428A2F98:32/big-unsigned, 16#71374491:32/big-unsigned, 16#B5C0FBCF:32/big-unsigned, - 16#E9B5DBA5:32/big-unsigned, 16#3956C25B:32/big-unsigned, 16#59F111F1:32/big-unsigned, - 16#923F82A4:32/big-unsigned, 16#AB1C5ED5:32/big-unsigned, 16#D807AA98:32/big-unsigned, - 16#12835B01:32/big-unsigned, 16#243185BE:32/big-unsigned, 16#550C7DC3:32/big-unsigned, - 16#72BE5D74:32/big-unsigned, 16#80DEB1FE:32/big-unsigned, 16#9BDC06A7:32/big-unsigned, - 16#C19BF174:32/big-unsigned, 16#E49B69C1:32/big-unsigned, 16#EFBE4786:32/big-unsigned, - 16#0FC19DC6:32/big-unsigned, 16#240CA1CC:32/big-unsigned, 16#2DE92C6F:32/big-unsigned, - 16#4A7484AA:32/big-unsigned, 16#5CB0A9DC:32/big-unsigned, 16#76F988DA:32/big-unsigned, - 16#983E5152:32/big-unsigned, 16#A831C66D:32/big-unsigned, 16#B00327C8:32/big-unsigned, - 16#BF597FC7:32/big-unsigned, 16#C6E00BF3:32/big-unsigned, 16#D5A79147:32/big-unsigned, - 16#06CA6351:32/big-unsigned, 16#14292967:32/big-unsigned, 16#27B70A85:32/big-unsigned, - 16#2E1B2138:32/big-unsigned, 16#4D2C6DFC:32/big-unsigned, 16#53380D13:32/big-unsigned, - 16#650A7354:32/big-unsigned, 16#766A0ABB:32/big-unsigned, 16#81C2C92E:32/big-unsigned, - 16#92722C85:32/big-unsigned, 16#A2BFE8A1:32/big-unsigned, 16#A81A664B:32/big-unsigned, - 16#C24B8B70:32/big-unsigned, 16#C76C51A3:32/big-unsigned, 16#D192E819:32/big-unsigned, - 16#D6990624:32/big-unsigned, 16#F40E3585:32/big-unsigned, 16#106AA070:32/big-unsigned, - 16#19A4C116:32/big-unsigned, 16#1E376C08:32/big-unsigned, 16#2748774C:32/big-unsigned, - 16#34B0BCB5:32/big-unsigned, 16#391C0CB3:32/big-unsigned, 16#4ED8AA4A:32/big-unsigned, - 16#5B9CCA4F:32/big-unsigned, 16#682E6FF3:32/big-unsigned, 16#748F82EE:32/big-unsigned, - 16#78A5636F:32/big-unsigned, 16#84C87814:32/big-unsigned, 16#8CC70208:32/big-unsigned, - 16#90BEFFFA:32/big-unsigned, 16#A4506CEB:32/big-unsigned, 16#BEF9A3F7:32/big-unsigned, - 16#C67178F2:32/big-unsigned>>). - --define(K512, <<16#428A2F98D728AE22:64/big-unsigned, 16#7137449123EF65CD:64/big-unsigned, - 16#B5C0FBCFEC4D3B2F:64/big-unsigned, 16#E9B5DBA58189DBBC:64/big-unsigned, - 16#3956C25BF348B538:64/big-unsigned, 16#59F111F1B605D019:64/big-unsigned, - 16#923F82A4AF194F9B:64/big-unsigned, 16#AB1C5ED5DA6D8118:64/big-unsigned, - 16#D807AA98A3030242:64/big-unsigned, 16#12835B0145706FBE:64/big-unsigned, - 16#243185BE4EE4B28C:64/big-unsigned, 16#550C7DC3D5FFB4E2:64/big-unsigned, - 16#72BE5D74F27B896F:64/big-unsigned, 16#80DEB1FE3B1696B1:64/big-unsigned, - 16#9BDC06A725C71235:64/big-unsigned, 16#C19BF174CF692694:64/big-unsigned, - 16#E49B69C19EF14AD2:64/big-unsigned, 16#EFBE4786384F25E3:64/big-unsigned, - 16#0FC19DC68B8CD5B5:64/big-unsigned, 16#240CA1CC77AC9C65:64/big-unsigned, - 16#2DE92C6F592B0275:64/big-unsigned, 16#4A7484AA6EA6E483:64/big-unsigned, - 16#5CB0A9DCBD41FBD4:64/big-unsigned, 16#76F988DA831153B5:64/big-unsigned, - 16#983E5152EE66DFAB:64/big-unsigned, 16#A831C66D2DB43210:64/big-unsigned, - 16#B00327C898FB213F:64/big-unsigned, 16#BF597FC7BEEF0EE4:64/big-unsigned, - 16#C6E00BF33DA88FC2:64/big-unsigned, 16#D5A79147930AA725:64/big-unsigned, - 16#06CA6351E003826F:64/big-unsigned, 16#142929670A0E6E70:64/big-unsigned, - 16#27B70A8546D22FFC:64/big-unsigned, 16#2E1B21385C26C926:64/big-unsigned, - 16#4D2C6DFC5AC42AED:64/big-unsigned, 16#53380D139D95B3DF:64/big-unsigned, - 16#650A73548BAF63DE:64/big-unsigned, 16#766A0ABB3C77B2A8:64/big-unsigned, - 16#81C2C92E47EDAEE6:64/big-unsigned, 16#92722C851482353B:64/big-unsigned, - 16#A2BFE8A14CF10364:64/big-unsigned, 16#A81A664BBC423001:64/big-unsigned, - 16#C24B8B70D0F89791:64/big-unsigned, 16#C76C51A30654BE30:64/big-unsigned, - 16#D192E819D6EF5218:64/big-unsigned, 16#D69906245565A910:64/big-unsigned, - 16#F40E35855771202A:64/big-unsigned, 16#106AA07032BBD1B8:64/big-unsigned, - 16#19A4C116B8D2D0C8:64/big-unsigned, 16#1E376C085141AB53:64/big-unsigned, - 16#2748774CDF8EEB99:64/big-unsigned, 16#34B0BCB5E19B48A8:64/big-unsigned, - 16#391C0CB3C5C95A63:64/big-unsigned, 16#4ED8AA4AE3418ACB:64/big-unsigned, - 16#5B9CCA4F7763E373:64/big-unsigned, 16#682E6FF3D6B2B8A3:64/big-unsigned, - 16#748F82EE5DEFB2FC:64/big-unsigned, 16#78A5636F43172F60:64/big-unsigned, - 16#84C87814A1F0AB72:64/big-unsigned, 16#8CC702081A6439EC:64/big-unsigned, - 16#90BEFFFA23631E28:64/big-unsigned, 16#A4506CEBDE82BDE9:64/big-unsigned, - 16#BEF9A3F7B2C67915:64/big-unsigned, 16#C67178F2E372532B:64/big-unsigned, - 16#CA273ECEEA26619C:64/big-unsigned, 16#D186B8C721C0C207:64/big-unsigned, - 16#EADA7DD6CDE0EB1E:64/big-unsigned, 16#F57D4F7FEE6ED178:64/big-unsigned, - 16#06F067AA72176FBA:64/big-unsigned, 16#0A637DC5A2C898A6:64/big-unsigned, - 16#113F9804BEF90DAE:64/big-unsigned, 16#1B710B35131C471B:64/big-unsigned, - 16#28DB77F523047D84:64/big-unsigned, 16#32CAAB7B40C72493:64/big-unsigned, - 16#3C9EBE0A15C9BEBC:64/big-unsigned, 16#431D67C49C100D4C:64/big-unsigned, - 16#4CC5D4BECB3E42B6:64/big-unsigned, 16#597F299CFC657E2A:64/big-unsigned, - 16#5FCB6FAB3AD6FAEC:64/big-unsigned, 16#6C44198C4A475817:64/big-unsigned>>). - --define(ADD32(X, Y), (X + Y) band 16#FFFFFFFF). --define(ADD64(X, Y), (X + Y) band 16#FFFFFFFFFFFFFFFF). - -%% @spec hexdigest224(message()) -> digest() -%% where -%% message() = binary() | string() -%% digest() = binary() | string() -%% @doc Returns a SHA-224 hexadecimal digest. -%% If the argument is a binary, the result is a binary, otherwise the argument is -%% expected to be a string and the result is a string. -%% -hexdigest224(M) when is_binary(M) -> - digest_bin(M, ?H224, 64, fun sha256_pad/1, fun sha224/2, 32); -hexdigest224(Str) -> - digest_str(Str, ?H224, 64, fun sha256_pad/1, fun sha224/2, "~8.16.0b"). - -%% @spec hexdigest256(message()) -> digest() -%% where -%% message() = binary() | string() -%% digest() = binary() | string() -%% @doc Returns a SHA-256 hexadecimal digest. -%% If the argument is a binary, the result is a binary, otherwise the argument is -%% expected to be a string and the result is a string. -%% -hexdigest256(M) when is_binary(M) -> - digest_bin(M, ?H256, 64, fun sha256_pad/1, fun sha256/2, 32); -hexdigest256(Str) -> - digest_str(Str, ?H256, 64, fun sha256_pad/1, fun sha256/2, "~8.16.0b"). - -%% @spec hexdigest384(message()) -> digest() -%% where -%% message() = binary() | string() -%% digest() = binary() | string() -%% @doc Returns a SHA-384 hexadecimal digest. -%% If the argument is a binary, the result is a binary, otherwise the argument is -%% expected to be a string and the result is a string. -%% -hexdigest384(M) when is_binary(M) -> - digest_bin(M, ?H384, 128, fun sha512_pad/1, fun sha384/2, 64); -hexdigest384(Str) -> - digest_str(Str, ?H384, 128, fun sha512_pad/1, fun sha384/2, "~16.16.0b"). - -%% @spec hexdigest512(message()) -> digest() -%% where -%% message() = binary() | string() -%% digest() = binary() | string() -%% @doc Returns a SHA-512 hexadecimal digest. -%% If the argument is a binary, the result is a binary, otherwise the argument is -%% expected to be a string and the result is a string. -%% -hexdigest512(M) when is_binary(M) -> - digest_bin(M, ?H512, 128, fun sha512_pad/1, fun sha512/2, 64); -hexdigest512(Str) -> - digest_str(Str, ?H512, 128, fun sha512_pad/1, fun sha512/2, "~16.16.0b"). - -digest_bin(M, Hashes, Bit_len, Pad, Sha, Word_size) -> - list_to_binary([<> || V <- Sha(split_binary(Pad(M), Bit_len), Hashes)]). -digest_str(Str, Hashes, Bit_len, Pad, Sha, Io_fmt) -> - M = list_to_binary(Str), - lists:flatten([io_lib:format(Io_fmt, [V]) || V <- Sha(split_binary(Pad(M), Bit_len), Hashes)]). - - -rotate32(V, Count) -> - Rest = 32 - Count, - <> = <>, - <> = <>, - New. - -rotate64(V, Count) -> - Rest = 64 - Count, - <> = <>, - <> = <>, - New. - -sha_pad(M, Base) -> - Len = size(M), - Len_bits = Len*8, - Pad_bits = (Len + 1 + Base div 8) rem Base, - Pad = case Pad_bits of - 0 -> 0; - _ -> (Base - Pad_bits) * 8 - end, - list_to_binary([M, <<16#80:8, 0:Pad, Len_bits:Base/big-unsigned>>]). - -sha256_pad(M) -> - sha_pad(M, 64). - -sha512_pad(M) -> - sha_pad(M, 128). - -sha256_extend(W, 64) -> - W; -sha256_extend(W, Count) -> - Off1 = (Count - 15) * 4, - Off2 = (Count - 2) * 4 - Off1 - 4, - <<_:Off1/binary, Word1:32/big-unsigned, _:Off2/binary, Word2:32/big-unsigned, _/binary>> = <>, - S0 = rotate32(Word1, 7) bxor rotate32(Word1, 18) bxor (Word1 bsr 3), - S1 = rotate32(Word2, 17) bxor rotate32(Word2, 19) bxor (Word2 bsr 10), - Off3 = (Count - 16) * 4, - Off4 = (Count - 7) * 4 - Off3 - 4, - <<_:Off3/binary, W16:32/big-unsigned, _:Off4/binary, W7:32/big-unsigned, _/binary>> = <>, - Next = (W16 + S0 + W7 + S1) band 16#FFFFFFFF, - sha256_extend(<>, Count+1). - -sha512_extend(W, 80) -> - W; -sha512_extend(W, Count) -> - Off1 = (Count - 15) * 8, - Off2 = (Count - 2) * 8 - Off1 - 8, - <<_:Off1/binary, Word1:64/big-unsigned, _:Off2/binary, Word2:64/big-unsigned, _/binary>> = <>, - S0 = rotate64(Word1, 1) bxor rotate64(Word1, 8) bxor (Word1 bsr 7), - S1 = rotate64(Word2, 19) bxor rotate64(Word2, 61) bxor (Word2 bsr 6), - Off3 = (Count - 16) * 8, - Off4 = (Count - 7) * 8 - Off3 - 8, - <<_:Off3/binary, W16:64/big-unsigned, _:Off4/binary, W7:64/big-unsigned, _/binary>> = <>, - Next = (W16 + S0 + W7 + S1) band 16#FFFFFFFFFFFFFFFF, - sha512_extend(<>, Count+1). - -sha256_loop(_W, Hashes, Next, 64) -> - lists:map(fun({X, Y}) -> ?ADD32(X, Y) end, lists:zip(Hashes, Next)); -sha256_loop(W, Hashes, [A, B, C, D, E, F, G, H], Count) -> - S0 = rotate32(A, 2) bxor rotate32(A, 13) bxor rotate32(A, 22), - Maj = (A band B) bxor (A band C) bxor (B band C), - T2 = ?ADD32(S0, Maj), - S1 = rotate32(E, 6) bxor rotate32(E, 11) bxor rotate32(E, 25), - Ch = (E band F) bxor (((bnot E) + 1 + 16#FFFFFFFF) band G), - Offset = Count * 4, - <<_:Offset/binary, K:32/big-unsigned, _/binary>> = ?K256, - <<_:Offset/binary, Wval:32/big-unsigned, _/binary>> = <>, - T1 = (H + S1 + Ch + K + Wval) band 16#FFFFFFFF, - sha256_loop(W, Hashes, [?ADD32(T1, T2), A, B, C, ?ADD32(D, T1), E, F, G], Count+1). - -sha512_loop(_W, Hashes, Next, 80) -> - lists:map(fun({X, Y}) -> ?ADD64(X, Y) end, lists:zip(Hashes, Next)); -sha512_loop(W, Hashes, [A, B, C, D, E, F, G, H], Count) -> - S0 = rotate64(A, 28) bxor rotate64(A, 34) bxor rotate64(A, 39), - Maj = (A band B) bxor (A band C) bxor (B band C), - T2 = ?ADD64(S0, Maj), - S1 = rotate64(E, 14) bxor rotate64(E, 18) bxor rotate64(E, 41), - Ch = (E band F) bxor (((bnot E) + 1 + 16#FFFFFFFFFFFFFFFF) band G), - Offset = Count * 8, - <<_:Offset/binary, K:64/big-unsigned, _/binary>> = ?K512, - <<_:Offset/binary, Wval:64/big-unsigned, _/binary>> = <>, - T1 = (H + S1 + Ch + K + Wval) band 16#FFFFFFFFFFFFFFFF, - sha512_loop(W, Hashes, [?ADD64(T1, T2), A, B, C, ?ADD64(D, T1), E, F, G], Count+1). - -sha256(M, Hashes) when is_binary(M) -> - Words64 = sha256_extend(M, 16), - sha256_loop(Words64, Hashes, Hashes, 0); -sha256({M, <<>>}, Hashes) -> - sha256(M, Hashes); -sha256({M, T}, Hashes) -> - sha256(split_binary(T, 64), sha256(M, Hashes)). - -sha224({M, <<>>}, Hashes) -> - [H0, H1, H2, H3, H4, H5, H6, _H7] = sha256(M, Hashes), - [H0, H1, H2, H3, H4, H5, H6]; -sha224({M, T}, Hashes) -> - sha224(split_binary(T, 64), sha256(M, Hashes)). - -sha512(M, Hashes) when is_binary(M) -> - Words128 = sha512_extend(M, 16), - sha512_loop(Words128, Hashes, Hashes, 0); -sha512({M, <<>>}, Hashes) -> - sha512(M, Hashes); -sha512({M, T}, Hashes) -> - sha512(split_binary(T, 128), sha512(M, Hashes)). - -sha384({M, <<>>}, Hashes) -> - [H0, H1, H2, H3, H4, H5 | _] = sha512(M, Hashes), - [H0, H1, H2, H3, H4, H5]; -sha384({M, T}, Hashes) -> - sha384(split_binary(T, 128), sha512(M, Hashes)). - - - -%%% These tests come from . The BASENAME macro above the -%%% read_test_vectors/0 fun is expected to be the basename of the test vectors filenames from that -%%% website. The tests read the test data from those files and compare against the expected results. Download -%%% this file to get the test data: . The test data in -%%% the "Expected" lists were either generated using the Python hashlib module, or were copied from the -%%% aforementioned URI/file; the copied data are subject to the following license: -%%% -%%% Copyright (c) 2000-2001, Aaron D. Gifford -%%% All rights reserved. -%%% -%%% Redistribution and use in source and binary forms, with or without -%%% modification, are permitted provided that the following conditions -%%% are met: -%%% 1. Redistributions of source code must retain the above copyright -%%% notice, this list of conditions and the following disclaimer. -%%% 2. Redistributions in binary form must reproduce the above copyright -%%% notice, this list of conditions and the following disclaimer in the -%%% documentation and/or other materials provided with the distribution. -%%% 3. Neither the name of the copyright holder nor the names of contributors -%%% may be used to endorse or promote products derived from this software -%%% without specific prior written permission. -%%% -%%% THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND -%%% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%%% ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE -%%% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -%%% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -%%% OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -%%% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -%%% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -%%% SUCH DAMAGE. - -%% @hidden -test() -> - Vectors = read_test_vectors(), - test224(Vectors), - test256(Vectors), - test384(Vectors), - test512(Vectors). - -%% @hidden -test224() -> - test224(read_test_vectors()). -test224(Vectors) -> - Expected224 = [<<16#23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7:224/big-unsigned>>, - <<16#75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525:224/big-unsigned>>, - <<16#c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3:224/big-unsigned>>, - <<16#62a41ab0961bcdd22db70b896db3955c1d04096af6de47f5aaad1226:224/big-unsigned>>, - <<16#d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f:224/big-unsigned>>, - <<16#d92622d56f83d869a884f6cc0763e90c4520a21e1cc429841e4584d2:224/big-unsigned>>, - <<16#0873433e1c8749dad0e34f92aff11c4b2ca310356283817747aa6940:224/big-unsigned>>, - <<16#5a69ccca0b5e7f84efda7c026d010fa46569c03f97b4440eba32b941:224/big-unsigned>>, - <<16#49e54148d21d457f2ffe28532543d91da98724c9883e67682301dec4:224/big-unsigned>>, - <<16#6417acfccd1d78cc14f1dd2de4ffcafe9cff0f92f0e28139866c2e2d:224/big-unsigned>>, - <<16#d4126ce69e15fc0c06cb1bf763f112b139ffd81189e3899e4e275560:224/big-unsigned>>, - <<16#0ace93ff0cfa76006af9db847f4ff2e702c2518dc946948807be0a47:224/big-unsigned>>, - <<16#91e452cfc8f22f9c69e637ec9dcf80d5798607a52234686fcf8880ad:224/big-unsigned>>, - <<16#bdaac28698611eba163f232785d8f4caffe29ac2fd8133651baf8212:224/big-unsigned>>, - <<16#4f41e1e6839ed85883ee0f259ac9025d19ecccbfc4d9d72f075ba5f2:224/big-unsigned>>, - <<16#4215dc642269cfd6d9b4b6da78fd01a9094bc89f4780905714b0a896:224/big-unsigned>>, - <<16#a1b0964a6d8188eb2980e126fefc70eb79d0745a91cc2f629af34ece:224/big-unsigned>>, - <<16#cc9286e04c4a39a6bb92a42f2ffabce02156090b6882b0ca22026294:224/big-unsigned>>], - io:format("testing SHA-224~n"), - test(fun hexdigest224/1, Vectors, Expected224, 1). - -%% @hidden -test256() -> - test256(read_test_vectors()). -test256(Vectors) -> - Expected256 = [<<16#ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad:256/big-unsigned>>, - <<16#248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1:256/big-unsigned>>, - <<16#cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1:256/big-unsigned>>, - <<16#4d25fccf8752ce470a58cd21d90939b7eb25f3fa418dd2da4c38288ea561e600:256/big-unsigned>>, - <<16#e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855:256/big-unsigned>>, - <<16#ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8:256/big-unsigned>>, - <<16#f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342:256/big-unsigned>>, - <<16#0ab803344830f92089494fb635ad00d76164ad6e57012b237722df0d7ad26896:256/big-unsigned>>, - <<16#e4326d0459653d7d3514674d713e74dc3df11ed4d30b4013fd327fdb9e394c26:256/big-unsigned>>, - <<16#a7f001d996dd25af402d03b5f61aef950565949c1a6ad5004efa730328d2dbf3:256/big-unsigned>>, - <<16#6dcd63a07b0922cc3a9b3315b158478681cc32543b0a4180abe58a73c5e14cc2:256/big-unsigned>>, - <<16#af6ebfde7d93d5badb6cde6287ecc2061c1cafc5b1c1217cd984fbcdb9c61aaa:256/big-unsigned>>, - <<16#8ff59c6d33c5a991088bc44dd38f037eb5ad5630c91071a221ad6943e872ac29:256/big-unsigned>>, - <<16#1818e87564e0c50974ecaabbb2eb4ca2f6cc820234b51861e2590be625f1f703:256/big-unsigned>>, - <<16#5e3dfe0cc98fd1c2de2a9d2fd893446da43d290f2512200c515416313cdf3192:256/big-unsigned>>, - <<16#80fced5a97176a5009207cd119551b42c5b51ceb445230d02ecc2663bbfb483a:256/big-unsigned>>, - <<16#88ee6ada861083094f4c64b373657e178d88ef0a4674fce6e4e1d84e3b176afb:256/big-unsigned>>, - <<16#5a2e925a7f8399fa63a20a1524ae83a7e3c48452f9af4df493c8c51311b04520:256/big-unsigned>>], - io:format("testing SHA-256~n"), - test(fun hexdigest256/1, Vectors, Expected256, 1). - -%% @hidden -test384() -> - test384(read_test_vectors()). -test384(Vectors) -> - Expected384 = [<<16#cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed:256/big-unsigned, - 16#8086072ba1e7cc2358baeca134c825a7:128/big-unsigned>>, - <<16#3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6:256/big-unsigned, - 16#b0455a8520bc4e6f5fe95b1fe3c8452b:128/big-unsigned>>, - <<16#09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712:256/big-unsigned, - 16#fcc7c71a557e2db966c3e9fa91746039:128/big-unsigned>>, - <<16#69cc75b95280bdd9e154e743903e37b1205aa382e92e051b1f48a6db9d0203f8:256/big-unsigned, - 16#a17c1762d46887037275606932d3381e:128/big-unsigned>>, - <<16#38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da:256/big-unsigned, - 16#274edebfe76f65fbd51ad2f14898b95b:128/big-unsigned>>, - <<16#e28e35e25a1874908bf0958bb088b69f3d742a753c86993e9f4b1c4c21988f95:256/big-unsigned, - 16#8bd1fe0315b195aca7b061213ac2a9bd:128/big-unsigned>>, - <<16#37b49ef3d08de53e9bd018b0630067bd43d09c427d06b05812f48531bce7d2a6:256/big-unsigned, - 16#98ee2d1ed1ffed46fd4c3b9f38a8a557:128/big-unsigned>>, - <<16#e3e3602f4d90c935321d788f722071a8809f4f09366f2825cd85da97ccd2955e:256/big-unsigned, - 16#b6b8245974402aa64789ed45293e94ba:128/big-unsigned>>, - <<16#1ca650f38480fa9dfb5729636bec4a935ebc1cd4c0055ee50cad2aa627e06687:256/big-unsigned, - 16#1044fd8e6fdb80edf10b85df15ba7aab:128/big-unsigned>>, - <<16#b8261ddcd7df7b3969a516b72550de6fbf0e394a4a7bb2bbc60ec603c2ceff64:256/big-unsigned, - 16#3c5bf62bc6dcbfa5beb54b62d750b969:128/big-unsigned>>, - <<16#548e4e9a1ff57f469ed47b023bf5279dfb4d4ca08c65051e3a5c41fab84479a2:256/big-unsigned, - 16#05496276906008b4b3c5b0970b2f5446:128/big-unsigned>>, - <<16#c6fec3a3278dd6b5afc8c0971d32d38faf5802f1a21527c32563b32a1ac34065:256/big-unsigned, - 16#6b433b44fe2648aa2232206f4301193a:128/big-unsigned>>, - <<16#92dca5655229b3c34796a227ff1809e273499adc2830149481224e0f54ff4483:256/big-unsigned, - 16#bd49834d4865e508ef53d4cd22b703ce:128/big-unsigned>>, - <<16#310fbb2027bdb7042f0e09e7b092e9ada506649510a7aa029825c8e8019e9c30:256/big-unsigned, - 16#749d723f2de1bd8c043d8d89d3748c2f:128/big-unsigned>>, - <<16#0d5e45317bc7997cb9c8a23bad9bac9170d5bc81789b51af6bcd74ace379fd64:256/big-unsigned, - 16#9a2b48cb56c4cb4ec1477e6933329e0e:128/big-unsigned>>, - <<16#aa1e77c094e5ce6db81a1add4c095201d020b7f8885a4333218da3b799b9fc42:256/big-unsigned, - 16#f00d60cd438a1724ae03bd7b515b739b:128/big-unsigned>>, - <<16#78cc6402a29eb984b8f8f888ab0102cabe7c06f0b9570e3d8d744c969db14397:256/big-unsigned, - 16#f58ecd14e70f324bf12d8dd4cd1ad3b2:128/big-unsigned>>, - <<16#72ec26cc742bc5fb1ef82541c9cadcf01a15c8104650d305f24ec8b006d7428e:256/big-unsigned, - 16#8ebe2bb320a465dbdd5c6326bbd8c9ad:128/big-unsigned>>], - io:format("testing SHA-384~n"), - test(fun hexdigest384/1, Vectors, Expected384, 1). - -%% @hidden -test512() -> - test512(read_test_vectors()). -test512(Vectors) -> - Expected512 = [<<16#ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a:256/big-unsigned, - 16#2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f:256/big-unsigned>>, - <<16#204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c335:256/big-unsigned, - 16#96fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445:256/big-unsigned>>, - <<16#8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018:256/big-unsigned, - 16#501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909:256/big-unsigned>>, - <<16#23450737795d2f6a13aa61adcca0df5eef6df8d8db2b42cd2ca8f783734217a7:256/big-unsigned, - 16#3e9cabc3c9b8a8602f8aeaeb34562b6b1286846060f9809b90286b3555751f09:256/big-unsigned>>, - <<16#cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce:256/big-unsigned, - 16#47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e:256/big-unsigned>>, - <<16#70aefeaa0e7ac4f8fe17532d7185a289bee3b428d950c14fa8b713ca09814a38:256/big-unsigned, - 16#7d245870e007a80ad97c369d193e41701aa07f3221d15f0e65a1ff970cedf030:256/big-unsigned>>, - <<16#b3de4afbc516d2478fe9b518d063bda6c8dd65fc38402dd81d1eb7364e72fb6e:256/big-unsigned, - 16#6663cf6d2771c8f5a6da09601712fb3d2a36c6ffea3e28b0818b05b0a8660766:256/big-unsigned>>, - <<16#97fb4ec472f3cb698b9c3c12a12768483e5b62bcdad934280750b4fa4701e5e0:256/big-unsigned, - 16#550a80bb0828342c19631ba55a55e1cee5de2fda91fc5d40e7bee1d4e6d415b3:256/big-unsigned>>, - <<16#d399507bbf5f2d0da51db1ff1fc51c1c9ff1de0937e00d01693b240e84fcc340:256/big-unsigned, - 16#0601429f45c297acc6e8fcf1e4e4abe9ff21a54a0d3d88888f298971bd206cd5:256/big-unsigned>>, - <<16#caf970d3638e21053173a638c4b94d6d1ff87bc47b58f8ee928fbe9e245c23ab:256/big-unsigned, - 16#f81019e45bf017ecc8610e5e0b95e3b025ccd611a772ca4fb3dfba26f0859725:256/big-unsigned>>, - <<16#ee5d07460183b130687c977e9f8d43110989b0864b18fe6ee00a53dec5eda111:256/big-unsigned, - 16#f3aaa3bac7ab8dae26ed545a4de33ed45190f18fa0c327c44642ab9424265330:256/big-unsigned>>, - <<16#73ffeb67716c3495fbc33f2d62fe08e2616706a5599881c7e67e9ef2b68f4988:256/big-unsigned, - 16#ea8b3b604ba87e50b07962692705c420fa31a00be41d6aaa9f3b11eafe9cf49b:256/big-unsigned>>, - <<16#0e928db6207282bfb498ee871202f2337f4074f3a1f5055a24f08e912ac118f8:256/big-unsigned, - 16#101832cdb9c2f702976e629183db9bacfdd7b086c800687c3599f15de7f7b9dd:256/big-unsigned>>, - <<16#a001636f3ff1ce34f432f8e8f7785b78be84318beb8485a406650a8b243c419f:256/big-unsigned, - 16#7db6435cf6bf3000c6524adb5b52bad01afb76b3ceff701331e18b85b0e4cbd3:256/big-unsigned>>, - <<16#735bd6bebfe6f8070d70069105bc761f35ed1ac3742f2e372fdc14d2a51898e6:256/big-unsigned, - 16#153ccaff9073324130abdc451c730dc5dab5a0452487b1171c4dd97f92e267b7:256/big-unsigned>>, - <<16#fae25ec70bcb3bbdef9698b9d579da49db68318dbdf18c021d1f76aaceff9628:256/big-unsigned, - 16#38873235597e7cce0c68aabc610e0deb79b13a01c302abc108e459ddfbe9bee8:256/big-unsigned>>, - <<16#211bec83fbca249c53668802b857a9889428dc5120f34b3eac1603f13d1b4796:256/big-unsigned, - 16#5c387b39ef6af15b3a44c5e7b6bbb6c1096a677dc98fc8f472737540a332f378:256/big-unsigned>>, - <<16#ebad464e6d9f1df7e8aadff69f52db40a001b253fbf65a018f29974dcc7fbf8e:256/big-unsigned, - 16#58b69e247975fbadb4153d7289357c9b6212752d0ab67dd3d9bbc0bb908aa98c:256/big-unsigned>>], - io:format("testing SHA-512~n"), - test(fun hexdigest512/1, Vectors, Expected512, 1). - -test(_, [], _, _) -> - ok; -test(Func, [Vector|Vectors], [Expect|Expected], Count) -> - Result = Func(Vector), - try - Result = Expect, - io:format(" test ~p passed~n", [Count]), - test(Func, Vectors, Expected, Count+1) - catch _:_ -> - io:format("error: expected ~s, got ~s~n", [Expect, Result]), - error - end. - --define(BASENAME, "/usr/local/src/sha2-1.0/testvectors/vector0"). - -read_test_vectors() -> - read_test_vectors(?BASENAME, [], 1). -read_test_vectors(_Base, Vectors, 19) -> - lists:reverse(Vectors); -read_test_vectors(Base, Vectors, Num) -> - {ok, Vector} = file:read_file(lists:flatten(io_lib:format("~s~2.10.0b.dat", [Base, Num]))), - read_test_vectors(Base, [Vector | Vectors], Num+1). diff --git a/apps/erlsha2/.gitignore b/apps/erlsha2/.gitignore deleted file mode 100644 index 98c49cc..0000000 --- a/apps/erlsha2/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -*~ -.eunit -c_src/config.h -c_src/*.o -ebin -priv -deps diff --git a/apps/erlsha2/AUTHORS b/apps/erlsha2/AUTHORS deleted file mode 100644 index c76d4e2..0000000 --- a/apps/erlsha2/AUTHORS +++ /dev/null @@ -1 +0,0 @@ -Steve Vinoski diff --git a/apps/erlsha2/LICENSE b/apps/erlsha2/LICENSE deleted file mode 100644 index 2c4bc71..0000000 --- a/apps/erlsha2/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2009-2011 Stephen B. Vinoski -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. diff --git a/apps/erlsha2/Makefile b/apps/erlsha2/Makefile deleted file mode 100644 index 1319737..0000000 --- a/apps/erlsha2/Makefile +++ /dev/null @@ -1,34 +0,0 @@ - -PREFIX:=../ -DEST:=$(PREFIX)$(PROJECT) - -# Expect to find rebar in the PATH. If you don't have rebar, you can get it -# from https://github.com/basho/rebar . -REBAR=rebar - -# Expect to find edown_make in the PATH. This is needed only to generate -# documentation. If you don't have it, you can get it from -# https://github.com/esl/edown.git . -EDOWN_MAKE=edown_make - -.PHONY: all edoc test clean build_plt dialyzer - -all: - @$(REBAR) get-deps compile - -edoc: - $(EDOWN_MAKE) -config edown.config - -test: - @rm -rf .eunit - @mkdir -p .eunit - @$(REBAR) skip_deps=true eunit - -clean: - @$(REBAR) clean - -build_plt: - @$(REBAR) build-plt - -dialyzer: - @$(REBAR) dialyze diff --git a/apps/erlsha2/README.md b/apps/erlsha2/README.md deleted file mode 100644 index 3c49c16..0000000 --- a/apps/erlsha2/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# SHA-224, SHA-256, SHA-384, SHA-512 implemented in Erlang NIFs. - -## Description - -The **erlsha2** library application implements the SHA-2 Secure Hash -Standard (SHA-224, SHA-256, SHA-384, SHA-512) using Erlang NIFs. (It -also provides pure Erlang implementations, though they are much slower -than the C NIF implementations.) It also includes HMAC wrappers for -the SHA-2 functions. - -See the following links for details: - -* [Secure Hash Standard (PDF)](http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf) -* [Wikipedia SHA1 article](http://en.wikipedia.org/wiki/SHA1) - -The code implemented here was written by simply following the -algorithm descriptions provided in the standard. Provided functions -follow the same style as those found in the standard Erlang `crypto` -module: for each hash variant there's a simple function returning a -binary digest and a set of three functions for initializing a digest -context, updating the context with additional data to be hashed, and -finalizing the context to get a binary digest result. - -This implementation replaces and obsoletes the -[original pure Erlang implementation](http://steve.vinoski.net/code/sha2.erl). - -## Building and Installing - -The **erlsha2** app is built with -[rebar](https://github.com/basho/rebar), which must be in the command -`PATH`. - -I don't use Windows at all so I doubt it builds there. I don't know of -any reason it shouldn't work there, though; you'll just have to build -it manually. If nothing else, you could comment out the `on_load` -directive in the Erlang file to prevent it from loading the NIF -implementation, thereby gaining access to the pure Erlang -implementation instead, but note that it's much slower than the C -code. - -If you run into any build trouble, first make sure the version of -`rebar` you're using is reasonably up to date. - -### Erlang Version - -The **erlsha2** app requires Erlang R14B or later. diff --git a/apps/erlsha2/c_src/config.sh b/apps/erlsha2/c_src/config.sh deleted file mode 100755 index 3e2e4e7..0000000 --- a/apps/erlsha2/c_src/config.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -CONFIG_HDR=$1 - -set -e - -tmpfile=`mktemp /tmp/erlsha2.XXXXXX` -tmpcfile=${tmpfile}.c -trap "rm -f $tmpfile $tmpcfile" EXIT -mv $tmpfile $tmpcfile -echo '#include ' > $tmpcfile -if $CC $CFLAGS -c -o /dev/null $tmpcfile 2>/dev/null ; then - echo '#define HAVE_STDINT_H 1' > $CONFIG_HDR -else - echo '#include ' > $tmpcfile - if $CC $CFLAGS -c -o /dev/null $tmpcfile 2>/dev/null ; then - echo '#define HAVE_INTTYPES_H 1' > $CONFIG_HDR - else - echo 'neither nor found, aborting' 1>&2 - exit 1 - fi -fi - -v='16#12345678' -prog="case <<$v:32/native>> of <<$v:32/big>> -> 0; <<$v:32/little>> -> 1 end" -if erl -noinput -noshell -eval "halt($prog)."; then - echo '#define WORDS_BIGENDIAN 1' >> $CONFIG_HDR -else - echo '#undef WORDS_BIGENDIAN' >> $CONFIG_HDR -fi - -exit 0 diff --git a/apps/erlsha2/c_src/erlsha2_nif.c b/apps/erlsha2/c_src/erlsha2_nif.c deleted file mode 100644 index e6a44b3..0000000 --- a/apps/erlsha2/c_src/erlsha2_nif.c +++ /dev/null @@ -1,785 +0,0 @@ -/* - * Copyright (c) 2009-2011 Stephen B. Vinoski - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" -#if HAVE_STDINT_H -#include -#elif HAVE_INTTYPES_H -#include -#endif -#include -#include "erl_nif.h" - - -#ifndef WORDS_BIGENDIAN -#define BYTESWAP32(x) \ - ((((uint32_t)(x) & 0x000000FF) << 24) | \ - (((uint32_t)(x) & 0x0000FF00) << 8) | \ - (((uint32_t)(x) >> 8) & 0x0000FF00) | \ - (((uint32_t)(x) >> 24) & 0x000000FF)) - -#define BYTESWAP64(x) \ - (((uint64_t)(x) << 56) | \ - (((uint64_t)(x) << 40) & 0X00FF000000000000ULL) | \ - (((uint64_t)(x) << 24) & 0X0000FF0000000000ULL) | \ - (((uint64_t)(x) << 8) & 0X000000FF00000000ULL) | \ - (((uint64_t)(x) >> 8) & 0X00000000FF000000ULL) | \ - (((uint64_t)(x) >> 24) & 0X0000000000FF0000ULL) | \ - (((uint64_t)(x) >> 40) & 0X000000000000FF00ULL) | \ - ((uint64_t)(x) >> 56)) -#endif - -static uint32_t H224[] = { - 0xC1059ED8, - 0x367CD507, - 0x3070DD17, - 0xF70E5939, - 0xFFC00B31, - 0x68581511, - 0x64F98FA7, - 0xBEFA4FA4, -}; - -static uint32_t H256[] = { - 0x6A09E667, - 0xBB67AE85, - 0x3C6EF372, - 0xA54FF53A, - 0x510E527F, - 0x9B05688C, - 0x1F83D9AB, - 0x5BE0CD19, -}; - -static uint64_t H384[] = { - 0xCBBB9D5DC1059ED8ULL, - 0x629A292A367CD507ULL, - 0x9159015A3070DD17ULL, - 0x152FECD8F70E5939ULL, - 0x67332667FFC00B31ULL, - 0x8EB44A8768581511ULL, - 0xDB0C2E0D64F98FA7ULL, - 0x47B5481DBEFA4FA4ULL, -}; - -static uint64_t H512[] = { - 0x6A09E667F3BCC908ULL, - 0xBB67AE8584CAA73BULL, - 0x3C6EF372FE94F82BULL, - 0xA54FF53A5F1D36F1ULL, - 0x510E527FADE682D1ULL, - 0x9B05688C2B3E6C1FULL, - 0x1F83D9ABFB41BD6BULL, - 0x5BE0CD19137E2179ULL, -}; - -static uint32_t K256[] = { - 0x428A2F98, - 0x71374491, - 0xB5C0FBCF, - 0xE9B5DBA5, - 0x3956C25B, - 0x59F111F1, - 0x923F82A4, - 0xAB1C5ED5, - 0xD807AA98, - 0x12835B01, - 0x243185BE, - 0x550C7DC3, - 0x72BE5D74, - 0x80DEB1FE, - 0x9BDC06A7, - 0xC19BF174, - 0xE49B69C1, - 0xEFBE4786, - 0x0FC19DC6, - 0x240CA1CC, - 0x2DE92C6F, - 0x4A7484AA, - 0x5CB0A9DC, - 0x76F988DA, - 0x983E5152, - 0xA831C66D, - 0xB00327C8, - 0xBF597FC7, - 0xC6E00BF3, - 0xD5A79147, - 0x06CA6351, - 0x14292967, - 0x27B70A85, - 0x2E1B2138, - 0x4D2C6DFC, - 0x53380D13, - 0x650A7354, - 0x766A0ABB, - 0x81C2C92E, - 0x92722C85, - 0xA2BFE8A1, - 0xA81A664B, - 0xC24B8B70, - 0xC76C51A3, - 0xD192E819, - 0xD6990624, - 0xF40E3585, - 0x106AA070, - 0x19A4C116, - 0x1E376C08, - 0x2748774C, - 0x34B0BCB5, - 0x391C0CB3, - 0x4ED8AA4A, - 0x5B9CCA4F, - 0x682E6FF3, - 0x748F82EE, - 0x78A5636F, - 0x84C87814, - 0x8CC70208, - 0x90BEFFFA, - 0xA4506CEB, - 0xBEF9A3F7, - 0xC67178F2, -}; - -static uint64_t K512[] = { - 0x428A2F98D728AE22ULL, - 0x7137449123EF65CDULL, - 0xB5C0FBCFEC4D3B2FULL, - 0xE9B5DBA58189DBBCULL, - 0x3956C25BF348B538ULL, - 0x59F111F1B605D019ULL, - 0x923F82A4AF194F9BULL, - 0xAB1C5ED5DA6D8118ULL, - 0xD807AA98A3030242ULL, - 0x12835B0145706FBEULL, - 0x243185BE4EE4B28CULL, - 0x550C7DC3D5FFB4E2ULL, - 0x72BE5D74F27B896FULL, - 0x80DEB1FE3B1696B1ULL, - 0x9BDC06A725C71235ULL, - 0xC19BF174CF692694ULL, - 0xE49B69C19EF14AD2ULL, - 0xEFBE4786384F25E3ULL, - 0x0FC19DC68B8CD5B5ULL, - 0x240CA1CC77AC9C65ULL, - 0x2DE92C6F592B0275ULL, - 0x4A7484AA6EA6E483ULL, - 0x5CB0A9DCBD41FBD4ULL, - 0x76F988DA831153B5ULL, - 0x983E5152EE66DFABULL, - 0xA831C66D2DB43210ULL, - 0xB00327C898FB213FULL, - 0xBF597FC7BEEF0EE4ULL, - 0xC6E00BF33DA88FC2ULL, - 0xD5A79147930AA725ULL, - 0x06CA6351E003826FULL, - 0x142929670A0E6E70ULL, - 0x27B70A8546D22FFCULL, - 0x2E1B21385C26C926ULL, - 0x4D2C6DFC5AC42AEDULL, - 0x53380D139D95B3DFULL, - 0x650A73548BAF63DEULL, - 0x766A0ABB3C77B2A8ULL, - 0x81C2C92E47EDAEE6ULL, - 0x92722C851482353BULL, - 0xA2BFE8A14CF10364ULL, - 0xA81A664BBC423001ULL, - 0xC24B8B70D0F89791ULL, - 0xC76C51A30654BE30ULL, - 0xD192E819D6EF5218ULL, - 0xD69906245565A910ULL, - 0xF40E35855771202AULL, - 0x106AA07032BBD1B8ULL, - 0x19A4C116B8D2D0C8ULL, - 0x1E376C085141AB53ULL, - 0x2748774CDF8EEB99ULL, - 0x34B0BCB5E19B48A8ULL, - 0x391C0CB3C5C95A63ULL, - 0x4ED8AA4AE3418ACBULL, - 0x5B9CCA4F7763E373ULL, - 0x682E6FF3D6B2B8A3ULL, - 0x748F82EE5DEFB2FCULL, - 0x78A5636F43172F60ULL, - 0x84C87814A1F0AB72ULL, - 0x8CC702081A6439ECULL, - 0x90BEFFFA23631E28ULL, - 0xA4506CEBDE82BDE9ULL, - 0xBEF9A3F7B2C67915ULL, - 0xC67178F2E372532BULL, - 0xCA273ECEEA26619CULL, - 0xD186B8C721C0C207ULL, - 0xEADA7DD6CDE0EB1EULL, - 0xF57D4F7FEE6ED178ULL, - 0x06F067AA72176FBAULL, - 0x0A637DC5A2C898A6ULL, - 0x113F9804BEF90DAEULL, - 0x1B710B35131C471BULL, - 0x28DB77F523047D84ULL, - 0x32CAAB7B40C72493ULL, - 0x3C9EBE0A15C9BEBCULL, - 0x431D67C49C100D4CULL, - 0x4CC5D4BECB3E42B6ULL, - 0x597F299CFC657E2AULL, - 0x5FCB6FAB3AD6FAECULL, - 0x6C44198C4A475817ULL, -}; - -#define PADDED_SIZE_2XX 512 -#define PADDED_SIZE_2XX_BYTES PADDED_SIZE_2XX/8 -#define CONGRUENCE_2XX 448 -#define PADDED_SIZE_5XX 1024 -#define PADDED_SIZE_5XX_BYTES PADDED_SIZE_5XX/8 -#define CONGRUENCE_5XX 896 - -typedef struct { - uint64_t bitlen; - unsigned char bytes[2*PADDED_SIZE_5XX_BYTES]; - ErlNifBinary digest; - size_t count; - size_t size; -} Context; - -typedef union { - Context* c; - void* v; -} ContextUnion; - -typedef void (*ChunkHandler)(Context* ctx, unsigned char* chunk); - -typedef ERL_NIF_TERM (*TermArgcArgvFun)( - ErlNifEnv* env, - int argc, - const ERL_NIF_TERM argv[] -); -typedef int (*BoolArgcArgvFun)( - ErlNifEnv* env, - int argc, - const ERL_NIF_TERM argv[] -); - -static void -pad(unsigned char* bin, uint64_t binsize, Context* ctx) -{ - unsigned char* p; - uint64_t congruence = ctx->size == PADDED_SIZE_2XX_BYTES ? - CONGRUENCE_2XX : CONGRUENCE_5XX; - uint64_t lenbits = ctx->bitlen; - uint64_t pad; - - while (lenbits + 1 > congruence) { - congruence += ctx->size*8; - } - pad = (congruence - (lenbits + 1)) / 8; - if (ctx->size == PADDED_SIZE_5XX_BYTES) { - pad += 8; - } - if (bin != NULL && binsize > 0) { - memcpy(ctx->bytes + ctx->count, bin, binsize); - ctx->count += binsize; - } - p = ctx->bytes + ctx->count; - *p++ = 0x80; - memset(p, 0, pad); -#ifndef WORDS_BIGENDIAN - *(uint64_t*)(p + pad) = BYTESWAP64(lenbits); -#else - *(uint64_t*)(p + pad) = lenbits; -#endif - ctx->count += 1 + pad + sizeof lenbits; -} - -static void -context_init(Context* ctx, void* hashes, size_t hsize, size_t padsize) -{ - enif_alloc_binary(hsize, &ctx->digest); - memcpy(ctx->digest.data, hashes, hsize); - ctx->bitlen = 0; - ctx->count = 0; - ctx->size = padsize/8; -} - -static ERL_NIF_TERM -context_fini(ErlNifEnv* env, Context* ctx, size_t dsize, ChunkHandler handler) -{ - ERL_NIF_TERM result; - ctx->bitlen += ctx->count*8; - pad(0, 0, ctx); - handler(ctx, ctx->bytes); - if (ctx->count > ctx->size) { - handler(ctx, ctx->bytes + ctx->size); - } -#ifndef WORDS_BIGENDIAN - { - int i; - if (ctx->size == PADDED_SIZE_2XX_BYTES) { - uint32_t* hash = (uint32_t*)ctx->digest.data; - for (i = 0; i < ctx->digest.size/sizeof(*hash); ++i) { - hash[i] = BYTESWAP32(hash[i]); - } - } else { - uint64_t* hash = (uint64_t*)ctx->digest.data; - for (i = 0; i < ctx->digest.size/sizeof(*hash); ++i) { - hash[i] = BYTESWAP64(hash[i]); - } - } - } -#endif - if (ctx->digest.size != dsize) { - enif_realloc_binary(&ctx->digest, dsize); - } - result = enif_make_binary(env, &ctx->digest); - ctx->digest.size = 0; - return result; -} - -#define CH(x,y,z) (((x) & (y)) ^ (~(x) & z)) -#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) - -#define ROTR(v, rotate, width) (((v) >> (rotate)) | ((v) << ((width)-(rotate)))) -#define ROTR32(v, rotate) ROTR(v, rotate, 32) -#define ROTR64(v, rotate) ROTR(v, rotate, 64) -#define SHIFTR(v, shift) ((v) >> (shift)) - -#define BIG_SIGMA256_0(x) (ROTR32(x,2) ^ ROTR32(x,13) ^ ROTR32(x,22)) -#define BIG_SIGMA256_1(x) (ROTR32(x,6) ^ ROTR32(x,11) ^ ROTR32(x,25)) -#define SM_SIGMA256_0(x) (ROTR32(x,7) ^ ROTR32(x,18) ^ SHIFTR(x,3)) -#define SM_SIGMA256_1(x) (ROTR32(x,17) ^ ROTR32(x,19) ^ SHIFTR(x,10)) - -#define BIG_SIGMA512_0(x) (ROTR64(x,28) ^ ROTR64(x,34) ^ ROTR64(x,39)) -#define BIG_SIGMA512_1(x) (ROTR64(x,14) ^ ROTR64(x,18) ^ ROTR64(x,41)) -#define SM_SIGMA512_0(x) (ROTR64(x,1) ^ ROTR64(x,8) ^ SHIFTR(x,7)) -#define SM_SIGMA512_1(x) (ROTR64(x,19) ^ ROTR64(x,61) ^ SHIFTR(x,6)) - -#define DIGEST_SIZE_224 28 -#define DIGEST_SIZE_256 32 -#define DIGEST_SIZE_384 48 -#define DIGEST_SIZE_512 64 - -static void -sha_update_chunks(Context* ctx, ErlNifBinary* data, ChunkHandler handler) -{ - size_t chunk, chunk_total, datasize, extra; - unsigned char* p = data->data; - datasize = data->size; - if (ctx->count != 0) { - extra = ctx->size - ctx->count; - if (extra > datasize) { - extra = datasize; - } - memcpy(ctx->bytes + ctx->count, p, extra); - ctx->count += extra; - if (ctx->count == ctx->size) { - handler(ctx, ctx->bytes); - ctx->bitlen += ctx->size*8; - ctx->count = 0; - } - p += extra; - datasize -= extra; - } - chunk_total = datasize/ctx->size; - for (chunk = 0; chunk < chunk_total; ++chunk) { - handler(ctx, p); - ctx->bitlen += ctx->size*8; - p += ctx->size; - datasize -= ctx->size; - } - extra = datasize % ctx->size; - if (extra != 0) { - memcpy(ctx->bytes, p, extra); - ctx->count = extra; - } -} - -static void -sha2xx_chunk(Context* ctx, unsigned char* chunk) -{ - uint32_t* hash = (uint32_t*)ctx->digest.data; - uint32_t a, b, c, d, e, f, g, h; - uint32_t words[64]; - int i; -#ifndef WORDS_BIGENDIAN - { - uint32_t* from = (uint32_t*)chunk; - for (i = 0; i < 16; ++i) { - words[i] = BYTESWAP32(from[i]); - } - } -#else - memcpy(words, chunk, 16*sizeof(*words)); -#endif - for (i = 16; i < sizeof(words)/sizeof(*words); ++i) { - uint32_t w15 = words[i-15], w2 = words[i-2]; - uint32_t s0 = SM_SIGMA256_0(w15), s1 = SM_SIGMA256_1(w2); - uint32_t w7 = words[i-7], w16 = words[i-16]; - words[i] = s1 + w7 + s0 + w16; - } - a = hash[0]; b = hash[1]; c = hash[2]; d = hash[3]; - e = hash[4]; f = hash[5]; g = hash[6]; h = hash[7]; - for (i = 0; i < sizeof(words)/sizeof(*words); ++i) { - uint32_t t1, t2; - t1 = h + BIG_SIGMA256_1(e) + CH(e,f,g) + K256[i] + words[i]; - t2 = BIG_SIGMA256_0(a) + MAJ(a,b,c); - h = g; - g = f; - f = e; - e = d + t1; - d = c; - c = b; - b = a; - a = t1 + t2; - } - hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; - hash[4] += e; hash[5] += f; hash[6] += g; hash[7] += h; -} - -static ERL_NIF_TERM -sha( - ErlNifEnv* env, - int argc, - const ERL_NIF_TERM argv[], - TermArgcArgvFun hd_init, - BoolArgcArgvFun hd_update, - TermArgcArgvFun hd_final -) -{ - ERL_NIF_TERM ctx = hd_init(env, argc, argv); - ERL_NIF_TERM args[2] = {ctx, argv[0]}; - ERL_NIF_TERM nargs[1]; - if (!hd_update(env, 2, args)) { - return enif_make_badarg(env); - } - nargs[0] = ctx; - return hd_final(env, 1, nargs); -} - -static ERL_NIF_TERM -hd224_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ERL_NIF_TERM result; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - Context* ctx = (Context*)enif_alloc_resource(ctx_type, sizeof(Context)); - context_init(ctx, H224, sizeof H224, PADDED_SIZE_2XX); - result = enif_make_resource(env, ctx); - enif_release_resource(ctx); - return result; -} - -static int -hd2xx_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ErlNifBinary data; - ContextUnion ctxu; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - if (!enif_get_resource(env, argv[0], ctx_type, &ctxu.v)) { - return 0; - } - if (!enif_inspect_iolist_as_binary(env, argv[1], &data)) { - return 0; - } - sha_update_chunks(ctxu.c, &data, sha2xx_chunk); - return 1; -} - -static ERL_NIF_TERM -hd224_final(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ContextUnion ctxu; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - if (!enif_get_resource(env, argv[0], ctx_type, &ctxu.v)) { - return enif_make_badarg(env); - } - return context_fini(env, ctxu.c, DIGEST_SIZE_224, sha2xx_chunk); -} - -static ERL_NIF_TERM -sha224(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return sha(env, argc, argv, hd224_init, hd2xx_update, hd224_final); -} - -static ERL_NIF_TERM -sha224_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd224_init(env, argc, argv); -} - -static ERL_NIF_TERM -sha224_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd2xx_update(env, argc, argv) ? argv[0] : enif_make_badarg(env); -} - -static ERL_NIF_TERM -sha224_final(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd224_final(env, argc, argv); -} - -static ERL_NIF_TERM -hd256_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ERL_NIF_TERM result; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - Context* ctx = (Context*)enif_alloc_resource(ctx_type, sizeof(Context)); - context_init(ctx, H256, sizeof H256, PADDED_SIZE_2XX); - result = enif_make_resource(env, ctx); - enif_release_resource(ctx); - return result; -} - -static ERL_NIF_TERM -hd256_final(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ContextUnion ctxu; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - if (!enif_get_resource(env, argv[0], ctx_type, &ctxu.v)) { - return enif_make_badarg(env); - } - return context_fini(env, ctxu.c, DIGEST_SIZE_256, sha2xx_chunk); -} - -static ERL_NIF_TERM -sha256(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return sha(env, argc, argv, hd256_init, hd2xx_update, hd256_final); -} - -static ERL_NIF_TERM -sha256_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd256_init(env, argc, argv); -} - -static ERL_NIF_TERM -sha256_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd2xx_update(env, argc, argv) ? argv[0] : enif_make_badarg(env); -} - -static ERL_NIF_TERM -sha256_final(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd256_final(env, argc, argv); -} - -static void -sha5xx_chunk(Context* ctx, unsigned char* chunk) -{ - uint64_t* hash = (uint64_t*)ctx->digest.data; - uint64_t a, b, c, d, e, f, g, h; - uint64_t words[80]; - int i; -#ifndef WORDS_BIGENDIAN - { - uint64_t* from = (uint64_t*)chunk; - for (i = 0; i < 16; ++i) { - words[i] = BYTESWAP64(from[i]); - } - } -#else - memcpy(words, chunk, 16*sizeof(*words)); -#endif - for (i = 16; i < sizeof(words)/sizeof(*words); ++i) { - uint64_t w15 = words[i-15], w2 = words[i-2]; - uint64_t s0 = SM_SIGMA512_0(w15), s1 = SM_SIGMA512_1(w2); - uint64_t w7 = words[i-7], w16 = words[i-16]; - words[i] = s1 + w7 + s0 + w16; - } - a = hash[0]; b = hash[1]; c = hash[2]; d = hash[3]; - e = hash[4]; f = hash[5]; g = hash[6]; h = hash[7]; - for (i = 0; i < sizeof(words)/sizeof(*words); ++i) { - uint64_t t1, t2; - t1 = h + BIG_SIGMA512_1(e) + CH(e,f,g) + K512[i] + words[i]; - t2 = BIG_SIGMA512_0(a) + MAJ(a,b,c); - h = g; - g = f; - f = e; - e = d + t1; - d = c; - c = b; - b = a; - a = t1 + t2; - } - hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; - hash[4] += e; hash[5] += f; hash[6] += g; hash[7] += h; -} - -static ERL_NIF_TERM -hd384_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ERL_NIF_TERM result; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - Context* ctx = (Context*)enif_alloc_resource(ctx_type, sizeof(Context)); - context_init(ctx, H384, sizeof H384, PADDED_SIZE_5XX); - result = enif_make_resource(env, ctx); - enif_release_resource(ctx); - return result; -} - -static int -hd5xx_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ErlNifBinary data; - ContextUnion ctxu; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - if (!enif_get_resource(env, argv[0], ctx_type, &ctxu.v)) { - return 0; - } - if (!enif_inspect_iolist_as_binary(env, argv[1], &data)) { - return 0; - } - sha_update_chunks(ctxu.c, &data, sha5xx_chunk); - return 1; -} - -static ERL_NIF_TERM -hd384_final(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ContextUnion ctxu; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - if (!enif_get_resource(env, argv[0], ctx_type, &ctxu.v)) { - return enif_make_badarg(env); - } - return context_fini(env, ctxu.c, DIGEST_SIZE_384, sha5xx_chunk); -} - -static ERL_NIF_TERM -sha384(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return sha(env, argc, argv, hd384_init, hd5xx_update, hd384_final); -} - -static ERL_NIF_TERM -sha384_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd384_init(env, argc, argv); -} - -static ERL_NIF_TERM -sha384_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd5xx_update(env, argc, argv) ? argv[0] : enif_make_badarg(env); -} - -static ERL_NIF_TERM -sha384_final(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd384_final(env, argc, argv); -} - -static ERL_NIF_TERM -hd512_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ERL_NIF_TERM result; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - Context* ctx = (Context*)enif_alloc_resource(ctx_type, sizeof(Context)); - context_init(ctx, H512, sizeof H512, PADDED_SIZE_5XX); - result = enif_make_resource(env, ctx); - enif_release_resource(ctx); - return result; -} - -static ERL_NIF_TERM -hd512_final(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - ContextUnion ctxu; - ErlNifResourceType* ctx_type = (ErlNifResourceType*)enif_priv_data(env); - if (!enif_get_resource(env, argv[0], ctx_type, &ctxu.v)) { - return enif_make_badarg(env); - } - return context_fini(env, ctxu.c, DIGEST_SIZE_512, sha5xx_chunk); -} - -static ERL_NIF_TERM -sha512(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return sha(env, argc, argv, hd512_init, hd5xx_update, hd512_final); -} - -static ERL_NIF_TERM -sha512_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd512_init(env, argc, argv); -} - -static ERL_NIF_TERM -sha512_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd5xx_update(env, argc, argv) ? argv[0] : enif_make_badarg(env); -} - -static ERL_NIF_TERM -sha512_final(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) -{ - return hd512_final(env, argc, argv); -} - -static ErlNifFunc funcs[] = { - {"sha224", 1, sha224}, - {"sha224_init", 0, sha224_init}, - {"sha224_update", 2, sha224_update}, - {"sha224_final", 1, sha224_final}, - {"sha256", 1, sha256}, - {"sha256_init", 0, sha256_init}, - {"sha256_update", 2, sha256_update}, - {"sha256_final", 1, sha256_final}, - {"sha384", 1, sha384}, - {"sha384_init", 0, sha384_init}, - {"sha384_update", 2, sha384_update}, - {"sha384_final", 1, sha384_final}, - {"sha512", 1, sha512}, - {"sha512_init", 0, sha512_init}, - {"sha512_update", 2, sha512_update}, - {"sha512_final", 1, sha512_final}, -}; - -static void -context_dtor(ErlNifEnv* env, void* obj) -{ - Context* ctx = (Context*)obj; - if (ctx != NULL && ctx->digest.size > 0) { - enif_release_binary(&ctx->digest); - } -} - -static int -nifload(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) -{ - *priv_data = enif_open_resource_type( - env, - NULL, - "erlsha2_context", - context_dtor, - ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER, - NULL - ); - return 0; -} - -ERL_NIF_INIT(erlsha2, funcs, nifload, NULL, NULL, NULL) diff --git a/apps/erlsha2/doc/README.md b/apps/erlsha2/doc/README.md deleted file mode 100644 index 0ccc456..0000000 --- a/apps/erlsha2/doc/README.md +++ /dev/null @@ -1,12 +0,0 @@ - - -#The erlsha2 application# - - -##Modules## - - - - -
erlsha2
hmac
- diff --git a/apps/erlsha2/doc/edoc-info b/apps/erlsha2/doc/edoc-info deleted file mode 100644 index c4ed9a9..0000000 --- a/apps/erlsha2/doc/edoc-info +++ /dev/null @@ -1,3 +0,0 @@ -{application,erlsha2}. -{packages,[]}. -{modules,[erlsha2,hmac]}. diff --git a/apps/erlsha2/doc/erlsha2.md b/apps/erlsha2/doc/erlsha2.md deleted file mode 100644 index c620228..0000000 --- a/apps/erlsha2/doc/erlsha2.md +++ /dev/null @@ -1,204 +0,0 @@ - - -#Module erlsha2# -* [Description](#description) -* [Function Index](#index) -* [Function Details](#functions) - - -Implementations of SHA-224, SHA-256, SHA-384, SHA-512 in Erlang NIFs. - -Copyright (c) 2009-2011 Stephen B. Vinoski, All rights reserved. Open source, BSD License - -__Version:__ 2.0 - - -__Introduced in:__ 03 Jan 2009 - - -__Authors:__ Steve Vinoski ([`vinoski@ieee.org`](mailto:vinoski@ieee.org)) (_web site:_ [`http://steve.vinoski.net/`](http://steve.vinoski.net/)). - -__References__* See [ -the Secure Hash Standard](http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf) and the [Wikipedia SHA1 -article](http://en.wikipedia.org/wiki/SHA1). Find the code [here](http://github.com/vinoski/erlsha2). - - -##Function Index## - - -
sha224/1Returns a SHA-224 hexadecimal digest.
sha224_final/1Finishes the update of a SHA-224 Context and returns the computed -message digest.
sha224_init/0Creates a SHA-224 context to be in subsequent calls to -sha224_update/2.
sha224_update/2Updates a SHA-224 context with message data and returns a new -context.
sha256/1Returns a SHA-256 hexadecimal digest.
sha256_final/1Finishes the update of a SHA-256 Context and returns the computed -message digest.
sha256_init/0Creates a SHA-256 context to be in subsequent calls to -sha256_update/2.
sha256_update/2Updates a SHA-256 context with message data and returns a new -context.
sha384/1Returns a SHA-384 hexadecimal digest.
sha384_final/1Finishes the update of a SHA-384 Context and returns the computed -message digest.
sha384_init/0Creates a SHA-384 context to be in subsequent calls to -sha384_update/2.
sha384_update/2Updates a SHA-384 context with message data and returns a new -context.
sha512/1Returns a SHA-512 hexadecimal digest.
sha512_final/1Finishes the update of a SHA-512 Context and returns the computed -message digest.
sha512_init/0Creates a SHA-512 context to be in subsequent calls to -sha512_update/2.
sha512_update/2Updates a SHA-512 context with message data and returns a new -context.
- - - - -##Function Details## - - - -###sha224/1## - - -
sha224(M :: message()) -> digest()
-
  • <a name="type-message">message()</a> = binary() | iolist()
  • <a name="type-digest">digest()</a> = binary()
- -Returns a SHA-224 hexadecimal digest. - - -###sha224_final/1## - - -
sha224_final(Context :: context()) -> digest()
-
  • <a name="type-context">context()</a> = binary()
  • <a name="type-digest">digest()</a> = binary()
- -Finishes the update of a SHA-224 Context and returns the computed -message digest. - - -###sha224_init/0## - - -
sha224_init() -> context()
-
  • <a name="type-context">context()</a> = binary()
- -Creates a SHA-224 context to be in subsequent calls to -sha224_update/2. - - -###sha224_update/2## - - -
sha224_update(Context :: context(), M :: message()) ->newcontext()
-
  • <a name="type-message">message()</a> = binary() | iolist()
  • <a name="type-context">context()</a> = binary()
  • <a name="type-newcontext">newcontext()</a> = binary()
- -Updates a SHA-224 context with message data and returns a new -context. - - -###sha256/1## - - -
sha256(M :: message()) -> digest()
-
  • <a name="type-message">message()</a> = binary() | iolist()
  • <a name="type-digest">digest()</a> = binary()
- -Returns a SHA-256 hexadecimal digest. - - -###sha256_final/1## - - -
sha256_final(Context :: context()) -> digest()
-
  • <a name="type-context">context()</a> = binary()
  • <a name="type-digest">digest()</a> = binary()
- -Finishes the update of a SHA-256 Context and returns the computed -message digest. - - -###sha256_init/0## - - -
sha256_init() -> context()
-
  • <a name="type-context">context()</a> = binary()
- -Creates a SHA-256 context to be in subsequent calls to -sha256_update/2. - - -###sha256_update/2## - - -
sha256_update(Context :: context(), M :: message()) ->newcontext()
-
  • <a name="type-message">message()</a> = binary() | iolist()
  • <a name="type-context">context()</a> = binary()
  • <a name="type-newcontext">newcontext()</a> = binary()
- -Updates a SHA-256 context with message data and returns a new -context. - - -###sha384/1## - - -
sha384(M :: message()) -> digest()
-
  • <a name="type-message">message()</a> = binary() | iolist()
  • <a name="type-digest">digest()</a> = binary()
- -Returns a SHA-384 hexadecimal digest. -If the argument is a binary, the result is a binary, otherwise the - - -###sha384_final/1## - - -
sha384_final(Context :: context()) -> digest()
-
  • <a name="type-context">context()</a> = binary()
  • <a name="type-digest">digest()</a> = binary()
- -Finishes the update of a SHA-384 Context and returns the computed -message digest. - - -###sha384_init/0## - - -
sha384_init() -> context()
-
  • <a name="type-context">context()</a> = binary()
- -Creates a SHA-384 context to be in subsequent calls to -sha384_update/2. - - -###sha384_update/2## - - -
sha384_update(Context :: context(), M :: message()) ->newcontext()
-
  • <a name="type-message">message()</a> = binary() | iolist()
  • <a name="type-context">context()</a> = binary()
  • <a name="type-newcontext">newcontext()</a> = binary()
- -Updates a SHA-384 context with message data and returns a new -context. - - -###sha512/1## - - -
sha512(M :: message()) -> digest()
-
  • <a name="type-message">message()</a> = binary() | iolist()
  • <a name="type-digest">digest()</a> = binary()
- -Returns a SHA-512 hexadecimal digest. - - -###sha512_final/1## - - -
sha512_final(Context :: context()) -> digest()
-
  • <a name="type-context">context()</a> = binary()
  • <a name="type-digest">digest()</a> = binary()
- -Finishes the update of a SHA-512 Context and returns the computed -message digest. - - -###sha512_init/0## - - -
sha512_init() -> context()
-
  • <a name="type-context">context()</a> = binary()
- -Creates a SHA-512 context to be in subsequent calls to -sha512_update/2. - - -###sha512_update/2## - - -
sha512_update(Context :: context(), M :: message()) ->newcontext()
-
  • <a name="type-message">message()</a> = binary() | iolist()
  • <a name="type-context">context()</a> = binary()
  • <a name="type-newcontext">newcontext()</a> = binary()
- -Updates a SHA-512 context with message data and returns a new -context. diff --git a/apps/erlsha2/doc/hmac.md b/apps/erlsha2/doc/hmac.md deleted file mode 100644 index f841ac5..0000000 --- a/apps/erlsha2/doc/hmac.md +++ /dev/null @@ -1,93 +0,0 @@ - - -#Module hmac# -* [Description](#description) -* [Function Index](#index) -* [Function Details](#functions) - - -HMAC wrappers for erlsha2. - -__Authors:__ Jared Flatow, Steve Vinoski. - -__References__* Based on the -[ -mailing list response -](http://erlang.org/pipermail/erlang-questions/2011-May/058174.md) -by Steve Davis. - - -##Function Index## - - -
hexlify/1Convert binary to equivalent hexadecimal string.
hmac/2Compute a SHA MAC message authentication code from key and data.
hmac/4Compute a SHA MAC message authentication code from key and data using -the specified hash function and blocksize.
hmac224/2Compute a SHA-224 MAC message authentication code from key and data.
hmac256/2Compute a SHA-256 MAC message authentication code from key and data.
hmac384/2Compute a SHA-384 MAC message authentication code from key and data.
hmac512/2Compute a SHA-512 MAC message authentication code from key and data.
- - - - -##Function Details## - - - -###hexlify/1## - - -
hexlify(Binary :: binary()) -> list()
- -Convert binary to equivalent hexadecimal string. - - -###hmac/2## - - -
hmac(Key :: key(), Data :: data()) -> mac()
-
  • <a name="type-key">key()</a> = iolist() | binary()
  • <a name="type-data">data()</a> = iolist() | binary()
  • <a name="type-mac">mac()</a> = binary()
- -Compute a SHA MAC message authentication code from key and data. - - -###hmac/4## - - -
hmac(Key :: key(),Data :: data(),Hash :: hash(),Blocksize :: blocksize()) ->mac()
-
  • <a name="type-key">key()</a> = iolist() | binary()
  • <a name="type-data">data()</a> = iolist() | binary()
  • <a name="type-hash">hash()</a> = fun((binary()) -> binary())
  • <a name="type-blocksize">blocksize()</a> = non_neg_integer()
  • <a name="type-mac">mac()</a> = binary()
- -Compute a SHA MAC message authentication code from key and data using -the specified hash function and blocksize. - - -###hmac224/2## - - -
hmac224(Key :: key(), Data :: data()) -> mac()
-
  • <a name="type-key">key()</a> = iolist() | binary()
  • <a name="type-data">data()</a> = iolist() | binary()
  • <a name="type-mac">mac()</a> = binary()
- -Compute a SHA-224 MAC message authentication code from key and data. - - -###hmac256/2## - - -
hmac256(Key :: key(), Data :: data()) -> mac()
-
  • <a name="type-key">key()</a> = iolist() | binary()
  • <a name="type-data">data()</a> = iolist() | binary()
  • <a name="type-mac">mac()</a> = binary()
- -Compute a SHA-256 MAC message authentication code from key and data. - - -###hmac384/2## - - -
hmac384(Key :: key(), Data :: data()) -> mac()
-
  • <a name="type-key">key()</a> = iolist() | binary()
  • <a name="type-data">data()</a> = iolist() | binary()
  • <a name="type-mac">mac()</a> = binary()
- -Compute a SHA-384 MAC message authentication code from key and data. - - -###hmac512/2## - - -
hmac512(Key :: key(), Data :: data()) -> mac()
-
  • <a name="type-key">key()</a> = iolist() | binary()
  • <a name="type-data">data()</a> = iolist() | binary()
  • <a name="type-mac">mac()</a> = binary()
- -Compute a SHA-512 MAC message authentication code from key and data. diff --git a/apps/erlsha2/edown.config b/apps/erlsha2/edown.config deleted file mode 100644 index 94f26be..0000000 --- a/apps/erlsha2/edown.config +++ /dev/null @@ -1,11 +0,0 @@ -%% -*- erlang -*- -{erlsha2, ".", [{doclet, edown_doclet}, - {pretty_printer, erl_pp}, - {src_path, ["src/"]}, - {subpackages, true}, - {stylesheet, ""}, - {image, ""}, - {app_default,"http://www.erlang.org/doc/man"}, - {top_level_readme, - {"./doc/README.md", - "http://github.com/vinoski/erlsha2"}}]}. diff --git a/apps/erlsha2/rebar.config b/apps/erlsha2/rebar.config deleted file mode 100644 index b832b3a..0000000 --- a/apps/erlsha2/rebar.config +++ /dev/null @@ -1,16 +0,0 @@ -%% -*- erlang -*- -{port_specs, [{"priv/erlsha2_nif.so", ["c_src/erlsha2_nif.c"]}]}. - -{port_env, [{"DRV_CFLAGS", "$DRV_CFLAGS -O3 -I."}, - {"(? [http://steve.vinoski.net/] -%%% @doc Implementations of SHA-224, SHA-256, SHA-384, SHA-512 in Erlang NIFs. -%%% @reference See -%%% the Secure Hash Standard and the Wikipedia SHA1 -%%% article. Find the code here. -%%% @since 03 Jan 2009 -%%% -%%% @copyright 2009-2011 Stephen B. Vinoski, All rights reserved. Open source, BSD License -%%% @version 2.0 -%%% - -%%% -%%% Copyright (c) 2009-2011 Stephen B. Vinoski -%%% All rights reserved. -%%% -%%% Redistribution and use in source and binary forms, with or without -%%% modification, are permitted provided that the following conditions -%%% are met: -%%% -%%% 1. Redistributions of source code must retain the above copyright -%%% notice, this list of conditions and the following disclaimer. -%%% 2. Redistributions in binary form must reproduce the above copyright -%%% notice, this list of conditions and the following disclaimer in the -%%% documentation and/or other materials provided with the distribution. -%%% 3. Neither the name of the copyright holder nor the names of contributors -%%% may be used to endorse or promote products derived from this software -%%% without specific prior written permission. -%%% -%%% THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND -%%% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%%% ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE -%%% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -%%% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -%%% OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -%%% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -%%% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -%%% SUCH DAMAGE. -%%% - --module(erlsha2). --export([sha224/1, sha256/1, sha384/1, sha512/1]). --export([sha224_init/0, sha224_update/2, sha224_final/1]). --export([sha256_init/0, sha256_update/2, sha256_final/1]). --export([sha384_init/0, sha384_update/2, sha384_final/1]). --export([sha512_init/0, sha512_update/2, sha512_final/1]). --version(2.0). --on_load(init/0). - --define(H224, [16#C1059ED8, 16#367CD507, 16#3070DD17, 16#F70E5939, - 16#FFC00B31, 16#68581511, 16#64F98FA7, 16#BEFA4FA4]). - --define(H256, [16#6A09E667, 16#BB67AE85, 16#3C6EF372, 16#A54FF53A, - 16#510E527F, 16#9B05688C, 16#1F83D9AB, 16#5BE0CD19]). - --define(H384, [16#CBBB9D5DC1059ED8, 16#629A292A367CD507, 16#9159015A3070DD17, - 16#152FECD8F70E5939, 16#67332667FFC00B31, 16#8EB44A8768581511, - 16#DB0C2E0D64F98FA7, 16#47B5481DBEFA4FA4]). - --define(H512, [16#6A09E667F3BCC908, 16#BB67AE8584CAA73B, 16#3C6EF372FE94F82B, - 16#A54FF53A5F1D36F1, 16#510E527FADE682D1, 16#9B05688C2B3E6C1F, - 16#1F83D9ABFB41BD6B, 16#5BE0CD19137E2179]). - --define(K256, <<16#428A2F98:32/big-unsigned, 16#71374491:32/big-unsigned, - 16#B5C0FBCF:32/big-unsigned, 16#E9B5DBA5:32/big-unsigned, - 16#3956C25B:32/big-unsigned, 16#59F111F1:32/big-unsigned, - 16#923F82A4:32/big-unsigned, 16#AB1C5ED5:32/big-unsigned, - 16#D807AA98:32/big-unsigned, 16#12835B01:32/big-unsigned, - 16#243185BE:32/big-unsigned, 16#550C7DC3:32/big-unsigned, - 16#72BE5D74:32/big-unsigned, 16#80DEB1FE:32/big-unsigned, - 16#9BDC06A7:32/big-unsigned, 16#C19BF174:32/big-unsigned, - 16#E49B69C1:32/big-unsigned, 16#EFBE4786:32/big-unsigned, - 16#0FC19DC6:32/big-unsigned, 16#240CA1CC:32/big-unsigned, - 16#2DE92C6F:32/big-unsigned, 16#4A7484AA:32/big-unsigned, - 16#5CB0A9DC:32/big-unsigned, 16#76F988DA:32/big-unsigned, - 16#983E5152:32/big-unsigned, 16#A831C66D:32/big-unsigned, - 16#B00327C8:32/big-unsigned, 16#BF597FC7:32/big-unsigned, - 16#C6E00BF3:32/big-unsigned, 16#D5A79147:32/big-unsigned, - 16#06CA6351:32/big-unsigned, 16#14292967:32/big-unsigned, - 16#27B70A85:32/big-unsigned, 16#2E1B2138:32/big-unsigned, - 16#4D2C6DFC:32/big-unsigned, 16#53380D13:32/big-unsigned, - 16#650A7354:32/big-unsigned, 16#766A0ABB:32/big-unsigned, - 16#81C2C92E:32/big-unsigned, 16#92722C85:32/big-unsigned, - 16#A2BFE8A1:32/big-unsigned, 16#A81A664B:32/big-unsigned, - 16#C24B8B70:32/big-unsigned, 16#C76C51A3:32/big-unsigned, - 16#D192E819:32/big-unsigned, 16#D6990624:32/big-unsigned, - 16#F40E3585:32/big-unsigned, 16#106AA070:32/big-unsigned, - 16#19A4C116:32/big-unsigned, 16#1E376C08:32/big-unsigned, - 16#2748774C:32/big-unsigned, 16#34B0BCB5:32/big-unsigned, - 16#391C0CB3:32/big-unsigned, 16#4ED8AA4A:32/big-unsigned, - 16#5B9CCA4F:32/big-unsigned, 16#682E6FF3:32/big-unsigned, - 16#748F82EE:32/big-unsigned, 16#78A5636F:32/big-unsigned, - 16#84C87814:32/big-unsigned, 16#8CC70208:32/big-unsigned, - 16#90BEFFFA:32/big-unsigned, 16#A4506CEB:32/big-unsigned, - 16#BEF9A3F7:32/big-unsigned, 16#C67178F2:32/big-unsigned>>). - --define(K512, <<16#428A2F98D728AE22:64/big-unsigned, - 16#7137449123EF65CD:64/big-unsigned, - 16#B5C0FBCFEC4D3B2F:64/big-unsigned, - 16#E9B5DBA58189DBBC:64/big-unsigned, - 16#3956C25BF348B538:64/big-unsigned, - 16#59F111F1B605D019:64/big-unsigned, - 16#923F82A4AF194F9B:64/big-unsigned, - 16#AB1C5ED5DA6D8118:64/big-unsigned, - 16#D807AA98A3030242:64/big-unsigned, - 16#12835B0145706FBE:64/big-unsigned, - 16#243185BE4EE4B28C:64/big-unsigned, - 16#550C7DC3D5FFB4E2:64/big-unsigned, - 16#72BE5D74F27B896F:64/big-unsigned, - 16#80DEB1FE3B1696B1:64/big-unsigned, - 16#9BDC06A725C71235:64/big-unsigned, - 16#C19BF174CF692694:64/big-unsigned, - 16#E49B69C19EF14AD2:64/big-unsigned, - 16#EFBE4786384F25E3:64/big-unsigned, - 16#0FC19DC68B8CD5B5:64/big-unsigned, - 16#240CA1CC77AC9C65:64/big-unsigned, - 16#2DE92C6F592B0275:64/big-unsigned, - 16#4A7484AA6EA6E483:64/big-unsigned, - 16#5CB0A9DCBD41FBD4:64/big-unsigned, - 16#76F988DA831153B5:64/big-unsigned, - 16#983E5152EE66DFAB:64/big-unsigned, - 16#A831C66D2DB43210:64/big-unsigned, - 16#B00327C898FB213F:64/big-unsigned, - 16#BF597FC7BEEF0EE4:64/big-unsigned, - 16#C6E00BF33DA88FC2:64/big-unsigned, - 16#D5A79147930AA725:64/big-unsigned, - 16#06CA6351E003826F:64/big-unsigned, - 16#142929670A0E6E70:64/big-unsigned, - 16#27B70A8546D22FFC:64/big-unsigned, - 16#2E1B21385C26C926:64/big-unsigned, - 16#4D2C6DFC5AC42AED:64/big-unsigned, - 16#53380D139D95B3DF:64/big-unsigned, - 16#650A73548BAF63DE:64/big-unsigned, - 16#766A0ABB3C77B2A8:64/big-unsigned, - 16#81C2C92E47EDAEE6:64/big-unsigned, - 16#92722C851482353B:64/big-unsigned, - 16#A2BFE8A14CF10364:64/big-unsigned, - 16#A81A664BBC423001:64/big-unsigned, - 16#C24B8B70D0F89791:64/big-unsigned, - 16#C76C51A30654BE30:64/big-unsigned, - 16#D192E819D6EF5218:64/big-unsigned, - 16#D69906245565A910:64/big-unsigned, - 16#F40E35855771202A:64/big-unsigned, - 16#106AA07032BBD1B8:64/big-unsigned, - 16#19A4C116B8D2D0C8:64/big-unsigned, - 16#1E376C085141AB53:64/big-unsigned, - 16#2748774CDF8EEB99:64/big-unsigned, - 16#34B0BCB5E19B48A8:64/big-unsigned, - 16#391C0CB3C5C95A63:64/big-unsigned, - 16#4ED8AA4AE3418ACB:64/big-unsigned, - 16#5B9CCA4F7763E373:64/big-unsigned, - 16#682E6FF3D6B2B8A3:64/big-unsigned, - 16#748F82EE5DEFB2FC:64/big-unsigned, - 16#78A5636F43172F60:64/big-unsigned, - 16#84C87814A1F0AB72:64/big-unsigned, - 16#8CC702081A6439EC:64/big-unsigned, - 16#90BEFFFA23631E28:64/big-unsigned, - 16#A4506CEBDE82BDE9:64/big-unsigned, - 16#BEF9A3F7B2C67915:64/big-unsigned, - 16#C67178F2E372532B:64/big-unsigned, - 16#CA273ECEEA26619C:64/big-unsigned, - 16#D186B8C721C0C207:64/big-unsigned, - 16#EADA7DD6CDE0EB1E:64/big-unsigned, - 16#F57D4F7FEE6ED178:64/big-unsigned, - 16#06F067AA72176FBA:64/big-unsigned, - 16#0A637DC5A2C898A6:64/big-unsigned, - 16#113F9804BEF90DAE:64/big-unsigned, - 16#1B710B35131C471B:64/big-unsigned, - 16#28DB77F523047D84:64/big-unsigned, - 16#32CAAB7B40C72493:64/big-unsigned, - 16#3C9EBE0A15C9BEBC:64/big-unsigned, - 16#431D67C49C100D4C:64/big-unsigned, - 16#4CC5D4BECB3E42B6:64/big-unsigned, - 16#597F299CFC657E2A:64/big-unsigned, - 16#5FCB6FAB3AD6FAEC:64/big-unsigned, - 16#6C44198C4A475817:64/big-unsigned>>). - --define(ADD32(X, Y), (X + Y) band 16#FFFFFFFF). --define(ADD64(X, Y), (X + Y) band 16#FFFFFFFFFFFFFFFF). - -%% @spec init() -> ok -%% @doc Initialize sha2 NIF. -%% If the platform supports NIFs, load the NIF library. If the library -%% isn't available, still return ok so we fall back to the Erlang -%% implementations below. -%% -init() -> - SoName = filename:join(case code:priv_dir(?MODULE) of - {error, bad_name} -> - %% this is here for testing purposes - filename:join( - [filename:dirname( - code:which(?MODULE)),"..","priv"]); - Dir -> - Dir - end, atom_to_list(?MODULE) ++ "_nif"), - erlang:load_nif(SoName, 0), - ok. - -%% @spec sha224(message()) -> digest() -%% where -%% message() = binary() | iolist() -%% digest() = binary() -%% @doc Returns a SHA-224 hexadecimal digest. -%% -sha224(M) when is_binary(M) -> - digest_bin(M, ?H224, 64, fun sha256_pad/1, fun sha224/2, 32); -sha224(Iolist) -> - Bin = list_to_binary(Iolist), - digest_bin(Bin, ?H224, 64, fun sha256_pad/1, fun sha224/2, 32). - -%% @spec sha224_init() -> context() -%% where -%% context() = binary() -%% @doc Creates a SHA-224 context to be in subsequent calls to -%% sha224_update/2. -%% -sha224_init() -> - <<>>. - -%% @spec sha224_update(context(), message()) -> newcontext() -%% where -%% message() = binary() | iolist() -%% context() = binary() -%% newcontext() = binary() -%% @doc Updates a SHA-224 context with message data and returns a new -%% context. -%% -sha224_update(Context, M) -> - list_to_binary([Context, M]). - -%% @spec sha224_final(context()) -> digest() -%% where -%% context() = binary() -%% digest() = binary() -%% @doc Finishes the update of a SHA-224 Context and returns the computed -%% message digest. -%% -sha224_final(Context) -> - sha224(Context). - -%% @spec sha256(message()) -> digest() -%% where -%% message() = binary() | iolist() -%% digest() = binary() -%% @doc Returns a SHA-256 hexadecimal digest. -%% -sha256(M) when is_binary(M) -> - digest_bin(M, ?H256, 64, fun sha256_pad/1, fun sha256/2, 32); -sha256(Iolist) -> - Bin = list_to_binary(Iolist), - digest_bin(Bin, ?H256, 64, fun sha256_pad/1, fun sha256/2, 32). - -%% @spec sha256_init() -> context() -%% where -%% context() = binary() -%% @doc Creates a SHA-256 context to be in subsequent calls to -%% sha256_update/2. -%% -sha256_init() -> - <<>>. - -%% @spec sha256_update(context(), message()) -> newcontext() -%% where -%% message() = binary() | iolist() -%% context() = binary() -%%% newcontext() = binary() -%% @doc Updates a SHA-256 context with message data and returns a new -%% context. -%% -sha256_update(Context, M) -> - list_to_binary([Context, M]). - -%% @spec sha256_final(context()) -> digest() -%% where -%% context() = binary() -%% digest() = binary() -%% @doc Finishes the update of a SHA-256 Context and returns the computed -%% message digest. -%% -sha256_final(Context) -> - sha256(Context). - -%% @spec sha384(message()) -> digest() -%% where -%% message() = binary() | iolist() -%% digest() = binary() -%% @doc Returns a SHA-384 hexadecimal digest. -%% If the argument is a binary, the result is a binary, otherwise the -%% -sha384(M) when is_binary(M) -> - digest_bin(M, ?H384, 128, fun sha512_pad/1, fun sha384/2, 64); -sha384(Iolist) -> - Bin = list_to_binary(Iolist), - digest_bin(Bin, ?H384, 128, fun sha512_pad/1, fun sha384/2, 64). - -%% @spec sha384_init() -> context() -%% where -%% context() = binary() -%% @doc Creates a SHA-384 context to be in subsequent calls to -%% sha384_update/2. -%% -sha384_init() -> - <<>>. - -%% @spec sha384_update(context(), message()) -> newcontext() -%% where -%% message() = binary() | iolist() -%% context() = binary() -%% newcontext() = binary() -%% @doc Updates a SHA-384 context with message data and returns a new -%% context. -%% -sha384_update(Context, M) -> - list_to_binary([Context, M]). - -%% @spec sha384_final(context()) -> digest() -%% where -%% context() = binary() -%% digest() = binary() -%% @doc Finishes the update of a SHA-384 Context and returns the computed -%% message digest. -%% -sha384_final(Context) -> - sha384(Context). - -%% @spec sha512(message()) -> digest() -%% where -%% message() = binary() | iolist() -%% digest() = binary() -%% @doc Returns a SHA-512 hexadecimal digest. -%% -sha512(M) when is_binary(M) -> - digest_bin(M, ?H512, 128, fun sha512_pad/1, fun sha512/2, 64); -sha512(Iolist) -> - Bin = list_to_binary(Iolist), - digest_bin(Bin, ?H512, 128, fun sha512_pad/1, fun sha512/2, 64). - -%% @spec sha512_init() -> context() -%% where -%% context() = binary() -%% @doc Creates a SHA-512 context to be in subsequent calls to -%% sha512_update/2. -%% -sha512_init() -> - <<>>. - -%% @spec sha512_update(context(), message()) -> newcontext() -%% where -%% message() = binary() | iolist() -%% context() = binary() -%% newcontext() = binary() -%% @doc Updates a SHA-512 context with message data and returns a new -%% context. -%% -sha512_update(Context, M) -> - list_to_binary([Context, M]). - -%% @spec sha512_final(context()) -> digest() -%% where -%% context() = binary() -%% digest() = binary() -%% @doc Finishes the update of a SHA-512 Context and returns the computed -%% message digest. -%% -sha512_final(Context) -> - sha512(Context). - - -digest_bin(M, Hashes, BitLen, Pad, Sha, WordSize) -> - list_to_binary([<> || - V <- Sha(split_binary(Pad(M), BitLen), Hashes)]). - -rotate32(V, Count) -> - Rest = 32 - Count, - <> = <>, - <> = <>, - New. - -rotate64(V, Count) -> - Rest = 64 - Count, - <> = <>, - <> = <>, - New. - -sha_pad(M, Base) -> - Len = size(M), - LenBits = Len*8, - PadBits = (Len + 1 + Base div 8) rem Base, - Pad = case PadBits of - 0 -> 0; - _ -> (Base - PadBits) * 8 - end, - list_to_binary([M, <<16#80:8, 0:Pad, LenBits:Base/big-unsigned>>]). - -sha256_pad(M) -> - sha_pad(M, 64). - -sha512_pad(M) -> - sha_pad(M, 128). - -sha256_extend(W, 64) -> - W; -sha256_extend(W, Count) -> - Off1 = (Count - 15) * 4, - Off2 = (Count - 2) * 4 - Off1 - 4, - <<_:Off1/binary, Word1:32/big-unsigned, - _:Off2/binary, Word2:32/big-unsigned, _/binary>> = <>, - S0 = rotate32(Word1, 7) bxor rotate32(Word1, 18) bxor (Word1 bsr 3), - S1 = rotate32(Word2, 17) bxor rotate32(Word2, 19) bxor (Word2 bsr 10), - Off3 = (Count - 16) * 4, - Off4 = (Count - 7) * 4 - Off3 - 4, - <<_:Off3/binary, W16:32/big-unsigned, - _:Off4/binary, W7:32/big-unsigned, _/binary>> = <>, - Next = (W16 + S0 + W7 + S1) band 16#FFFFFFFF, - sha256_extend(<>, Count+1). - -sha512_extend(W, 80) -> - W; -sha512_extend(W, Count) -> - Off1 = (Count - 15) * 8, - Off2 = (Count - 2) * 8 - Off1 - 8, - <<_:Off1/binary, Word1:64/big-unsigned, - _:Off2/binary, Word2:64/big-unsigned, _/binary>> = <>, - S0 = rotate64(Word1, 1) bxor rotate64(Word1, 8) bxor (Word1 bsr 7), - S1 = rotate64(Word2, 19) bxor rotate64(Word2, 61) bxor (Word2 bsr 6), - Off3 = (Count - 16) * 8, - Off4 = (Count - 7) * 8 - Off3 - 8, - <<_:Off3/binary, W16:64/big-unsigned, - _:Off4/binary, W7:64/big-unsigned, _/binary>> = <>, - Next = (W16 + S0 + W7 + S1) band 16#FFFFFFFFFFFFFFFF, - sha512_extend(<>, Count+1). - -sha256_loop(_W, Hashes, Next, 64) -> - lists:map(fun({X, Y}) -> ?ADD32(X, Y) end, lists:zip(Hashes, Next)); -sha256_loop(W, Hashes, [A, B, C, D, E, F, G, H], Count) -> - S0 = rotate32(A, 2) bxor rotate32(A, 13) bxor rotate32(A, 22), - Maj = (A band B) bxor (A band C) bxor (B band C), - T2 = ?ADD32(S0, Maj), - S1 = rotate32(E, 6) bxor rotate32(E, 11) bxor rotate32(E, 25), - Ch = (E band F) bxor (((bnot E) + 1 + 16#FFFFFFFF) band G), - Offset = Count * 4, - <<_:Offset/binary, K:32/big-unsigned, _/binary>> = ?K256, - <<_:Offset/binary, Wval:32/big-unsigned, _/binary>> = <>, - T1 = (H + S1 + Ch + K + Wval) band 16#FFFFFFFF, - sha256_loop(W, Hashes, [?ADD32(T1, T2), A, B, C, ?ADD32(D, T1), E, F, G], - Count+1). - -sha512_loop(_W, Hashes, Next, 80) -> - lists:map(fun({X, Y}) -> ?ADD64(X, Y) end, lists:zip(Hashes, Next)); -sha512_loop(W, Hashes, [A, B, C, D, E, F, G, H], Count) -> - S0 = rotate64(A, 28) bxor rotate64(A, 34) bxor rotate64(A, 39), - Maj = (A band B) bxor (A band C) bxor (B band C), - T2 = ?ADD64(S0, Maj), - S1 = rotate64(E, 14) bxor rotate64(E, 18) bxor rotate64(E, 41), - Ch = (E band F) bxor (((bnot E) + 1 + 16#FFFFFFFFFFFFFFFF) band G), - Offset = Count * 8, - <<_:Offset/binary, K:64/big-unsigned, _/binary>> = ?K512, - <<_:Offset/binary, Wval:64/big-unsigned, _/binary>> = <>, - T1 = (H + S1 + Ch + K + Wval) band 16#FFFFFFFFFFFFFFFF, - sha512_loop(W, Hashes, [?ADD64(T1, T2), A, B, C, ?ADD64(D, T1), E, F, G], - Count+1). - -sha256(M, Hashes) when is_binary(M) -> - Words64 = sha256_extend(M, 16), - sha256_loop(Words64, Hashes, Hashes, 0); -sha256({M, <<>>}, Hashes) -> - sha256(M, Hashes); -sha256({M, T}, Hashes) -> - sha256(split_binary(T, 64), sha256(M, Hashes)). - -sha224({M, <<>>}, Hashes) -> - [H0, H1, H2, H3, H4, H5, H6, _H7] = sha256(M, Hashes), - [H0, H1, H2, H3, H4, H5, H6]; -sha224({M, T}, Hashes) -> - sha224(split_binary(T, 64), sha256(M, Hashes)). - -sha512(M, Hashes) when is_binary(M) -> - Words128 = sha512_extend(M, 16), - sha512_loop(Words128, Hashes, Hashes, 0); -sha512({M, <<>>}, Hashes) -> - sha512(M, Hashes); -sha512({M, T}, Hashes) -> - sha512(split_binary(T, 128), sha512(M, Hashes)). - -sha384({M, <<>>}, Hashes) -> - [H0, H1, H2, H3, H4, H5 | _] = sha512(M, Hashes), - [H0, H1, H2, H3, H4, H5]; -sha384({M, T}, Hashes) -> - sha384(split_binary(T, 128), sha512(M, Hashes)). diff --git a/apps/erlsha2/src/hmac.erl b/apps/erlsha2/src/hmac.erl deleted file mode 100644 index 146232d..0000000 --- a/apps/erlsha2/src/hmac.erl +++ /dev/null @@ -1,110 +0,0 @@ -%% @author Jared Flatow, Steve Vinoski -%% @doc HMAC wrappers for erlsha2 -%% @reference -%% Based on the -%% -%% mailing list response -%% -%% by Steve Davis. - --module(hmac). --export([hexlify/1, - hmac/2, - hmac/4, - hmac224/2, - hmac256/2, - hmac384/2, - hmac512/2]). - --define(SHA_224_BLOCKSIZE, 64). --define(SHA_256_BLOCKSIZE, 64). --define(SHA_384_BLOCKSIZE, 128). --define(SHA_512_BLOCKSIZE, 128). - -%% @spec hexlify(binary()) -> list() -%% @doc Convert binary to equivalent hexadecimal string. -%% -hexlify(Binary) when is_binary(Binary) -> - lists:flatten([io_lib:format("~2.16.0B", [B]) || - B <- binary_to_list(Binary)]). - -%% @spec hmac224(key(), data()) -> mac() -%% where -%% key() = iolist() | binary() -%% data() = iolist() | binary() -%% mac() = binary() -%% @doc Compute a SHA-224 MAC message authentication code from key and data. -%% -hmac224(Key, Data) -> - hmac(Key, Data, fun erlsha2:sha224/1, ?SHA_224_BLOCKSIZE). - -%% @spec hmac256(key(), data()) -> mac() -%% where -%% key() = iolist() | binary() -%% data() = iolist() | binary() -%% mac() = binary() -%% @doc Compute a SHA-256 MAC message authentication code from key and data. -%% -hmac256(Key, Data) -> - hmac(Key, Data, fun erlsha2:sha256/1, ?SHA_256_BLOCKSIZE). - -%% @spec hmac384(key(), data()) -> mac() -%% where -%% key() = iolist() | binary() -%% data() = iolist() | binary() -%% mac() = binary() -%% @doc Compute a SHA-384 MAC message authentication code from key and data. -%% -hmac384(Key, Data) -> - hmac(Key, Data, fun erlsha2:sha384/1, ?SHA_384_BLOCKSIZE). - -%% @spec hmac512(key(), data()) -> mac() -%% where -%% key() = iolist() | binary() -%% data() = iolist() | binary() -%% mac() = binary() -%% @doc Compute a SHA-512 MAC message authentication code from key and data. -%% -hmac512(Key, Data) -> - hmac(Key, Data, fun erlsha2:sha512/1, ?SHA_512_BLOCKSIZE). - -%% @spec hmac(key(), data()) -> mac() -%% where -%% key() = iolist() | binary() -%% data() = iolist() | binary() -%% mac() = binary() -%% @doc Compute a SHA MAC message authentication code from key and data. -%% -hmac(Key, Data) -> - crypto:sha_mac(Key, Data). - -%% @spec hmac(key(), data(), hash(), blocksize()) -> mac() -%% where -%% key() = iolist() | binary() -%% data() = iolist() | binary() -%% hash() = fun((binary()) -> binary()) -%% blocksize() = non_neg_integer() -%% mac() = binary() -%% @doc Compute a SHA MAC message authentication code from key and data using -%% the specified hash function and blocksize. -%% -hmac(Key, Data, Hash, Blocksize) when is_list(Key) -> - hmac(iolist_to_binary(Key), Data, Hash, Blocksize); -hmac(Key, Data, Hash, Blocksize) when is_list(Data) -> - hmac(Key, iolist_to_binary(Data), Hash, Blocksize); -hmac(Key, Data, Hash, Blocksize) when is_binary(Key), is_binary(Data) -> - HashKey = - case Blocksize - byte_size(Key) of - X when X < 0 -> - KeyDigest = Hash(Key), - Pad = Blocksize - byte_size(KeyDigest), - <>; - X when X > 0 -> - <>; - X when X =:= 0 -> - Key - end, - IPad = binary:copy(<<16#36>>, Blocksize), - OPad = binary:copy(<<16#5c>>, Blocksize), - HVal = Hash(<<(crypto:exor(HashKey, IPad))/binary, Data/binary>>), - Hash(<<(crypto:exor(HashKey, OPad))/binary, HVal/binary>>). diff --git a/apps/erlsha2/test/erlsha2_test.erl b/apps/erlsha2/test/erlsha2_test.erl deleted file mode 100644 index 148ab38..0000000 --- a/apps/erlsha2/test/erlsha2_test.erl +++ /dev/null @@ -1,471 +0,0 @@ -%%% -%%% These tests come from -%%% . These tests read the -%%% test data from files in the testvector directory and compare against -%%% the expected results. The test vectors and expected results are subject -%%% to the license in testvectors/LICENSE. -%%% --module(erlsha2_test). --compile([export_all]). - --include_lib("eunit/include/eunit.hrl"). - -all_test_() -> - {setup, fun read_test_vectors/0, - {with, [fun sha224_test/1, - fun sha224_update_test/1, - fun sha256_test/1, - fun sha256_update_test/1, - fun sha384_test/1, - fun sha384_update_test/1, - fun sha512_test/1, - fun sha512_update_test/1]}}. - -badarg_224_test() -> - try - erlsha2:sha224(1234) - catch - error:badarg -> - ok; - Type:Error -> - ?assertMatch(error, Type), - ?assertMatch(badarg, Error) - end. - -badarg_224_update_test() -> - Ctx1 = erlsha2:sha224_init(), - try - NCtx1 = erlsha2:sha224_update(Ctx1, not_an_iolist), - erlsha2:sha224_final(NCtx1) - catch - error:badarg -> - ok; - Type1:Error1 -> - ?assertMatch(error, Type1), - ?assertMatch(badarg, Error1) - end, - _Ctx2 = erlsha2:sha224_init(), - try - NCtx2 = erlsha2:sha224_update(not_a_context, <<"a">>), - erlsha2:sha224_final(NCtx2) - catch - error:badarg -> - ok; - Type2:Error2 -> - ?assertMatch(error, Type2), - ?assertMatch(badarg, Error2) - end. - -badarg_256_test() -> - try - erlsha2:sha256(1234) - catch - error:badarg -> - ok; - Type:Error -> - ?assertMatch(error, Type), - ?assertMatch(badarg, Error) - end. - -badarg_256_update_test() -> - Ctx1 = erlsha2:sha256_init(), - try - NCtx1 = erlsha2:sha256_update(Ctx1, not_an_iolist), - erlsha2:sha256_final(NCtx1) - catch - error:badarg -> - ok; - Type1:Error1 -> - ?assertMatch(error, Type1), - ?assertMatch(badarg, Error1) - end, - _Ctx2 = erlsha2:sha256_init(), - try - NCtx2 = erlsha2:sha256_update(not_a_context, <<"a">>), - erlsha2:sha256_final(NCtx2) - catch - error:badarg -> - ok; - Type2:Error2 -> - ?assertMatch(error, Type2), - ?assertMatch(badarg, Error2) - end. - -badarg_384_test() -> - try - erlsha2:sha384(1234) - catch - error:badarg -> - ok; - Type:Error -> - ?assertMatch(error, Type), - ?assertMatch(badarg, Error) - end. - -badarg_384_update_test() -> - Ctx1 = erlsha2:sha384_init(), - try - NCtx1 = erlsha2:sha384_update(Ctx1, not_an_iolist), - erlsha2:sha384_final(NCtx1) - catch - error:badarg -> - ok; - Type1:Error1 -> - ?assertMatch(error, Type1), - ?assertMatch(badarg, Error1) - end, - _Ctx2 = erlsha2:sha384_init(), - try - NCtx2 = erlsha2:sha384_update(not_a_context, <<"a">>), - erlsha2:sha384_final(NCtx2) - catch - error:badarg -> - ok; - Type2:Error2 -> - ?assertMatch(error, Type2), - ?assertMatch(badarg, Error2) - end. - -badarg_512_test() -> - try - erlsha2:sha512(1234) - catch - error:badarg -> - ok; - Type:Error -> - ?assertMatch(error, Type), - ?assertMatch(badarg, Error) - end. - -badarg_512_update_test() -> - Ctx1 = erlsha2:sha512_init(), - try - NCtx1 = erlsha2:sha512_update(Ctx1, not_an_iolist), - erlsha2:sha512_final(NCtx1) - catch - error:badarg -> - ok; - Type1:Error1 -> - ?assertMatch(error, Type1), - ?assertMatch(badarg, Error1) - end, - _Ctx2 = erlsha2:sha512_init(), - try - NCtx2 = erlsha2:sha512_update(not_a_context, <<"a">>), - erlsha2:sha512_final(NCtx2) - catch - error:badarg -> - ok; - Type2:Error2 -> - ?assertMatch(error, Type2), - ?assertMatch(badarg, Error2) - end. - -sha224_test(Vectors) -> - Expected224 = sha224_expected(), - lists:foreach(fun({Vector, Expected}) -> - Actual = erlsha2:sha224(Vector), - ?assertMatch(Expected, Actual) - end, lists:zip(Vectors, Expected224)), - ok. - -sha224_update_test(Vectors) -> - Expected224 = sha224_expected(), - ExpectedActual = lists:zip(Vectors, Expected224), - lists:foreach(fun({Vector, Expected}) -> - Ctx = erlsha2:sha224_init(), - NCtx = case size(Vector) of - 0 -> - erlsha2:sha224_update( - Ctx, Vector); - Sz -> - Pos = Sz div 2, - {V1,V2} = split_binary(Vector, Pos), - NCtx0 = erlsha2:sha224_update( - Ctx, V1), - erlsha2:sha224_update( - NCtx0, V2) - end, - Actual = erlsha2:sha224_final(NCtx), - ?assertMatch(Expected, Actual) - end, ExpectedActual), - lists:foreach(fun({Vector, Expected}) -> - case size(Vector) of - 0 -> - ok; - _ -> - Ctx = erlsha2:sha224_init(), - Vals = binary_to_list(Vector), - NCtx = lists:foldl( - fun(V, LastCtx) -> - erlsha2:sha224_update( - LastCtx, <>) - end, Ctx, Vals), - Actual = erlsha2:sha224_final(NCtx), - ?assertMatch(Expected, Actual) - end - end, ExpectedActual), - ok. - -sha256_test(Vectors) -> - Expected256 = sha256_expected(), - lists:foreach(fun({Vector, Expected}) -> - Actual = erlsha2:sha256(Vector), - ?assertMatch(Expected, Actual) - end, lists:zip(Vectors, Expected256)), - ok. - -sha256_update_test(Vectors) -> - Expected256 = sha256_expected(), - ExpectedActual = lists:zip(Vectors, Expected256), - lists:foreach(fun({Vector, Expected}) -> - Ctx = erlsha2:sha256_init(), - NCtx = case size(Vector) of - 0 -> - erlsha2:sha256_update( - Ctx, Vector); - Sz -> - Pos = Sz div 2, - {V1,V2} = split_binary(Vector, Pos), - NCtx0 = erlsha2:sha256_update( - Ctx, V1), - erlsha2:sha256_update( - NCtx0, V2) - end, - Actual = erlsha2:sha256_final(NCtx), - ?assertMatch(Expected, Actual) - end, ExpectedActual), - lists:foreach(fun({Vector, Expected}) -> - case size(Vector) of - 0 -> - ok; - _ -> - Ctx = erlsha2:sha256_init(), - Vals = binary_to_list(Vector), - NCtx = lists:foldl( - fun(V, LastCtx) -> - erlsha2:sha256_update( - LastCtx, <>) - end, Ctx, Vals), - Actual = erlsha2:sha256_final(NCtx), - ?assertMatch(Expected, Actual) - end - end, ExpectedActual), - ok. - -sha384_test(Vectors) -> - Expected384 = sha384_expected(), - lists:foreach(fun({Vector, Expected}) -> - Actual = erlsha2:sha384(Vector), - ?assertMatch(Expected, Actual) - end, lists:zip(Vectors, Expected384)), - ok. - -sha384_update_test(Vectors) -> - Expected384 = sha384_expected(), - ExpectedActual = lists:zip(Vectors, Expected384), - lists:foreach(fun({Vector, Expected}) -> - Ctx = erlsha2:sha384_init(), - NCtx = case size(Vector) of - 0 -> - erlsha2:sha384_update( - Ctx, Vector); - Sz -> - Pos = Sz div 2, - {V1,V2} = split_binary(Vector, Pos), - NCtx0 = erlsha2:sha384_update( - Ctx, V1), - erlsha2:sha384_update( - NCtx0, V2) - end, - Actual = erlsha2:sha384_final(NCtx), - ?assertMatch(Expected, Actual) - end, ExpectedActual), - lists:foreach(fun({Vector, Expected}) -> - case size(Vector) of - 0 -> - ok; - _ -> - Ctx = erlsha2:sha384_init(), - Vals = binary_to_list(Vector), - NCtx = lists:foldl( - fun(V, LastCtx) -> - erlsha2:sha384_update( - LastCtx, <>) - end, Ctx, Vals), - Actual = erlsha2:sha384_final(NCtx), - ?assertMatch(Expected, Actual) - end - end, ExpectedActual), - ok. - -sha512_test(Vectors) -> - Expected512 = sha512_expected(), - lists:foreach(fun({Vector, Expected}) -> - Actual = erlsha2:sha512(Vector), - ?assertMatch(Expected, Actual) - end, lists:zip(Vectors, Expected512)), - ok. - -sha512_update_test(Vectors) -> - Expected512 = sha512_expected(), - ExpectedActual = lists:zip(Vectors, Expected512), - lists:foreach(fun({Vector, Expected}) -> - Ctx = erlsha2:sha512_init(), - NCtx = case size(Vector) of - 0 -> - erlsha2:sha512_update( - Ctx, Vector); - Sz -> - Pos = Sz div 2, - {V1,V2} = split_binary(Vector, Pos), - NCtx0 = erlsha2:sha512_update( - Ctx, V1), - erlsha2:sha512_update( - NCtx0, V2) - end, - Actual = erlsha2:sha512_final(NCtx), - ?assertMatch(Expected, Actual) - end, ExpectedActual), - lists:foreach(fun({Vector, Expected}) -> - case size(Vector) of - 0 -> - ok; - _ -> - Ctx = erlsha2:sha512_init(), - Vals = binary_to_list(Vector), - NCtx = lists:foldl( - fun(V, LastCtx) -> - erlsha2:sha512_update( - LastCtx, <>) - end, Ctx, Vals), - Actual = erlsha2:sha512_final(NCtx), - ?assertMatch(Expected, Actual) - end - end, ExpectedActual), - ok. - -read_test_vectors() -> - read_test_vectors([], 1). -read_test_vectors(Vectors, 19) -> - lists:reverse(Vectors); -read_test_vectors(Vectors, Num) -> - VecFile = io_lib:format("../test/testvectors/vector~3.10.0b.dat", [Num]), - {ok, Vector} = file:read_file(lists:flatten(VecFile)), - read_test_vectors([Vector|Vectors], Num+1). - -sha224_expected() -> - [<<16#23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7:224/big-unsigned>>, - <<16#75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525:224/big-unsigned>>, - <<16#c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3:224/big-unsigned>>, - <<16#62a41ab0961bcdd22db70b896db3955c1d04096af6de47f5aaad1226:224/big-unsigned>>, - <<16#d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f:224/big-unsigned>>, - <<16#d92622d56f83d869a884f6cc0763e90c4520a21e1cc429841e4584d2:224/big-unsigned>>, - <<16#0873433e1c8749dad0e34f92aff11c4b2ca310356283817747aa6940:224/big-unsigned>>, - <<16#5a69ccca0b5e7f84efda7c026d010fa46569c03f97b4440eba32b941:224/big-unsigned>>, - <<16#49e54148d21d457f2ffe28532543d91da98724c9883e67682301dec4:224/big-unsigned>>, - <<16#6417acfccd1d78cc14f1dd2de4ffcafe9cff0f92f0e28139866c2e2d:224/big-unsigned>>, - <<16#d4126ce69e15fc0c06cb1bf763f112b139ffd81189e3899e4e275560:224/big-unsigned>>, - <<16#0ace93ff0cfa76006af9db847f4ff2e702c2518dc946948807be0a47:224/big-unsigned>>, - <<16#91e452cfc8f22f9c69e637ec9dcf80d5798607a52234686fcf8880ad:224/big-unsigned>>, - <<16#bdaac28698611eba163f232785d8f4caffe29ac2fd8133651baf8212:224/big-unsigned>>, - <<16#4f41e1e6839ed85883ee0f259ac9025d19ecccbfc4d9d72f075ba5f2:224/big-unsigned>>, - <<16#4215dc642269cfd6d9b4b6da78fd01a9094bc89f4780905714b0a896:224/big-unsigned>>, - <<16#a1b0964a6d8188eb2980e126fefc70eb79d0745a91cc2f629af34ece:224/big-unsigned>>, - <<16#cc9286e04c4a39a6bb92a42f2ffabce02156090b6882b0ca22026294:224/big-unsigned>>]. - -sha256_expected() -> - [<<16#ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad:256/big-unsigned>>, - <<16#248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1:256/big-unsigned>>, - <<16#cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1:256/big-unsigned>>, - <<16#4d25fccf8752ce470a58cd21d90939b7eb25f3fa418dd2da4c38288ea561e600:256/big-unsigned>>, - <<16#e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855:256/big-unsigned>>, - <<16#ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8:256/big-unsigned>>, - <<16#f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342:256/big-unsigned>>, - <<16#0ab803344830f92089494fb635ad00d76164ad6e57012b237722df0d7ad26896:256/big-unsigned>>, - <<16#e4326d0459653d7d3514674d713e74dc3df11ed4d30b4013fd327fdb9e394c26:256/big-unsigned>>, - <<16#a7f001d996dd25af402d03b5f61aef950565949c1a6ad5004efa730328d2dbf3:256/big-unsigned>>, - <<16#6dcd63a07b0922cc3a9b3315b158478681cc32543b0a4180abe58a73c5e14cc2:256/big-unsigned>>, - <<16#af6ebfde7d93d5badb6cde6287ecc2061c1cafc5b1c1217cd984fbcdb9c61aaa:256/big-unsigned>>, - <<16#8ff59c6d33c5a991088bc44dd38f037eb5ad5630c91071a221ad6943e872ac29:256/big-unsigned>>, - <<16#1818e87564e0c50974ecaabbb2eb4ca2f6cc820234b51861e2590be625f1f703:256/big-unsigned>>, - <<16#5e3dfe0cc98fd1c2de2a9d2fd893446da43d290f2512200c515416313cdf3192:256/big-unsigned>>, - <<16#80fced5a97176a5009207cd119551b42c5b51ceb445230d02ecc2663bbfb483a:256/big-unsigned>>, - <<16#88ee6ada861083094f4c64b373657e178d88ef0a4674fce6e4e1d84e3b176afb:256/big-unsigned>>, - <<16#5a2e925a7f8399fa63a20a1524ae83a7e3c48452f9af4df493c8c51311b04520:256/big-unsigned>>]. - -sha384_expected() -> - [<<16#cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed:256/big-unsigned, - 16#8086072ba1e7cc2358baeca134c825a7:128/big-unsigned>>, - <<16#3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6:256/big-unsigned, - 16#b0455a8520bc4e6f5fe95b1fe3c8452b:128/big-unsigned>>, - <<16#09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712:256/big-unsigned, - 16#fcc7c71a557e2db966c3e9fa91746039:128/big-unsigned>>, - <<16#69cc75b95280bdd9e154e743903e37b1205aa382e92e051b1f48a6db9d0203f8:256/big-unsigned, - 16#a17c1762d46887037275606932d3381e:128/big-unsigned>>, - <<16#38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da:256/big-unsigned, - 16#274edebfe76f65fbd51ad2f14898b95b:128/big-unsigned>>, - <<16#e28e35e25a1874908bf0958bb088b69f3d742a753c86993e9f4b1c4c21988f95:256/big-unsigned, - 16#8bd1fe0315b195aca7b061213ac2a9bd:128/big-unsigned>>, - <<16#37b49ef3d08de53e9bd018b0630067bd43d09c427d06b05812f48531bce7d2a6:256/big-unsigned, - 16#98ee2d1ed1ffed46fd4c3b9f38a8a557:128/big-unsigned>>, - <<16#e3e3602f4d90c935321d788f722071a8809f4f09366f2825cd85da97ccd2955e:256/big-unsigned, - 16#b6b8245974402aa64789ed45293e94ba:128/big-unsigned>>, - <<16#1ca650f38480fa9dfb5729636bec4a935ebc1cd4c0055ee50cad2aa627e06687:256/big-unsigned, - 16#1044fd8e6fdb80edf10b85df15ba7aab:128/big-unsigned>>, - <<16#b8261ddcd7df7b3969a516b72550de6fbf0e394a4a7bb2bbc60ec603c2ceff64:256/big-unsigned, - 16#3c5bf62bc6dcbfa5beb54b62d750b969:128/big-unsigned>>, - <<16#548e4e9a1ff57f469ed47b023bf5279dfb4d4ca08c65051e3a5c41fab84479a2:256/big-unsigned, - 16#05496276906008b4b3c5b0970b2f5446:128/big-unsigned>>, - <<16#c6fec3a3278dd6b5afc8c0971d32d38faf5802f1a21527c32563b32a1ac34065:256/big-unsigned, - 16#6b433b44fe2648aa2232206f4301193a:128/big-unsigned>>, - <<16#92dca5655229b3c34796a227ff1809e273499adc2830149481224e0f54ff4483:256/big-unsigned, - 16#bd49834d4865e508ef53d4cd22b703ce:128/big-unsigned>>, - <<16#310fbb2027bdb7042f0e09e7b092e9ada506649510a7aa029825c8e8019e9c30:256/big-unsigned, - 16#749d723f2de1bd8c043d8d89d3748c2f:128/big-unsigned>>, - <<16#0d5e45317bc7997cb9c8a23bad9bac9170d5bc81789b51af6bcd74ace379fd64:256/big-unsigned, - 16#9a2b48cb56c4cb4ec1477e6933329e0e:128/big-unsigned>>, - <<16#aa1e77c094e5ce6db81a1add4c095201d020b7f8885a4333218da3b799b9fc42:256/big-unsigned, - 16#f00d60cd438a1724ae03bd7b515b739b:128/big-unsigned>>, - <<16#78cc6402a29eb984b8f8f888ab0102cabe7c06f0b9570e3d8d744c969db14397:256/big-unsigned, - 16#f58ecd14e70f324bf12d8dd4cd1ad3b2:128/big-unsigned>>, - <<16#72ec26cc742bc5fb1ef82541c9cadcf01a15c8104650d305f24ec8b006d7428e:256/big-unsigned, - 16#8ebe2bb320a465dbdd5c6326bbd8c9ad:128/big-unsigned>>]. - -sha512_expected() -> - [<<16#ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a:256/big-unsigned, - 16#2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f:256/big-unsigned>>, - <<16#204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c335:256/big-unsigned, - 16#96fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445:256/big-unsigned>>, - <<16#8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018:256/big-unsigned, - 16#501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909:256/big-unsigned>>, - <<16#23450737795d2f6a13aa61adcca0df5eef6df8d8db2b42cd2ca8f783734217a7:256/big-unsigned, - 16#3e9cabc3c9b8a8602f8aeaeb34562b6b1286846060f9809b90286b3555751f09:256/big-unsigned>>, - <<16#cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce:256/big-unsigned, - 16#47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e:256/big-unsigned>>, - <<16#70aefeaa0e7ac4f8fe17532d7185a289bee3b428d950c14fa8b713ca09814a38:256/big-unsigned, - 16#7d245870e007a80ad97c369d193e41701aa07f3221d15f0e65a1ff970cedf030:256/big-unsigned>>, - <<16#b3de4afbc516d2478fe9b518d063bda6c8dd65fc38402dd81d1eb7364e72fb6e:256/big-unsigned, - 16#6663cf6d2771c8f5a6da09601712fb3d2a36c6ffea3e28b0818b05b0a8660766:256/big-unsigned>>, - <<16#97fb4ec472f3cb698b9c3c12a12768483e5b62bcdad934280750b4fa4701e5e0:256/big-unsigned, - 16#550a80bb0828342c19631ba55a55e1cee5de2fda91fc5d40e7bee1d4e6d415b3:256/big-unsigned>>, - <<16#d399507bbf5f2d0da51db1ff1fc51c1c9ff1de0937e00d01693b240e84fcc340:256/big-unsigned, - 16#0601429f45c297acc6e8fcf1e4e4abe9ff21a54a0d3d88888f298971bd206cd5:256/big-unsigned>>, - <<16#caf970d3638e21053173a638c4b94d6d1ff87bc47b58f8ee928fbe9e245c23ab:256/big-unsigned, - 16#f81019e45bf017ecc8610e5e0b95e3b025ccd611a772ca4fb3dfba26f0859725:256/big-unsigned>>, - <<16#ee5d07460183b130687c977e9f8d43110989b0864b18fe6ee00a53dec5eda111:256/big-unsigned, - 16#f3aaa3bac7ab8dae26ed545a4de33ed45190f18fa0c327c44642ab9424265330:256/big-unsigned>>, - <<16#73ffeb67716c3495fbc33f2d62fe08e2616706a5599881c7e67e9ef2b68f4988:256/big-unsigned, - 16#ea8b3b604ba87e50b07962692705c420fa31a00be41d6aaa9f3b11eafe9cf49b:256/big-unsigned>>, - <<16#0e928db6207282bfb498ee871202f2337f4074f3a1f5055a24f08e912ac118f8:256/big-unsigned, - 16#101832cdb9c2f702976e629183db9bacfdd7b086c800687c3599f15de7f7b9dd:256/big-unsigned>>, - <<16#a001636f3ff1ce34f432f8e8f7785b78be84318beb8485a406650a8b243c419f:256/big-unsigned, - 16#7db6435cf6bf3000c6524adb5b52bad01afb76b3ceff701331e18b85b0e4cbd3:256/big-unsigned>>, - <<16#735bd6bebfe6f8070d70069105bc761f35ed1ac3742f2e372fdc14d2a51898e6:256/big-unsigned, - 16#153ccaff9073324130abdc451c730dc5dab5a0452487b1171c4dd97f92e267b7:256/big-unsigned>>, - <<16#fae25ec70bcb3bbdef9698b9d579da49db68318dbdf18c021d1f76aaceff9628:256/big-unsigned, - 16#38873235597e7cce0c68aabc610e0deb79b13a01c302abc108e459ddfbe9bee8:256/big-unsigned>>, - <<16#211bec83fbca249c53668802b857a9889428dc5120f34b3eac1603f13d1b4796:256/big-unsigned, - 16#5c387b39ef6af15b3a44c5e7b6bbb6c1096a677dc98fc8f472737540a332f378:256/big-unsigned>>, - <<16#ebad464e6d9f1df7e8aadff69f52db40a001b253fbf65a018f29974dcc7fbf8e:256/big-unsigned, - 16#58b69e247975fbadb4153d7289357c9b6212752d0ab67dd3d9bbc0bb908aa98c:256/big-unsigned>>]. diff --git a/apps/erlsha2/test/hmac_test.erl b/apps/erlsha2/test/hmac_test.erl deleted file mode 100644 index 445d2ae..0000000 --- a/apps/erlsha2/test/hmac_test.erl +++ /dev/null @@ -1,132 +0,0 @@ -%% @author Jared Flatow -%% @doc tests for hmac erlsha2 wrappers -%% @reference -%% See also -%% -%% Identifiers and Test Vectors for HMAC-SHA* -%% . - --module(hmac_test). - --include_lib("eunit/include/eunit.hrl"). - -hex_int(Binary) -> - list_to_integer(hmac:hexlify(Binary), 16). - -wikipedia_test() -> - ?assertMatch(16#fbdb1d1b18aa6c08324b7d64b71fb76370690e1d, - hex_int(hmac:hmac("", ""))), - ?assertMatch(16#b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad, - hex_int(hmac:hmac256("", ""))), - ?assertMatch(16#b936cee86c9f87aa5d3c6f2e84cb5a4239a5fe50480a6ec66b70ab5b1f4ac6730c6c515421b327ec1d69402e53dfb49ad7381eb067b338fd7b0cb22247225d47, - hex_int(hmac:hmac512("", ""))), - ?assertMatch(16#de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9, - hex_int(hmac:hmac("key", "The quick brown fox jumps over the lazy dog"))), - ?assertMatch(16#f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8, - hex_int(hmac:hmac256("key", "The quick brown fox jumps over the lazy dog"))), - ?assertMatch(16#b42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a, - hex_int(hmac:hmac512("key", "The quick brown fox jumps over the lazy dog"))), - ok. - -rfc_4231_1_test() -> - Key = binary:copy(<<16#0b>>, 20), - Val = "Hi There", - ?assertMatch(16#896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22, - hex_int(hmac:hmac224(Key, Val))), - ?assertMatch(16#b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7, - hex_int(hmac:hmac256(Key, Val))), - ?assertMatch(16#afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6, - hex_int(hmac:hmac384(Key, Val))), - ?assertMatch(16#87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854, - hex_int(hmac:hmac512(Key, Val))), - ok. - -%% Test with a key shorter than the length of the HMAC output. -rfc_4231_2_test() -> - Key = "Jefe", - Val = "what do ya want for nothing?", - ?assertMatch(16#a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44, - hex_int(hmac:hmac224(Key, Val))), - ?assertMatch(16#5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843, - hex_int(hmac:hmac256(Key, Val))), - ?assertMatch(16#af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649, - hex_int(hmac:hmac384(Key, Val))), - ?assertMatch(16#164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737, - hex_int(hmac:hmac512(Key, Val))), - ok. - -%% Test with a combined length of key and data that is larger than 64 bytes -%% (= block-size of SHA-224 and SHA-256). -rfc_4231_3_test() -> - Key = binary:copy(<<16#aa>>, 20), - Val = binary:copy(<<16#dd>>, 50), - ?assertMatch(16#7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea, - hex_int(hmac:hmac224(Key, Val))), - ?assertMatch(16#773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe, - hex_int(hmac:hmac256(Key, Val))), - ?assertMatch(16#88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e55966144b2a5ab39dc13814b94e3ab6e101a34f27, - hex_int(hmac:hmac384(Key, Val))), - ?assertMatch(16#fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb, - hex_int(hmac:hmac512(Key, Val))), - ok. - -%% Test with a combined length of key and data that is larger than 64 bytes -%% (= block-size of SHA-224 and SHA-256). -rfc_4231_4_test() -> - Key = list_to_binary(lists:seq(1, 16#19)), - Val = binary:copy(<<16#cd>>, 50), - ?assertMatch(16#6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a, - hex_int(hmac:hmac224(Key, Val))), - ?assertMatch(16#82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b, - hex_int(hmac:hmac256(Key, Val))), - ?assertMatch(16#3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e1f573b4e6801dd23c4a7d679ccf8a386c674cffb, - hex_int(hmac:hmac384(Key, Val))), - ?assertMatch(16#b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd, - hex_int(hmac:hmac512(Key, Val))), - ok. - -%% Test with a truncation of output to 128 bits. -rfc_4231_5_test() -> - Key = binary:copy(<<16#0c>>, 20), - Val = "Test With Truncation", - <> = hmac:hmac224(Key, Val), - <> = hmac:hmac256(Key, Val), - <> = hmac:hmac384(Key, Val), - <> = hmac:hmac512(Key, Val), - ?assertMatch(16#0e2aea68a90c8d37c988bcdb9fca6fa8, hex_int(Left224)), - ?assertMatch(16#a3b6167473100ee06e0c796c2955552b, hex_int(Left256)), - ?assertMatch(16#3abf34c3503b2a23a46efc619baef897, hex_int(Left384)), - ?assertMatch(16#415fad6271580a531d4179bc891d87a6, hex_int(Left512)), - ok. - -%% Test with a key larger than 128 bytes -%% (= block-size of SHA-384 and SHA-512). -rfc_4231_6_test() -> - Key = binary:copy(<<16#aa>>, 131), - Val = "Test Using Larger Than Block-Size Key - Hash Key First", - ?assertMatch(16#95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e, - hex_int(hmac:hmac224(Key, Val))), - ?assertMatch(16#60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54, - hex_int(hmac:hmac256(Key, Val))), - ?assertMatch(16#4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05033ac4c60c2ef6ab4030fe8296248df163f44952, - hex_int(hmac:hmac384(Key, Val))), - ?assertMatch(16#80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598, - hex_int(hmac:hmac512(Key, Val))), - ok. - -%% Test with a key and data that is larger than 128 bytes -%% (= block-size of SHA-384 and SHA-512). -rfc_4231_7_test() -> - Key = binary:copy(<<16#aa>>, 131), - Val = - "This is a test using a larger than block-size key and a larger than block-size data. " - "The key needs to be hashed before being used by the HMAC algorithm.", - ?assertMatch(16#3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1, - hex_int(hmac:hmac224(Key, Val))), - ?assertMatch(16#9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2, - hex_int(hmac:hmac256(Key, Val))), - ?assertMatch(16#6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82461e99c5a678cc31e799176d3860e6110c46523e, - hex_int(hmac:hmac384(Key, Val))), - ?assertMatch(16#e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58, - hex_int(hmac:hmac512(Key, Val))), - ok. diff --git a/apps/erlsha2/test/testvectors/LICENSE b/apps/erlsha2/test/testvectors/LICENSE deleted file mode 100644 index 5be305e..0000000 --- a/apps/erlsha2/test/testvectors/LICENSE +++ /dev/null @@ -1,30 +0,0 @@ -The test vectors in this directory are subject to the license -below. They're from . - -Copyright (c) 2000-2001, Aaron D. Gifford -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. diff --git a/apps/erlsha2/test/testvectors/vector001.dat b/apps/erlsha2/test/testvectors/vector001.dat deleted file mode 100644 index f2ba8f8..0000000 --- a/apps/erlsha2/test/testvectors/vector001.dat +++ /dev/null @@ -1 +0,0 @@ -abc \ No newline at end of file diff --git a/apps/erlsha2/test/testvectors/vector001.info b/apps/erlsha2/test/testvectors/vector001.info deleted file mode 100644 index 57b444e..0000000 --- a/apps/erlsha2/test/testvectors/vector001.info +++ /dev/null @@ -1,21 +0,0 @@ -DESCRIPTION: - This test vector is taken from the PDF document that describes - the SHA-256/384/512 algorithms. That document contains sample - output for all three versions (SHA-256, SHA-384, and SHA-512). - - (Total length of test vector data: 3) - -FILE: - vector001.dat - -SHA256: - ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad - -SHA384: - cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed - 8086072ba1e7cc2358baeca134c825a7 - -SHA512: - ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a - 2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f - diff --git a/apps/erlsha2/test/testvectors/vector002.dat b/apps/erlsha2/test/testvectors/vector002.dat deleted file mode 100644 index 199f24e..0000000 --- a/apps/erlsha2/test/testvectors/vector002.dat +++ /dev/null @@ -1 +0,0 @@ -abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq \ No newline at end of file diff --git a/apps/erlsha2/test/testvectors/vector002.info b/apps/erlsha2/test/testvectors/vector002.info deleted file mode 100644 index 0fc1ed3..0000000 --- a/apps/erlsha2/test/testvectors/vector002.info +++ /dev/null @@ -1,21 +0,0 @@ -DESCRIPTION: - The PDF document only provided sample output for SHA-256 using - this test data. I have provided SHA-384 and SHA-512 sample - output from my own implementation which may not be correct. - - (Total length of test vector data: 56) - -FILE: - vector002.dat - -SHA256: - 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 - -SHA384: - 3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6 - b0455a8520bc4e6f5fe95b1fe3c8452b - -SHA512: - 204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c335 - 96fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445 - diff --git a/apps/erlsha2/test/testvectors/vector003.dat b/apps/erlsha2/test/testvectors/vector003.dat deleted file mode 100644 index 4674ea4..0000000 --- a/apps/erlsha2/test/testvectors/vector003.dat +++ /dev/null @@ -1 +0,0 @@ -abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu \ No newline at end of file diff --git a/apps/erlsha2/test/testvectors/vector003.info b/apps/erlsha2/test/testvectors/vector003.info deleted file mode 100644 index 17a2ad8..0000000 --- a/apps/erlsha2/test/testvectors/vector003.info +++ /dev/null @@ -1,22 +0,0 @@ -DESCRIPTION: - For this test data (from the PDF document), no example output - was provided for SHA-256 (SHA-384 and SHA-512 samples were - provided), so the sample for SHA-256 comes from the output of - my own implementation and so may not be correct. - - (Total length of test vector data: 112) - -FILE: - vector003.dat - -SHA256: - cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1 - -SHA384: - 09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712 - fcc7c71a557e2db966c3e9fa91746039 - -SHA512: - 8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018 - 501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909 - diff --git a/apps/erlsha2/test/testvectors/vector004.dat b/apps/erlsha2/test/testvectors/vector004.dat deleted file mode 100644 index 3d71eba..0000000 --- a/apps/erlsha2/test/testvectors/vector004.dat +++ /dev/null @@ -1 +0,0 @@ -Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate--we can not consecrate--we can not hallow--this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us--that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion--that we here highly resolve that these dead shall not have died in vain--that this nation, under God, shall have a new birth of freedom--and that government of the people, by the people, for the people, shall not perish from the earth. -- President Abraham Lincoln, November 19, 1863 \ No newline at end of file diff --git a/apps/erlsha2/test/testvectors/vector004.info b/apps/erlsha2/test/testvectors/vector004.info deleted file mode 100644 index eed148c..0000000 --- a/apps/erlsha2/test/testvectors/vector004.info +++ /dev/null @@ -1,22 +0,0 @@ -DESCRIPTION: - The output samples for this test vector come exclusively from my - own implementation and so may be completely incorrect. Use with - a very large grain of salt. The input sample comes from...well - most anyone in the U.S. will know and many outside the U.S. too. - - (Total length of test vector data: 1515) - -FILE: - vector004.dat - -SHA256: - 4d25fccf8752ce470a58cd21d90939b7eb25f3fa418dd2da4c38288ea561e600 - -SHA384: - 69cc75b95280bdd9e154e743903e37b1205aa382e92e051b1f48a6db9d0203f8 - a17c1762d46887037275606932d3381e - -SHA512: - 23450737795d2f6a13aa61adcca0df5eef6df8d8db2b42cd2ca8f783734217a7 - 3e9cabc3c9b8a8602f8aeaeb34562b6b1286846060f9809b90286b3555751f09 - diff --git a/apps/erlsha2/test/testvectors/vector005.dat b/apps/erlsha2/test/testvectors/vector005.dat deleted file mode 100644 index e69de29..0000000 diff --git a/apps/erlsha2/test/testvectors/vector005.info b/apps/erlsha2/test/testvectors/vector005.info deleted file mode 100644 index 37602d3..0000000 --- a/apps/erlsha2/test/testvectors/vector005.info +++ /dev/null @@ -1,23 +0,0 @@ -DESCRIPTION: - The output samples for this test vector come exclusively from my - own implementation and so may be completely incorrect. Use with - a very large grain of salt. The input sample is EMPTY (no bits). - Mr. David A. Ireland's SHA-256 implementation agrees with my own - implementation on the output of this test vector (SHA-256 only). - - (Total length of test vector data: 0) - -FILE: - vector005.dat - -SHA256: - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - -SHA384: - 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da - 274edebfe76f65fbd51ad2f14898b95b - -SHA512: - cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce - 47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e - diff --git a/apps/erlsha2/test/testvectors/vector006.dat b/apps/erlsha2/test/testvectors/vector006.dat deleted file mode 100644 index 7caf161..0000000 --- a/apps/erlsha2/test/testvectors/vector006.dat +++ /dev/null @@ -1 +0,0 @@ -This is exactly 64 bytes long, not counting the terminating byte \ No newline at end of file diff --git a/apps/erlsha2/test/testvectors/vector006.info b/apps/erlsha2/test/testvectors/vector006.info deleted file mode 100644 index 2a0d78a..0000000 --- a/apps/erlsha2/test/testvectors/vector006.info +++ /dev/null @@ -1,22 +0,0 @@ -DESCRIPTION: - The output samples for thi test vector come exclusively from my - own implementation and so may be completely incorrect. Use with - a very large grain of salt. The input sample exactly the same - length as the SHA-256 block length. - - (Total length of test vector data: 64) - -FILE: - vector006.dat - -SHA256: - ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8 - -SHA384: - e28e35e25a1874908bf0958bb088b69f3d742a753c86993e9f4b1c4c21988f95 - 8bd1fe0315b195aca7b061213ac2a9bd - -SHA512: - 70aefeaa0e7ac4f8fe17532d7185a289bee3b428d950c14fa8b713ca09814a38 - 7d245870e007a80ad97c369d193e41701aa07f3221d15f0e65a1ff970cedf030 - diff --git a/apps/erlsha2/test/testvectors/vector007.dat b/apps/erlsha2/test/testvectors/vector007.dat deleted file mode 100644 index 1caf01b..0000000 --- a/apps/erlsha2/test/testvectors/vector007.dat +++ /dev/null @@ -1 +0,0 @@ -For this sample, this 63-byte string will be used as input data \ No newline at end of file diff --git a/apps/erlsha2/test/testvectors/vector007.info b/apps/erlsha2/test/testvectors/vector007.info deleted file mode 100644 index fad860d..0000000 --- a/apps/erlsha2/test/testvectors/vector007.info +++ /dev/null @@ -1,22 +0,0 @@ -DESCRIPTION: - The output samples for thi test vector come exclusively from my - own implementation and so may be completely incorrect. Use with - a very large grain of salt. The input sample one byte shorter - than the SHA-256 block length. - - (Total length of test vector data: 63) - -FILE: - vector007.dat - -SHA256: - f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342 - -SHA384: - 37b49ef3d08de53e9bd018b0630067bd43d09c427d06b05812f48531bce7d2a6 - 98ee2d1ed1ffed46fd4c3b9f38a8a557 - -SHA512: - b3de4afbc516d2478fe9b518d063bda6c8dd65fc38402dd81d1eb7364e72fb6e - 6663cf6d2771c8f5a6da09601712fb3d2a36c6ffea3e28b0818b05b0a8660766 - diff --git a/apps/erlsha2/test/testvectors/vector008.dat b/apps/erlsha2/test/testvectors/vector008.dat deleted file mode 100644 index baae226..0000000 --- a/apps/erlsha2/test/testvectors/vector008.dat +++ /dev/null @@ -1 +0,0 @@ -And this textual data, astonishing as it may appear, is exactly 128 bytes in length, as are both SHA-384 and SHA-512 block sizes \ No newline at end of file diff --git a/apps/erlsha2/test/testvectors/vector008.info b/apps/erlsha2/test/testvectors/vector008.info deleted file mode 100644 index 22cfd81..0000000 --- a/apps/erlsha2/test/testvectors/vector008.info +++ /dev/null @@ -1,22 +0,0 @@ -DESCRIPTION: - The output samples for thi test vector come exclusively from my - own implementation and so may be completely incorrect. Use with - a very large grain of salt. The input sample exactly the same - length as the SHA-384 and SHA-512 block lengths. - - (Total length of test vector data: 128) - -FILE: - vector008.dat - -SHA256: - 0ab803344830f92089494fb635ad00d76164ad6e57012b237722df0d7ad26896 - -SHA384: - e3e3602f4d90c935321d788f722071a8809f4f09366f2825cd85da97ccd2955e - b6b8245974402aa64789ed45293e94ba - -SHA512: - 97fb4ec472f3cb698b9c3c12a12768483e5b62bcdad934280750b4fa4701e5e0 - 550a80bb0828342c19631ba55a55e1cee5de2fda91fc5d40e7bee1d4e6d415b3 - diff --git a/apps/erlsha2/test/testvectors/vector009.dat b/apps/erlsha2/test/testvectors/vector009.dat deleted file mode 100644 index 9c64af4..0000000 --- a/apps/erlsha2/test/testvectors/vector009.dat +++ /dev/null @@ -1 +0,0 @@ -By hashing data that is one byte less than a multiple of a hash block length (like this 127-byte string), bugs may be revealed. \ No newline at end of file diff --git a/apps/erlsha2/test/testvectors/vector009.info b/apps/erlsha2/test/testvectors/vector009.info deleted file mode 100644 index d5fe515..0000000 --- a/apps/erlsha2/test/testvectors/vector009.info +++ /dev/null @@ -1,22 +0,0 @@ -DESCRIPTION: - The output samples for thi test vector come exclusively from my - own implementation and so may be completely incorrect. Use with - a very large grain of salt. The input sample is one byte shorter - in length than the SHA-384 and SHA-512 block lengths. - - (Total length of test vector data: 127) - -FILE: - vector009.dat - -SHA256: - e4326d0459653d7d3514674d713e74dc3df11ed4d30b4013fd327fdb9e394c26 - -SHA384: - 1ca650f38480fa9dfb5729636bec4a935ebc1cd4c0055ee50cad2aa627e06687 - 1044fd8e6fdb80edf10b85df15ba7aab - -SHA512: - d399507bbf5f2d0da51db1ff1fc51c1c9ff1de0937e00d01693b240e84fcc340 - 0601429f45c297acc6e8fcf1e4e4abe9ff21a54a0d3d88888f298971bd206cd5 - diff --git a/apps/erlsha2/test/testvectors/vector010.dat b/apps/erlsha2/test/testvectors/vector010.dat deleted file mode 100644 index f1681bce65cb44b71f4e7d038c0996d18e87e52d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 320 zcmV-G0l)qi?_wT_&uOCGc%%j%23hC|&&IOS1gR8BGE?I*zIf8%28ujfJXqz+MOpEb zQTh4+iDHl^gCSGgb3=fr^+xlNDBJ=46-NNfK8tNXdh*|`j7}SQfE#RGQFH7(W%C5N zy;G@9j?B>L;`;+6>zqQQ91wq>SY)RJf=zXl<07DF;=*e-G-&~(V zAA9HoSr!4veH7BtVZC>+&ERmF`FoNw!qV2Z5imje_UHbps@~W?T*emj)?L1O2Xy*D zuL?nSnJ?7(T`id8xt;aAXzAbWJGY-wt6$ZqA_YRJdP?>13Zfs?Ir}l;plRmXLF6X7 zCROD{c_>#$&J4ngIdK@G=r<_T6rfg=8-3YqJ646+>`;?Xm%ix(8ay1ufMq8CGFoYQ S#pjxPhO@Ky;+z{B`1-N&OsFUT diff --git a/apps/erlsha2/test/testvectors/vector010.info b/apps/erlsha2/test/testvectors/vector010.info deleted file mode 100644 index df7717d..0000000 --- a/apps/erlsha2/test/testvectors/vector010.info +++ /dev/null @@ -1,22 +0,0 @@ -DESCRIPTION: - The output samples for thi test vector come exclusively from my - own implementation and so may be completely incorrect. Use with - a very large grain of salt. The input sample is exactly 5 times - size of the SHA-256 block length. - - (Total length of test vector data: 320) - -FILE: - vector010.dat - -SHA256: - a7f001d996dd25af402d03b5f61aef950565949c1a6ad5004efa730328d2dbf3 - -SHA384: - b8261ddcd7df7b3969a516b72550de6fbf0e394a4a7bb2bbc60ec603c2ceff64 - 3c5bf62bc6dcbfa5beb54b62d750b969 - -SHA512: - caf970d3638e21053173a638c4b94d6d1ff87bc47b58f8ee928fbe9e245c23ab - f81019e45bf017ecc8610e5e0b95e3b025ccd611a772ca4fb3dfba26f0859725 - diff --git a/apps/erlsha2/test/testvectors/vector011.dat b/apps/erlsha2/test/testvectors/vector011.dat deleted file mode 100644 index d1609a9b5e72c7125f55e39cb9e2ef20e2ad36e6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 447 zcmV;w0YLsue@9|VqFjU1a#k~Et^q|DOu3BCP(^fUZilk#G%64?%ADnBvx%#MsV0TH zSmOX62J(PkVWRv;MDRi7bHtUCmb;`|W9gOTG-gPXw=;D1lR;yUOxX;NVM%frG1*@O zSY`pHPrRnwsLBN6nz}KK>x$XqQ22CT+auD@z%Thros6t*BM1tHXpMtSv&2Q8zwToz}g{NDaU4#c!bFt zbkoFg0GC666&Y`d8V&*Zhr$_p&eW}mD#FqoWNC2LpuDr#fO7e-^_1wPC6($2CTzIF zJtv@`@gT00307*(0-iCG?jAx1MwTfjc1{2!QQ0u@!k$|2YJTWUL@r1>M%=5ila)r! zsrScSX2*tA50JWhdq51{`LJTfDRoiqN7Yzsj@Hes0$a@eVhhp{C0kwM(8oUPu9t~w zewqF6qq#;B$!t6CGlgh!7|U`dNNXv!{4Mk5-Jnyq`3>r;k7#A;RCp2RzOpYZ=5QMjf=h|Da0YdiOdIVnUhuyZZ1&O^yNLfgM|ncQKk{eZFcs(2MR zd~b`bR8>n>GN*O<$z1KvL;$n*gO$|c^_&lH1>17KL5h?RS+-yBJB~4i3%%gQi+}74 zAFhWxGAijtYCrTj5&X~T>Trh{D((kUy(8aa-Gi_;Q#YQ*_2{OT z-;F?I3tVg^%t3>Rm<=?WFHwA=S73Ks+`t!?Ddd(HFehG+&;n`ctN5kV9otqwmZecI zk{5YIDvIR61)zY%FV2Q*(Q&ZKJOs@6BqC$O!W!FAXt)|{pcpvLk8L_z#s1f{i^2*T_Rk>>I;)!5hSn#v6HVofe? zob>llHbs(kr?j@nZYr-vt@E(3I$3k;=g3tPsnX9?IpNvLvC^y3mF(o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