Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

revamp the original pure Erlang implementation

  • Loading branch information...
commit 475111d5add6ff0cc322e58f8b1251fd042ec7da 0 parents
@vinoski authored
Showing with 2,089 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +1 −0  AUTHORS
  3. +27 −0 LICENSE
  4. +30 −0 README.md
  5. +39 −0 c_src/config.sh
  6. +750 −0 c_src/erlsha2_nif.c
  7. +13 −0 rebar.config
  8. +14 −0 src/erlsha2.app.src
  9. +496 −0 src/erlsha2.erl
  10. +263 −0 test/erlsha2_test.erl
  11. +30 −0 test/testvectors/LICENSE
  12. +1 −0  test/testvectors/vector001.dat
  13. +21 −0 test/testvectors/vector001.info
  14. +1 −0  test/testvectors/vector002.dat
  15. +21 −0 test/testvectors/vector002.info
  16. +1 −0  test/testvectors/vector003.dat
  17. +22 −0 test/testvectors/vector003.info
  18. +1 −0  test/testvectors/vector004.dat
  19. +22 −0 test/testvectors/vector004.info
  20. 0  test/testvectors/vector005.dat
  21. +23 −0 test/testvectors/vector005.info
  22. +1 −0  test/testvectors/vector006.dat
  23. +22 −0 test/testvectors/vector006.info
  24. +1 −0  test/testvectors/vector007.dat
  25. +22 −0 test/testvectors/vector007.info
  26. +1 −0  test/testvectors/vector008.dat
  27. +22 −0 test/testvectors/vector008.info
  28. +1 −0  test/testvectors/vector009.dat
  29. +22 −0 test/testvectors/vector009.info
  30. BIN  test/testvectors/vector010.dat
  31. +22 −0 test/testvectors/vector010.info
  32. BIN  test/testvectors/vector011.dat
  33. +22 −0 test/testvectors/vector011.info
  34. BIN  test/testvectors/vector012.dat
  35. +22 −0 test/testvectors/vector012.info
  36. BIN  test/testvectors/vector013.dat
  37. +22 −0 test/testvectors/vector013.info
  38. BIN  test/testvectors/vector014.dat
  39. +22 −0 test/testvectors/vector014.info
  40. +1 −0  test/testvectors/vector015.dat
  41. +21 −0 test/testvectors/vector015.info
  42. +1 −0  test/testvectors/vector016.dat
  43. +23 −0 test/testvectors/vector016.info
  44. BIN  test/testvectors/vector017.dat
  45. +32 −0 test/testvectors/vector017.info
  46. BIN  test/testvectors/vector018.dat
  47. +26 −0 test/testvectors/vector018.info
7 .gitignore
@@ -0,0 +1,7 @@
+*~
+.eunit
+c_src/config.h
+c_src/*.o
+doc
+ebin
+priv
1  AUTHORS
@@ -0,0 +1 @@
+Steve Vinoski <vinoski@ieee.org>
27 LICENSE
@@ -0,0 +1,27 @@
+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.
30 README.md
@@ -0,0 +1,30 @@
+# 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.
+
+See the following links for details:
+
+* (Secure Hash Standard)[href="http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf"]
+* (Wikipedia SHA1 article)[href="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.
+
+## Building and Installing
+
+The **erlsha2** app is built with
+[rebar](https://github.com/basho/rebar), which must be in the command `PATH`.
+
+### Erlang Version
+
+The **erlsha2** app requires Erlang R14B or later.
39 c_src/config.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+set -e
+
+CONFIG_HDR=c_src/config.h
+
+if [[ $1 = clean ]]; then
+ rm -f $CONFIG_HDR
+ exit 0
+fi
+
+[[ -n "$CC" ]]
+
+tmpfile=`mktemp /tmp/erlsha2.XXXXXX`
+tmpcfile=${tmpfile}.c
+trap "rm -f $tmpfile $tmpcfile" EXIT
+mv $tmpfile $tmpcfile
+echo '#include <stdint.h>' > $tmpcfile
+if $CC $CFLAGS -c -o /dev/null $tmpcfile 2>/dev/null ; then
+ echo '#define HAVE_STDINT_H 1' > $CONFIG_HDR
+else
+ echo '#include <inttypes.h>' > $tmpcfile
+ if $CC $CFLAGS -c -o /dev/null $tmpcfile 2>/dev/null ; then
+ echo '#define HAVE_INTTYPES_H 1' > $CONFIG_HDR
+ else
+ echo 'neither <stdint.h> nor <inttypes.h> 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
750 c_src/erlsha2_nif.c
@@ -0,0 +1,750 @@
+/*
+ * 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 <stdint.h>
+#elif HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#include <string.h>
+#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[]
+);
+
+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 term;
+ 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);
+ }
+ term = enif_make_binary(env, &ctx->digest);
+ enif_release_resource(ctx);
+ return term;
+}
+
+#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,
+ TermArgcArgvFun 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 nctx = hd_update(env, 2, args);
+ ERL_NIF_TERM nargs[1] = {nctx};
+ return hd_final(env, 1, nargs);
+}
+
+static ERL_NIF_TERM
+hd224_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+ 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);
+ return enif_make_resource(env, ctx);
+}
+
+static ERL_NIF_TERM
+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 enif_make_badarg(env);
+ }
+ if (!enif_inspect_iolist_as_binary(env, argv[1], &data)) {
+ return enif_make_badarg(env);
+ }
+ sha_update_chunks(ctxu.c, &data, sha2xx_chunk);
+ return argv[0];
+}
+
+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);
+}
+
+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[])
+{
+ 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);
+ return enif_make_resource(env, ctx);
+}
+
+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);
+}
+
+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[])
+{
+ 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);
+ return enif_make_resource(env, ctx);
+}
+
+static ERL_NIF_TERM
+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 enif_make_badarg(env);
+ }
+ if (!enif_inspect_iolist_as_binary(env, argv[1], &data)) {
+ return enif_make_badarg(env);
+ }
+ sha_update_chunks(ctxu.c, &data, sha5xx_chunk);
+ return argv[0];
+}
+
+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);
+}
+
+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[])
+{
+ 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);
+ return enif_make_resource(env, ctx);
+}
+
+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);
+}
+
+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 int
+nifload(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
+{
+ *priv_data = enif_open_resource_type(env, NULL, "erlsha2_context", NULL,
+ ERL_NIF_RT_CREATE, NULL);
+ return 0;
+}
+
+ERL_NIF_INIT(erlsha2, funcs, nifload, NULL, NULL, NULL)
13 rebar.config
@@ -0,0 +1,13 @@
+{port_sources, ["c_src/*.c"]}.
+{so_specs, [{"priv/erlsha2_nif.so",["c_src/erlsha2_nif.o"]}]}.
+
+{port_envs, [
+ {"DRV_CFLAGS", "$DRV_CFLAGS -O3 -I."},
+ {"linux.*-32$", "CFLAGS", "-m32"},
+ {"linux.*-32$", "LDFLAGS", "-m32"},
+ {"linux.*-64$", "CFLAGS", "-m64"},
+ {"linux.*-64$", "LDFLAGS", "-m64"}
+ ]}.
+
+{port_pre_script, {"c_src/config.sh", "c_src/config.h"}}.
+{port_cleanup_script, "c_src/config.sh clean"}.
14 src/erlsha2.app.src
@@ -0,0 +1,14 @@
+{application, erlsha2,
+ [
+ {description, "SHA-2 Erlang/C library"},
+ {vsn, "2.0"},
+ {modules, [
+ erlsha2
+ ]},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {env, []}
+ ]}.
496 src/erlsha2.erl
@@ -0,0 +1,496 @@
+%%% @author Steve Vinoski <vinoski@ieee.org> [http://steve.vinoski.net/]
+%%% @doc Implementations of SHA-224, SHA-256, SHA-384, SHA-512 in Erlang NIFs.
+%%% @reference See <a
+%%% href="http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf">
+%%% the Secure Hash Standard</a> and the <a
+%%% href="http://en.wikipedia.org/wiki/SHA1">Wikipedia SHA1
+%%% article</a>. Find the code <a
+%%% href="http://github.com/vinoski/erlsha2">here</a>.
+%%% @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
+ case file:read_file_info("./priv") of
+ {error, _} ->
+ "../priv";
+ _ ->
+ "./priv"
+ end;
+ Dir ->
+ Dir
+ end, atom_to_list(?MODULE) ++ "_nif"),
+ erlang:load_nif(SoName, 0).
+
+%% @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:WordSize/big-unsigned>> ||
+ V <- Sha(split_binary(Pad(M), BitLen), Hashes)]).
+
+rotate32(V, Count) ->
+ Rest = 32 - Count,
+ <<Top:Rest/unsigned, Bottom:Count/unsigned>> = <<V:32/big-unsigned>>,
+ <<New:32/big-unsigned>> = <<Bottom:Count/unsigned, Top:Rest/unsigned>>,
+ New.
+
+rotate64(V, Count) ->
+ Rest = 64 - Count,
+ <<Top:Rest/unsigned, Bottom:Count/unsigned>> = <<V:64/big-unsigned>>,
+ <<New:64/big-unsigned>> = <<Bottom:Count/unsigned, Top:Rest/unsigned>>,
+ 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>> = <<W/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>> = <<W/binary>>,
+ Next = (W16 + S0 + W7 + S1) band 16#FFFFFFFF,
+ sha256_extend(<<W/binary, Next:32/big-unsigned>>, 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>> = <<W/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>> = <<W/binary>>,
+ Next = (W16 + S0 + W7 + S1) band 16#FFFFFFFFFFFFFFFF,
+ sha512_extend(<<W/binary, Next:64/big-unsigned>>, 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>> = <<W/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>> = <<W/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)).
263 test/erlsha2_test.erl
@@ -0,0 +1,263 @@
+%%%
+%%% These tests come from
+%%% <http://www.aarongifford.com/computers/sha.html>. 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]}}.
+
+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(),
+ 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, lists:zip(Vectors, Expected224)),
+ 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(),
+ 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, lists:zip(Vectors, Expected256)),
+ 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(),
+ 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, lists:zip(Vectors, Expected384)),
+ 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(),
+ 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, lists:zip(Vectors, Expected512)),
+ 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>>].
30 test/testvectors/LICENSE
@@ -0,0 +1,30 @@
+The test vectors in this directory are subject to the license
+below. They're from <http://www.aarongifford.com/computers/sha2-1.0.tar.gz>.
+
+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.
1  test/testvectors/vector001.dat
@@ -0,0 +1 @@
+abc
21 test/testvectors/vector001.info
@@ -0,0 +1,21 @@
+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
+
1  test/testvectors/vector002.dat
@@ -0,0 +1 @@
+abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
21 test/testvectors/vector002.info
@@ -0,0 +1,21 @@
+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
+
1  test/testvectors/vector003.dat
@@ -0,0 +1 @@
+abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu
22 test/testvectors/vector003.info
@@ -0,0 +1,22 @@
+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
+
1  test/testvectors/vector004.dat
@@ -0,0 +1 @@
+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
22 test/testvectors/vector004.info
@@ -0,0 +1,22 @@
+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
+
0  test/testvectors/vector005.dat
No changes.
23 test/testvectors/vector005.info
@@ -0,0 +1,23 @@
+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
+
1  test/testvectors/vector006.dat
@@ -0,0 +1 @@
+This is exactly 64 bytes long, not counting the terminating byte
22 test/testvectors/vector006.info
@@ -0,0 +1,22 @@
+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
+
1  test/testvectors/vector007.dat
@@ -0,0 +1 @@
+For this sample, this 63-byte string will be used as input data
22 test/testvectors/vector007.info
@@ -0,0 +1,22 @@
+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
+
1  test/testvectors/vector008.dat
@@ -0,0 +1 @@
+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
22 test/testvectors/vector008.info
@@ -0,0 +1,22 @@
+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
+
1  test/testvectors/vector009.dat
@@ -0,0 +1 @@
+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.
22 test/testvectors/vector009.info
@@ -0,0 +1,22 @@
+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
+
BIN  test/testvectors/vector010.dat
Binary file not shown
22 test/testvectors/vector010.info
@@ -0,0 +1,22 @@
+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
+
BIN  test/testvectors/vector011.dat
Binary file not shown
22 test/testvectors/vector011.info
@@ -0,0 +1,22 @@
+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 less
+ than 7 times the size of the SHA-256 block length.
+
+ (Total length of test vector data: 447)
+
+FILE:
+ vector011.dat
+
+SHA256:
+ 6dcd63a07b0922cc3a9b3315b158478681cc32543b0a4180abe58a73c5e14cc2
+
+SHA384:
+ 548e4e9a1ff57f469ed47b023bf5279dfb4d4ca08c65051e3a5c41fab84479a2
+ 05496276906008b4b3c5b0970b2f5446
+
+SHA512:
+ ee5d07460183b130687c977e9f8d43110989b0864b18fe6ee00a53dec5eda111
+ f3aaa3bac7ab8dae26ed545a4de33ed45190f18fa0c327c44642ab9424265330
+
BIN  test/testvectors/vector012.dat
Binary file not shown
22 test/testvectors/vector012.info
@@ -0,0 +1,22 @@
+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-384 and SHA-512 block lengths.
+
+ (Total length of test vector data: 640)
+
+FILE:
+ vector012.dat
+
+SHA256:
+ af6ebfde7d93d5badb6cde6287ecc2061c1cafc5b1c1217cd984fbcdb9c61aaa
+
+SHA384:
+ c6fec3a3278dd6b5afc8c0971d32d38faf5802f1a21527c32563b32a1ac34065
+ 6b433b44fe2648aa2232206f4301193a
+
+SHA512:
+ 73ffeb67716c3495fbc33f2d62fe08e2616706a5599881c7e67e9ef2b68f4988
+ ea8b3b604ba87e50b07962692705c420fa31a00be41d6aaa9f3b11eafe9cf49b
+
BIN  test/testvectors/vector013.dat
Binary file not shown
22 test/testvectors/vector013.info
@@ -0,0 +1,22 @@
+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 short
+ of 17 times size of the SHA-384 and SHA-512 block lengths.
+
+ (Total length of test vector data: 2175)
+
+FILE:
+ vector013.dat
+
+SHA256:
+ 8ff59c6d33c5a991088bc44dd38f037eb5ad5630c91071a221ad6943e872ac29
+
+SHA384:
+ 92dca5655229b3c34796a227ff1809e273499adc2830149481224e0f54ff4483
+ bd49834d4865e508ef53d4cd22b703ce
+
+SHA512:
+ 0e928db6207282bfb498ee871202f2337f4074f3a1f5055a24f08e912ac118f8
+ 101832cdb9c2f702976e629183db9bacfdd7b086c800687c3599f15de7f7b9dd
+
BIN  test/testvectors/vector014.dat
Binary file not shown
22 test/testvectors/vector014.info
@@ -0,0 +1,22 @@
+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 4 KB of misc.
+ data.
+
+ (Total length of test vector data: 16384)
+
+FILE:
+ vector014.dat
+
+SHA256:
+ 1818e87564e0c50974ecaabbb2eb4ca2f6cc820234b51861e2590be625f1f703
+
+SHA384:
+ 310fbb2027bdb7042f0e09e7b092e9ada506649510a7aa029825c8e8019e9c30
+ 749d723f2de1bd8c043d8d89d3748c2f
+
+SHA512:
+ a001636f3ff1ce34f432f8e8f7785b78be84318beb8485a406650a8b243c419f
+ 7db6435cf6bf3000c6524adb5b52bad01afb76b3ceff701331e18b85b0e4cbd3
+
1  test/testvectors/vector015.dat
1 addition, 0 deletions not shown
21 test/testvectors/vector015.info
@@ -0,0 +1,21 @@
+DESCRIPTION:
+ This is yet another of my own test vectors for a larger
+ input data set. The input data is the string "qwerty
+ repeated 65536 times.
+
+ (Total length of test vector data: 393216)
+
+FILE:
+ vector015.dat
+
+SHA256:
+ 5e3dfe0cc98fd1c2de2a9d2fd893446da43d290f2512200c515416313cdf3192
+
+SHA384:
+ 0d5e45317bc7997cb9c8a23bad9bac9170d5bc81789b51af6bcd74ace379fd64
+ 9a2b48cb56c4cb4ec1477e6933329e0e
+
+SHA512:
+ 735bd6bebfe6f8070d70069105bc761f35ed1ac3742f2e372fdc14d2a51898e6
+ 153ccaff9073324130abdc451c730dc5dab5a0452487b1171c4dd97f92e267b7
+
1  test/testvectors/vector016.dat
@@ -0,0 +1 @@
+Rijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AESRijndael is AES
23 test/testvectors/vector016.info
@@ -0,0 +1,23 @@
+DESCRIPTION:
+ This test vector came from Brian LaMacchia in his e-mail
+ message containing several samples of output from his SHA-256
+ and SHA-512 implementations. My own implementations match
+ his output exactly. The input data data set is the string
+ "Rijndael is AES" repeated 1024 times.
+
+ (Total length of test vector data: 15360)
+
+FILE:
+ vector016.dat
+
+SHA256:
+ 80fced5a97176a5009207cd119551b42c5b51ceb445230d02ecc2663bbfb483a
+
+SHA384:
+ aa1e77c094e5ce6db81a1add4c095201d020b7f8885a4333218da3b799b9fc42
+ f00d60cd438a1724ae03bd7b515b739b
+
+SHA512:
+ fae25ec70bcb3bbdef9698b9d579da49db68318dbdf18c021d1f76aaceff9628
+ 38873235597e7cce0c68aabc610e0deb79b13a01c302abc108e459ddfbe9bee8
+
BIN  test/testvectors/vector017.dat
Binary file not shown
32 test/testvectors/vector017.info
@@ -0,0 +1,32 @@
+DESCRIPTION:
+ Rogier van de Pol notified me that my implementation differed
+ with several others on several test data sets he had tested
+ against. This test vector data set is one Rogier provided
+ to me that highlighted an off-by-one bug in my implementation
+ that affected SHA-256/384/512 hashes where the data set length
+ was of a certain length. In the case of SHA512 or SHA384, if
+ the data length after subtracting 111 was an even multiple of
+ 128 bytes, the bug surfaced. In the case of SHA256, after
+ subtracting 55, the remaining length was an even multiple of 64,
+ the bug surfaced. The fix was simple. In SHA512_Last() and in
+ SHA256_Final() functions, I simply replaced a single "<" test
+ with a "<=" test.
+
+ Thanks, Rogier!
+
+ (Total length of test vector data: 12271)
+
+FILE:
+ vector017.dat
+
+SHA256:
+ 88ee6ada861083094f4c64b373657e178d88ef0a4674fce6e4e1d84e3b176afb
+
+SHA384:
+ 78cc6402a29eb984b8f8f888ab0102cabe7c06f0b9570e3d8d744c969db14397
+ f58ecd14e70f324bf12d8dd4cd1ad3b2
+
+SHA512:
+ 211bec83fbca249c53668802b857a9889428dc5120f34b3eac1603f13d1b4796
+ 5c387b39ef6af15b3a44c5e7b6bbb6c1096a677dc98fc8f472737540a332f378
+
BIN  test/testvectors/vector018.dat
Binary file not shown
26 test/testvectors/vector018.info
@@ -0,0 +1,26 @@
+DESCRIPTION:
+ I added this vector after fixing a bug first discovered by
+ Rogier van de Pol. The length of this data set is designed to
+ test for that bug or similar bugs in SHA-256 hashes. The bug
+ was an off-by-one bug where I used a "<" test instead of a "<="
+ test in SHA256_Final(). Whenever data set lengths were an even
+ multiple of 64 after subtracting 55, the bug showed up. The
+ fix was easy, once the problem was fully diagnosed.
+
+ Thanks, Rogier!
+
+ (Total length of test vector data: 1079)
+
+FILE:
+ vector018.dat
+
+SHA256:
+ 5a2e925a7f8399fa63a20a1524ae83a7e3c48452f9af4df493c8c51311b04520
+
+SHA384:
+ 72ec26cc742bc5fb1ef82541c9cadcf01a15c8104650d305f24ec8b006d7428e
+ 8ebe2bb320a465dbdd5c6326bbd8c9ad
+
+SHA512:
+ ebad464e6d9f1df7e8aadff69f52db40a001b253fbf65a018f29974dcc7fbf8e
+ 58b69e247975fbadb4153d7289357c9b6212752d0ab67dd3d9bbc0bb908aa98c
Please sign in to comment.
Something went wrong with that request. Please try again.