Permalink
Browse files

revamp the original pure Erlang implementation

  • Loading branch information...
vinoski committed Feb 19, 2011
0 parents commit 475111d5add6ff0cc322e58f8b1251fd042ec7da
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
@@ -0,0 +1,7 @@
+*~
+.eunit
+c_src/config.h
+c_src/*.o
+doc
+ebin
+priv
@@ -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.
@@ -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.
@@ -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
Oops, something went wrong.

0 comments on commit 475111d

Please sign in to comment.