Skip to content
Browse files

Switched to using OpenSSL for SHA-1

  • Loading branch information...
1 parent d1bc0b4 commit b6556f342dda6234cffa6939defdb287b86d4742 @hintjens hintjens committed Nov 15, 2012
View
5 configure.in
@@ -13,8 +13,6 @@ AC_CONFIG_MACRO_DIR(config)
AM_CONFIG_HEADER(src/platform.h)
AM_INIT_AUTOMAKE(tar-ustar)
-AC_CONFIG_SUBDIRS([sha-1.1])
-
# This defines PACKAGE_VERSION_... in src/platform.h
PV_MAJOR=`echo $PACKAGE_VERSION | cut -d . -f 1`
PV_MINOR=`echo $PACKAGE_VERSION | cut -d . -f 2`
@@ -114,6 +112,9 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <czmq.h>],
[AC_MSG_RESULT([yes])],
[AC_MSG_ERROR([no. Please specify libczmq installation prefix using --with-czmq])])
+# Other libraries
+AC_CHECK_LIB(crypto, SHA1_Init, ,[AC_MSG_ERROR([cannot link with -lcrypto, install libssl-dev.])])
+
#Whether we are on mingw or not.
fmq_on_mingw32="no"
View
0 include/fmq_sha.h → include/fmq_hash.h
File renamed without changes.
View
7 sha-1.1/.gitignore
@@ -1,7 +0,0 @@
-.deps/
-config.h
-config.h.in~
-libsha.a
-sha
-shatest
-stamp-h1
View
38 sha-1.1/ChangeLog
@@ -1,38 +0,0 @@
-2011-04-10 Allan Saddi <allan@saddi.com>
-
- * Add HMAC-SHA-X support.
-
-2003-07-25 Allan Saddi <allan@saddi.com>
-
- * Minor tweaks to sha code to make more ANSI C compliant.
- Thanks to Paul Gilmartin for noticing the issue.
- * Add shatest program for portable testing of algorithm
- correctness.
- * Version 1.0.4 released.
-
-2002-09-13 Allan Saddi <allan@saddi.com>
-
- * Version 1.0.3 released.
-
-2002-09-11 Allan Saddi <allan@saddi.com>
-
- * Switch to autoconf 2.53/automake 1.5
- * Test for existence of inttypes.h and stdint.h. If neither are
- found, use sane defaults for the uintXX_t types.
- * Exit with non-zero status code if anything goes wrong.
-
-2001-08-19 Allan Saddi <allan@saddi.com>
-
- * Add man page.
- * Version 1.0.2 released.
-
-2001-08-12 Allan Saddi <allan@saddi.com>
-
- * Burn sensitive information from the stack.
- * Be sure to burn file buffer too.
- * Version 1.0.1 released.
-
-2001-07-14 Allan Saddi <allan@saddi.com>
-
- * Initial release.
-
View
21 sha-1.1/Makefile.am
@@ -1,21 +0,0 @@
-AUTOMAKE_OPTIONS = foreign
-AM_CFLAGS = -Wall
-
-lib_LIBRARIES = libsha.a
-libsha_a_SOURCES = sha.c sha1.c sha256.c sha384.c sha512.c \
- hmac-sha1.c hmac-sha256.c hmac-sha384.c hmac-sha512.c
-
-bin_PROGRAMS = sha
-noinst_PROGRAMS = shatest
-
-sha_SOURCES = sha.c sha1.c sha256.c sha384.c sha512.c \
- hmac-sha1.c hmac-sha256.c hmac-sha384.c hmac-sha512.c \
- sha1.h sha256.h sha384.h sha512.h \
- hmac-sha1.h hmac-sha256.h hmac-sha384.h hmac-sha512.h \
- version.h
-shatest_SOURCES = shatest.c sha1.c sha256.c sha384.c sha512.c \
- sha1.h sha256.h sha384.h sha512.h
-
-man_MANS = sha.1
-
-EXTRA_DIST = $(man_MANS) README.SHA
View
68 sha-1.1/README
@@ -1,68 +0,0 @@
-sha version 1.0.4 (2003-Jul-25)
-===============================
-Copyright (c) 2001-2003 Allan Saddi <allan@saddi.com>
-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.
-
-THIS SOFTWARE IS PROVIDED BY ALLAN SADDI AND HIS CONTRIBUTORS ``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 ALLAN SADDI OR HIS CONTRIBUTORS 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.
-
-Introduction
-------------
-sha is a simple program that hashes files. It uses the National
-Institute of Standards and Technology's Secure Hash Algorithm.
-It can use SHA-1, SHA-256, SHA-384, or SHA-512, which generate
-respectively, hashes of 160, 256, 384, or 512 bits. sha can be
-used in scripts to do, for example, file integrity checking.
-
-For more information on SHA (the algorithms), visit:
-http://csrc.nist.gov/encryption/tkhash.html
-
-To build sha, see INSTALL.
-
-Using sha is simple. Just pass the names of one or more files on
-the command line. By default, sha will use SHA-1 unless passed
-one of the following flags: -2 for SHA-256, -3 for SHA-384 or
--5 for SHA-512. Type "sha -h" for help.
-
-If no filenames are given, sha will hash stdin.
-
-If the environment variable SHA_DEFAULT is set, the default hashing
-algorithm can be changed. Only the first character of the value of
-SHA_DEFAULT is significant. It can be '1' for SHA-1, '2' for SHA-256,
-'3' for SHA-384, or '5' for SHA-512. With any other value, sha will
-use SHA-1 by default. Again, "sha -h" will display the default.
-
-You may want to perform a sanity check on sha before relying on it. A
-program called "shatest" is built along with sha (but not installed).
-If you run shatest, it will display the results of running the various
-SHA algorithms on a set of known test vectors. If the resultant hash
-matches what is expected, "PASS" will be displayed. Otherwise it will
-display "FAIL."
-
-Also, feel free to use my SHA implementations in your own projects.
-They are fast and relatively portable. Please see the top of each
-source file for copyright and warranty information. See README.SHA
-for technical notes.
-
-The latest version of sha can always be found at:
-http://philosophysw.com/
-
-- Allan Saddi <allan@saddi.com>
View
223 sha-1.1/README.SHA
@@ -1,223 +0,0 @@
-shaX-asaddi (X = 1, 256, 384, 512)
-==================================
-Copyright (c) 2001-2003 Allan Saddi <allan@saddi.com>
-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.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
-
-Introduction
-------------
-These are portable implementations of the National Institute of
-Standards and Technology's Secure Hash Algorithms. Implementations
-for SHA-1, SHA-256, SHA-384, and SHA-512 are available. All are
-equally portable, assuming your compiler supports 64-bit integers
-(which gcc does).
-
-For more information on SHA (the algorithms), visit:
-http://csrc.nist.gov/encryption/tkhash.html
-
-The following documentation and examples will refer to the SHA-1
-implementation. However, they equally apply to the SHA-256, SHA-384,
-and SHA-512 implementations except where noted.
-
-API
----
-SHA1_Context
- This is the hash context. There should be one SHA1_Context for each
- object to be hashed. (This only applies if hashing is being done
- in parallel. Otherwise, it's perfectly safe to reuse a SHA1_Context
- to hash objects serially, e.g. one file at a time.)
-
- A SHA1_Context can be declared static, automatic, or allocated from
- the heap. There are certain alignment restrictions, but it shouldn't
- be of any concern in normal usage (malloc() should return suitably
- aligned memory, and the compiler will take care of the other cases).
-
- There's nothing really special about a SHA1_Context. It should be
- safe to copy it, e.g. using memcpy() or bcopy().
-
-void SHA1_Init (SHA1_Context *sc);
- Initializes a SHA1_Context. This should be called before any of the
- following functions are called.
-
-void SHA1_Update (SHA1_Context *sc, const void *data, uint32_t len);
- Hashes some data. len is in bytes.
-
-void SHA1_Final (SHA1_Context *sc, uint8_t hash[SHA1_HASH_SIZE]);
- Gets the SHA-1 hash and "closes" the context. The context should
- no longer be used. (Due to padding, etc.) If you wish to hash a
- new set of data using the same SHA1_Context, be sure to call
- SHA1_Init(). If you want to continue hashing data using the
- same context, simply make a copy of the context and call
- SHA1_Final() on the copy.
-
- hash may be NULL, in which case no hash is generated (but the
- context is still closed). Regardless if hash is NULL or not, a
- word representation of the hash (32-bit words for SHA-1 and SHA-256,
- 64-bit words for SHA-384 and SHA-512) is available in
- sc->hash[0..SHA1_HASH_WORDS-1]. This may be useful in other
- applications.
-
- If being used for cryptography, it's probably a good idea to zero-out
- the SHA1_Context after you're done.
-
-Compile-Time Options
---------------------
-HAVE_CONFIG_H
- Define this if you want the code to include <config.h>. This is useful
- if you use GNU configure.
-
-HAVE_INTTYPES_H
-HAVE_STDINT_H
- Define one of these to 1 if you have the respective header file. If you
- have neither, be sure to typedef/define uint8_t, uint32_t, and uint64_t
- appropriately (perhaps in config.h above).
-
-WORDS_BIGENDIAN
- Define this if you're on a big-endian processor.
-
-RUNTIME_ENDIAN
- Define this if you would rather determine processor endianess at
- runtime. WORDS_BIGENDIAN will be ignored if this is defined. The
- generated code may be slightly slower, but at least you won't
- have to worry about big-endian vs. little-endian!
-
-SHA1_FAST_COPY
- Defining this will eliminate some copying overhead of hashed data.
- Also, calculating the hash in SHA1_Final() should be slightly faster.
- This isn't on by default because of alignment issues. See Portability
- Notes.
-
-SHA1_UNROLL
- If undefined, it will default to 1. This is the number of rounds
- to perform in a loop iteration. The larger the number, the bigger
- the code, but also the less loop overhead there will be. It must
- be between 1 and 20 inclusive, and it must be a factor of 20 or
- a product of some of its factors. (Don't worry, you'll get a nice
- error message if you defined it wrong.)
-
- SHA-256 is the only other implementation that has something
- similar (SHA256_UNROLL). It must be a power of 2 between 1 and
- 64 inclusive and it defaults to 1.
-
- You may want to experiment with different values. I've generally
- found that big code is slower, despite being more efficient. This
- is most likely due to cache space limitations.
-
-SHA1_TEST
- Define this to compile a simple test program. See the comments in
- sha1.c for what the output should look like. If the output doesn't
- look right, try flipping WORDS_BIGENDIAN (define it if you didn't
- define it, undefine it if you did). For example:
-
- > gcc -Wall -O2 -DSHA1_TEST -o test sha1.c
-
-Portability Notes
------------------
-As was mentioned, you need a compiler that supports 64-bit integers.
-You will also need <inttypes.h> for uint8_t, uint32_t, uint64_t. I'm not
-sure how common or standard this include file is, but it was available
-on all platforms I tested.
-
-It was actually surprising to find that all but one of the processors
-tested supported unaligned word accesses. (I came from a MC680x0 +
-MIPS background.) I developed the code on i386 and powerpc architectures,
-which both supported unaligned words. It wasn't until I tried out my
-code on a sparc that I realized I needed to be a little more careful.
-(Bus errors... yum!)
-
-With SHA1_FAST_COPY undefined, the code should be very portable. If you
-define it, the code may be slightly faster, but there are a few things
-you need to be careful about, especially on architectures that don't
-support unaligned word accesses. Here are some general guidelines:
-
-Use SHA1_FAST_COPY if:
-
- * You call SHA1_Update() with a consistent buffer size every time.
- (The last time you call it before calling SHA1_Final() can be the
- exception.) And:
-
- * The buffer size is a multiple of 64-bytes (SHA-1, SHA-256) or
- 128-bytes (SHA-384, SHA-512). And:
-
- * The buffer address is evenly divisible by 4 (SHA-1, SHA-256) or
- evenly divisible by 8 (SHA-384, SHA-512). And finally:
-
- * The hash address passed to SHA1_Final() is evenly divisible by
- 4 (SHA-1, SHA-256) or evenly divisible by 8 (SHA-384, SHA-512).
-
-You can ensure proper address alignment by using malloc() (read your
-man page to verify this) or by doing something like:
-
- union {
- uint32_t w; /* use uint64_t for SHA-384, SHA-512 */
- uint8_t b[SHA1_HASH_SIZE];
- } hash;
- ...
- SHA1_Final (&sha, hash.b);
-
-If you're on an architecture that supports unaligned word accesses,
-it may be safe to define SHA1_FAST_COPY anyway. However, it would be
-a good idea to experiment, since unaligned word accesses may actually
-take longer and cancel the benefits of faster code.
-
-Example
--------
- #include <inttypes.h> /* for uint8_t, etc. */
- #include <string.h> /* for memset() */
-
- #include "sha1.h"
-
- ...
- SHA1_Context sha;
- uint8_t hash[SHA1_HASH_SIZE];
- ...
- SHA1_Init (&sha);
- ...
- SHA1_Update (&sha, buffer, length);
- ...
- SHA1_Update (&sha, buffer2, length2);
- ...
- call SHA1_Update() with more data
- ...
- SHA1_Final (&sha, hash);
- memset (&sha, 0, sizeof (sha)); /* for the truly paranoid */
- ...
- do something with hash
- ...
-
-Platforms Tested
-----------------
-gcc was the compiler used on all tested platforms.
-
-FreeBSD i386
-Darwin powerpc
-Linux i386
-Linux alpha
-Linux powerpc
-Solaris sparc
-
-Comments? Suggestions? Bugs?
-----------------------------
-Please let me know!
-
-- Allan Saddi <allan@saddi.com>
View
94 sha-1.1/config.h.in
@@ -1,94 +0,0 @@
-/* config.h.in. Generated from configure.in by autoheader. */
-
-/* Define if building universal (internal helper macro) */
-#undef AC_APPLE_UNIVERSAL_BUILD
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the `strerror' function. */
-#undef HAVE_STRERROR
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the home page for this package. */
-#undef PACKAGE_URL
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* Version number of package */
-#undef VERSION
-
-/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
- significant byte first (like Motorola and SPARC, unlike Intel). */
-#if defined AC_APPLE_UNIVERSAL_BUILD
-# if defined __BIG_ENDIAN__
-# define WORDS_BIGENDIAN 1
-# endif
-#else
-# ifndef WORDS_BIGENDIAN
-# undef WORDS_BIGENDIAN
-# endif
-#endif
-
-/* Define to empty if `const' does not conform to ANSI C. */
-#undef const
-
-/* Define to `__inline__' or `__inline' if that's what the C compiler
- calls it, or to nothing if 'inline' is not supported under any name. */
-#ifndef __cplusplus
-#undef inline
-#endif
-
-/* Define to `unsigned int' if <sys/types.h> does not define. */
-#undef size_t
-
-/* Define to `unsigned int' if not defined. */
-#undef uint32_t
-
-/* Define to `unsigned long long' if not defined. */
-#undef uint64_t
-
-/* Define to `unsigned char' if not defined. */
-#undef uint8_t
View
0 sha-1.1/config/dontdelete
No changes.
View
33 sha-1.1/configure.in
@@ -1,33 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT(sha.c)
-AM_INIT_AUTOMAKE(sha, 1.1)
-AM_CONFIG_HEADER(config.h)
-
-dnl Checks for programs.
-AC_PROG_CC
-AC_PROG_RANLIB
-
-dnl Checks for libraries.
-
-dnl Checks for header files.
-AC_HEADER_STDC
-
-dnl Checks for typedefs, structures, and compiler characteristics.
-AC_C_BIGENDIAN
-AC_C_CONST
-AC_C_INLINE
-AC_TYPE_SIZE_T
-AC_CHECK_TYPE([uint8_t],,
-[AC_DEFINE([uint8_t], [unsigned char],
-[Define to `unsigned char' if not defined.])])
-AC_CHECK_TYPE([uint32_t],,
-[AC_DEFINE([uint32_t], [unsigned int],
-[Define to `unsigned int' if not defined.])])
-AC_CHECK_TYPE([uint64_t],,
-[AC_DEFINE([uint64_t], [unsigned long long],
-[Define to `unsigned long long' if not defined.])])
-
-dnl Checks for library functions.
-AC_CHECK_FUNCS(strerror)
-
-AC_OUTPUT(Makefile)
View
688 sha-1.1/depcomp
@@ -1,688 +0,0 @@
-#! /bin/sh
-# depcomp - compile a program generating dependencies as side-effects
-
-scriptversion=2011-12-04.11; # UTC
-
-# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
-# 2011 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
-
-case $1 in
- '')
- echo "$0: No command. Try \`$0 --help' for more information." 1>&2
- exit 1;
- ;;
- -h | --h*)
- cat <<\EOF
-Usage: depcomp [--help] [--version] PROGRAM [ARGS]
-
-Run PROGRAMS ARGS to compile a file, generating dependencies
-as side-effects.
-
-Environment variables:
- depmode Dependency tracking mode.
- source Source file read by `PROGRAMS ARGS'.
- object Object file output by `PROGRAMS ARGS'.
- DEPDIR directory where to store dependencies.
- depfile Dependency file to output.
- tmpdepfile Temporary file to use when outputting dependencies.
- libtool Whether libtool is used (yes/no).
-
-Report bugs to <bug-automake@gnu.org>.
-EOF
- exit $?
- ;;
- -v | --v*)
- echo "depcomp $scriptversion"
- exit $?
- ;;
-esac
-
-if test -z "$depmode" || test -z "$source" || test -z "$object"; then
- echo "depcomp: Variables source, object and depmode must be set" 1>&2
- exit 1
-fi
-
-# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
-depfile=${depfile-`echo "$object" |
- sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
-tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
-
-rm -f "$tmpdepfile"
-
-# Some modes work just like other modes, but use different flags. We
-# parameterize here, but still list the modes in the big case below,
-# to make depend.m4 easier to write. Note that we *cannot* use a case
-# here, because this file can only contain one case statement.
-if test "$depmode" = hp; then
- # HP compiler uses -M and no extra arg.
- gccflag=-M
- depmode=gcc
-fi
-
-if test "$depmode" = dashXmstdout; then
- # This is just like dashmstdout with a different argument.
- dashmflag=-xM
- depmode=dashmstdout
-fi
-
-cygpath_u="cygpath -u -f -"
-if test "$depmode" = msvcmsys; then
- # This is just like msvisualcpp but w/o cygpath translation.
- # Just convert the backslash-escaped backslashes to single forward
- # slashes to satisfy depend.m4
- cygpath_u='sed s,\\\\,/,g'
- depmode=msvisualcpp
-fi
-
-if test "$depmode" = msvc7msys; then
- # This is just like msvc7 but w/o cygpath translation.
- # Just convert the backslash-escaped backslashes to single forward
- # slashes to satisfy depend.m4
- cygpath_u='sed s,\\\\,/,g'
- depmode=msvc7
-fi
-
-case "$depmode" in
-gcc3)
-## gcc 3 implements dependency tracking that does exactly what
-## we want. Yay! Note: for some reason libtool 1.4 doesn't like
-## it if -MD -MP comes after the -MF stuff. Hmm.
-## Unfortunately, FreeBSD c89 acceptance of flags depends upon
-## the command line argument order; so add the flags where they
-## appear in depend2.am. Note that the slowdown incurred here
-## affects only configure: in makefiles, %FASTDEP% shortcuts this.
- for arg
- do
- case $arg in
- -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
- *) set fnord "$@" "$arg" ;;
- esac
- shift # fnord
- shift # $arg
- done
- "$@"
- stat=$?
- if test $stat -eq 0; then :
- else
- rm -f "$tmpdepfile"
- exit $stat
- fi
- mv "$tmpdepfile" "$depfile"
- ;;
-
-gcc)
-## There are various ways to get dependency output from gcc. Here's
-## why we pick this rather obscure method:
-## - Don't want to use -MD because we'd like the dependencies to end
-## up in a subdir. Having to rename by hand is ugly.
-## (We might end up doing this anyway to support other compilers.)
-## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
-## -MM, not -M (despite what the docs say).
-## - Using -M directly means running the compiler twice (even worse
-## than renaming).
- if test -z "$gccflag"; then
- gccflag=-MD,
- fi
- "$@" -Wp,"$gccflag$tmpdepfile"
- stat=$?
- if test $stat -eq 0; then :
- else
- rm -f "$tmpdepfile"
- exit $stat
- fi
- rm -f "$depfile"
- echo "$object : \\" > "$depfile"
- alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
-## The second -e expression handles DOS-style file names with drive letters.
- sed -e 's/^[^:]*: / /' \
- -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
-## This next piece of magic avoids the `deleted header file' problem.
-## The problem is that when a header file which appears in a .P file
-## is deleted, the dependency causes make to die (because there is
-## typically no way to rebuild the header). We avoid this by adding
-## dummy dependencies for each header file. Too bad gcc doesn't do
-## this for us directly.
- tr ' ' '
-' < "$tmpdepfile" |
-## Some versions of gcc put a space before the `:'. On the theory
-## that the space means something, we add a space to the output as
-## well. hp depmode also adds that space, but also prefixes the VPATH
-## to the object. Take care to not repeat it in the output.
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly. Breaking it into two sed invocations is a workaround.
- sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
- | sed -e 's/$/ :/' >> "$depfile"
- rm -f "$tmpdepfile"
- ;;
-
-hp)
- # This case exists only to let depend.m4 do its work. It works by
- # looking at the text of this script. This case will never be run,
- # since it is checked for above.
- exit 1
- ;;
-
-sgi)
- if test "$libtool" = yes; then
- "$@" "-Wp,-MDupdate,$tmpdepfile"
- else
- "$@" -MDupdate "$tmpdepfile"
- fi
- stat=$?
- if test $stat -eq 0; then :
- else
- rm -f "$tmpdepfile"
- exit $stat
- fi
- rm -f "$depfile"
-
- if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
- echo "$object : \\" > "$depfile"
-
- # Clip off the initial element (the dependent). Don't try to be
- # clever and replace this with sed code, as IRIX sed won't handle
- # lines with more than a fixed number of characters (4096 in
- # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
- # the IRIX cc adds comments like `#:fec' to the end of the
- # dependency line.
- tr ' ' '
-' < "$tmpdepfile" \
- | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
- tr '
-' ' ' >> "$depfile"
- echo >> "$depfile"
-
- # The second pass generates a dummy entry for each header file.
- tr ' ' '
-' < "$tmpdepfile" \
- | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
- >> "$depfile"
- else
- # The sourcefile does not contain any dependencies, so just
- # store a dummy comment line, to avoid errors with the Makefile
- # "include basename.Plo" scheme.
- echo "#dummy" > "$depfile"
- fi
- rm -f "$tmpdepfile"
- ;;
-
-aix)
- # The C for AIX Compiler uses -M and outputs the dependencies
- # in a .u file. In older versions, this file always lives in the
- # current directory. Also, the AIX compiler puts `$object:' at the
- # start of each line; $object doesn't have directory information.
- # Version 6 uses the directory in both cases.
- dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
- test "x$dir" = "x$object" && dir=
- base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
- if test "$libtool" = yes; then
- tmpdepfile1=$dir$base.u
- tmpdepfile2=$base.u
- tmpdepfile3=$dir.libs/$base.u
- "$@" -Wc,-M
- else
- tmpdepfile1=$dir$base.u
- tmpdepfile2=$dir$base.u
- tmpdepfile3=$dir$base.u
- "$@" -M
- fi
- stat=$?
-
- if test $stat -eq 0; then :
- else
- rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
- exit $stat
- fi
-
- for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
- do
- test -f "$tmpdepfile" && break
- done
- if test -f "$tmpdepfile"; then
- # Each line is of the form `foo.o: dependent.h'.
- # Do two passes, one to just change these to
- # `$object: dependent.h' and one to simply `dependent.h:'.
- sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
- # That's a tab and a space in the [].
- sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
- else
- # The sourcefile does not contain any dependencies, so just
- # store a dummy comment line, to avoid errors with the Makefile
- # "include basename.Plo" scheme.
- echo "#dummy" > "$depfile"
- fi
- rm -f "$tmpdepfile"
- ;;
-
-icc)
- # Intel's C compiler understands `-MD -MF file'. However on
- # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
- # ICC 7.0 will fill foo.d with something like
- # foo.o: sub/foo.c
- # foo.o: sub/foo.h
- # which is wrong. We want:
- # sub/foo.o: sub/foo.c
- # sub/foo.o: sub/foo.h
- # sub/foo.c:
- # sub/foo.h:
- # ICC 7.1 will output
- # foo.o: sub/foo.c sub/foo.h
- # and will wrap long lines using \ :
- # foo.o: sub/foo.c ... \
- # sub/foo.h ... \
- # ...
-
- "$@" -MD -MF "$tmpdepfile"
- stat=$?
- if test $stat -eq 0; then :
- else
- rm -f "$tmpdepfile"
- exit $stat
- fi
- rm -f "$depfile"
- # Each line is of the form `foo.o: dependent.h',
- # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
- # Do two passes, one to just change these to
- # `$object: dependent.h' and one to simply `dependent.h:'.
- sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
- # Some versions of the HPUX 10.20 sed can't process this invocation
- # correctly. Breaking it into two sed invocations is a workaround.
- sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
- sed -e 's/$/ :/' >> "$depfile"
- rm -f "$tmpdepfile"
- ;;
-
-hp2)
- # The "hp" stanza above does not work with aCC (C++) and HP's ia64
- # compilers, which have integrated preprocessors. The correct option
- # to use with these is +Maked; it writes dependencies to a file named
- # 'foo.d', which lands next to the object file, wherever that
- # happens to be.
- # Much of this is similar to the tru64 case; see comments there.
- dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
- test "x$dir" = "x$object" && dir=
- base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
- if test "$libtool" = yes; then
- tmpdepfile1=$dir$base.d
- tmpdepfile2=$dir.libs/$base.d
- "$@" -Wc,+Maked
- else
- tmpdepfile1=$dir$base.d
- tmpdepfile2=$dir$base.d
- "$@" +Maked
- fi
- stat=$?
- if test $stat -eq 0; then :
- else
- rm -f "$tmpdepfile1" "$tmpdepfile2"
- exit $stat
- fi
-
- for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
- do
- test -f "$tmpdepfile" && break
- done
- if test -f "$tmpdepfile"; then
- sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
- # Add `dependent.h:' lines.
- sed -ne '2,${
- s/^ *//
- s/ \\*$//
- s/$/:/
- p
- }' "$tmpdepfile" >> "$depfile"
- else
- echo "#dummy" > "$depfile"
- fi
- rm -f "$tmpdepfile" "$tmpdepfile2"
- ;;
-
-tru64)
- # The Tru64 compiler uses -MD to generate dependencies as a side
- # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
- # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
- # dependencies in `foo.d' instead, so we check for that too.
- # Subdirectories are respected.
- dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
- test "x$dir" = "x$object" && dir=
- base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
-
- if test "$libtool" = yes; then
- # With Tru64 cc, shared objects can also be used to make a
- # static library. This mechanism is used in libtool 1.4 series to
- # handle both shared and static libraries in a single compilation.
- # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
- #
- # With libtool 1.5 this exception was removed, and libtool now
- # generates 2 separate objects for the 2 libraries. These two
- # compilations output dependencies in $dir.libs/$base.o.d and
- # in $dir$base.o.d. We have to check for both files, because
- # one of the two compilations can be disabled. We should prefer
- # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
- # automatically cleaned when .libs/ is deleted, while ignoring
- # the former would cause a distcleancheck panic.
- tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
- tmpdepfile2=$dir$base.o.d # libtool 1.5
- tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
- tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
- "$@" -Wc,-MD
- else
- tmpdepfile1=$dir$base.o.d
- tmpdepfile2=$dir$base.d
- tmpdepfile3=$dir$base.d
- tmpdepfile4=$dir$base.d
- "$@" -MD
- fi
-
- stat=$?
- if test $stat -eq 0; then :
- else
- rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
- exit $stat
- fi
-
- for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
- do
- test -f "$tmpdepfile" && break
- done
- if test -f "$tmpdepfile"; then
- sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
- # That's a tab and a space in the [].
- sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
- else
- echo "#dummy" > "$depfile"
- fi
- rm -f "$tmpdepfile"
- ;;
-
-msvc7)
- if test "$libtool" = yes; then
- showIncludes=-Wc,-showIncludes
- else
- showIncludes=-showIncludes
- fi
- "$@" $showIncludes > "$tmpdepfile"
- stat=$?
- grep -v '^Note: including file: ' "$tmpdepfile"
- if test "$stat" = 0; then :
- else
- rm -f "$tmpdepfile"
- exit $stat
- fi
- rm -f "$depfile"
- echo "$object : \\" > "$depfile"
- # The first sed program below extracts the file names and escapes
- # backslashes for cygpath. The second sed program outputs the file
- # name when reading, but also accumulates all include files in the
- # hold buffer in order to output them again at the end. This only
- # works with sed implementations that can handle large buffers.
- sed < "$tmpdepfile" -n '
-/^Note: including file: *\(.*\)/ {
- s//\1/
- s/\\/\\\\/g
- p
-}' | $cygpath_u | sort -u | sed -n '
-s/ /\\ /g
-s/\(.*\)/ \1 \\/p
-s/.\(.*\) \\/\1:/
-H
-$ {
- s/.*/ /
- G
- p
-}' >> "$depfile"
- rm -f "$tmpdepfile"
- ;;
-
-msvc7msys)
- # This case exists only to let depend.m4 do its work. It works by
- # looking at the text of this script. This case will never be run,
- # since it is checked for above.
- exit 1
- ;;
-
-#nosideeffect)
- # This comment above is used by automake to tell side-effect
- # dependency tracking mechanisms from slower ones.
-
-dashmstdout)
- # Important note: in order to support this mode, a compiler *must*
- # always write the preprocessed file to stdout, regardless of -o.
- "$@" || exit $?
-
- # Remove the call to Libtool.
- if test "$libtool" = yes; then
- while test "X$1" != 'X--mode=compile'; do
- shift
- done
- shift
- fi
-
- # Remove `-o $object'.
- IFS=" "
- for arg
- do
- case $arg in
- -o)
- shift
- ;;
- $object)
- shift
- ;;
- *)
- set fnord "$@" "$arg"
- shift # fnord
- shift # $arg
- ;;
- esac
- done
-
- test -z "$dashmflag" && dashmflag=-M
- # Require at least two characters before searching for `:'
- # in the target name. This is to cope with DOS-style filenames:
- # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
- "$@" $dashmflag |
- sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
- rm -f "$depfile"
- cat < "$tmpdepfile" > "$depfile"
- tr ' ' '
-' < "$tmpdepfile" | \
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly. Breaking it into two sed invocations is a workaround.
- sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
- rm -f "$tmpdepfile"
- ;;
-
-dashXmstdout)
- # This case only exists to satisfy depend.m4. It is never actually
- # run, as this mode is specially recognized in the preamble.
- exit 1
- ;;
-
-makedepend)
- "$@" || exit $?
- # Remove any Libtool call
- if test "$libtool" = yes; then
- while test "X$1" != 'X--mode=compile'; do
- shift
- done
- shift
- fi
- # X makedepend
- shift
- cleared=no eat=no
- for arg
- do
- case $cleared in
- no)
- set ""; shift
- cleared=yes ;;
- esac
- if test $eat = yes; then
- eat=no
- continue
- fi
- case "$arg" in
- -D*|-I*)
- set fnord "$@" "$arg"; shift ;;
- # Strip any option that makedepend may not understand. Remove
- # the object too, otherwise makedepend will parse it as a source file.
- -arch)
- eat=yes ;;
- -*|$object)
- ;;
- *)
- set fnord "$@" "$arg"; shift ;;
- esac
- done
- obj_suffix=`echo "$object" | sed 's/^.*\././'`
- touch "$tmpdepfile"
- ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
- rm -f "$depfile"
- # makedepend may prepend the VPATH from the source file name to the object.
- # No need to regex-escape $object, excess matching of '.' is harmless.
- sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
- sed '1,2d' "$tmpdepfile" | tr ' ' '
-' | \
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly. Breaking it into two sed invocations is a workaround.
- sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
- rm -f "$tmpdepfile" "$tmpdepfile".bak
- ;;
-
-cpp)
- # Important note: in order to support this mode, a compiler *must*
- # always write the preprocessed file to stdout.
- "$@" || exit $?
-
- # Remove the call to Libtool.
- if test "$libtool" = yes; then
- while test "X$1" != 'X--mode=compile'; do
- shift
- done
- shift
- fi
-
- # Remove `-o $object'.
- IFS=" "
- for arg
- do
- case $arg in
- -o)
- shift
- ;;
- $object)
- shift
- ;;
- *)
- set fnord "$@" "$arg"
- shift # fnord
- shift # $arg
- ;;
- esac
- done
-
- "$@" -E |
- sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
- -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
- sed '$ s: \\$::' > "$tmpdepfile"
- rm -f "$depfile"
- echo "$object : \\" > "$depfile"
- cat < "$tmpdepfile" >> "$depfile"
- sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
- rm -f "$tmpdepfile"
- ;;
-
-msvisualcpp)
- # Important note: in order to support this mode, a compiler *must*
- # always write the preprocessed file to stdout.
- "$@" || exit $?
-
- # Remove the call to Libtool.
- if test "$libtool" = yes; then
- while test "X$1" != 'X--mode=compile'; do
- shift
- done
- shift
- fi
-
- IFS=" "
- for arg
- do
- case "$arg" in
- -o)
- shift
- ;;
- $object)
- shift
- ;;
- "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
- set fnord "$@"
- shift
- shift
- ;;
- *)
- set fnord "$@" "$arg"
- shift
- shift
- ;;
- esac
- done
- "$@" -E 2>/dev/null |
- sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
- rm -f "$depfile"
- echo "$object : \\" > "$depfile"
- sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
- echo " " >> "$depfile"
- sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
- rm -f "$tmpdepfile"
- ;;
-
-msvcmsys)
- # This case exists only to let depend.m4 do its work. It works by
- # looking at the text of this script. This case will never be run,
- # since it is checked for above.
- exit 1
- ;;
-
-none)
- exec "$@"
- ;;
-
-*)
- echo "Unknown depmode $depmode" 1>&2
- exit 1
- ;;
-esac
-
-exit 0
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 2
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
-# time-stamp-end: "; # UTC"
-# End:
View
158 sha-1.1/hmac-sha1.c
@@ -1,158 +0,0 @@
-/*-
- * Copyright (c) 2010 Allan Saddi <allan@saddi.com>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
- *
- * $Id$
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#else
-# if HAVE_STDINT_H
-# include <stdint.h>
-# endif
-#endif
-#include <string.h>
-
-#include "hmac-sha1.h"
-
-#define HASH_BLOCK_SIZE 64
-
-void
-HMAC_SHA1_Init(HMAC_SHA1_Context *ctxt, void *key, uint32_t keyLen)
-{
- SHA1_Context keyCtxt;
- int i;
- uint8_t pkey[HASH_BLOCK_SIZE], okey[HASH_BLOCK_SIZE], ikey[HASH_BLOCK_SIZE];
-
- /* Ensure key is zero-padded */
- memset(pkey, 0, sizeof(pkey));
-
- if (keyLen > sizeof(pkey)) {
- /* Hash key if > HASH_BLOCK_SIZE */
- SHA1_Init(&keyCtxt);
- SHA1_Update(&keyCtxt, key, keyLen);
- SHA1_Final(&keyCtxt, pkey);
- }
- else {
- memcpy(pkey, key, keyLen);
- }
-
- /* XOR with opad, ipad */
- for (i = 0; i < sizeof(okey); i++) {
- okey[i] = pkey[i] ^ 0x5c;
- }
- for (i = 0; i < sizeof(ikey); i++) {
- ikey[i] = pkey[i] ^ 0x36;
- }
-
- /* Initialize hash contexts */
- SHA1_Init(&ctxt->outer);
- SHA1_Update(&ctxt->outer, okey, sizeof(okey));
- SHA1_Init(&ctxt->inner);
- SHA1_Update(&ctxt->inner, ikey, sizeof(ikey));
-
- /* Burn the stack */
- memset(ikey, 0, sizeof(ikey));
- memset(okey, 0, sizeof(okey));
- memset(pkey, 0, sizeof(pkey));
- memset(&keyCtxt, 0, sizeof(keyCtxt));
-}
-
-void
-HMAC_SHA1_Update(HMAC_SHA1_Context *ctxt, void *data, uint32_t len)
-{
- SHA1_Update(&ctxt->inner, data, len);
-}
-
-void
-HMAC_SHA1_Final(HMAC_SHA1_Context *ctxt, uint8_t hmac[SHA1_HASH_SIZE])
-{
- uint8_t ihash[SHA1_HASH_SIZE];
-
- SHA1_Final(&ctxt->inner, ihash);
- SHA1_Update(&ctxt->outer, ihash, sizeof(ihash));
- SHA1_Final(&ctxt->outer, hmac);
-
- memset(ihash, 0, sizeof(ihash));
-}
-
-#ifdef HMAC_SHA1_TEST
-#include <stdlib.h>
-#include <stdio.h>
-
-static void
-print_hmac(uint8_t hmac[SHA1_HASH_SIZE])
-{
- int i;
-
- for (i = 0; i < SHA1_HASH_SIZE;) {
- printf("%02x", hmac[i++]);
- if (!(i % 4)) printf(" ");
- }
- printf("\n");
-}
-
-int
-main(int argc, char *argv[])
-{
- uint8_t key1[16];
- char *key2 = "Jefe";
- char *testdata1 = "Hi There";
- char *testdata2 = "what do ya want for nothing?";
- uint8_t testdata3[50];
- HMAC_SHA1_Context ctxt;
- uint8_t hmac[SHA1_HASH_SIZE];
-
- memset(key1, 0x0b, sizeof(key1));
- HMAC_SHA1_Init(&ctxt, key1, sizeof(key1));
- HMAC_SHA1_Update(&ctxt, testdata1, strlen(testdata1));
- HMAC_SHA1_Final(&ctxt, hmac);
-
- /* Expecting: 675b0b3a 1b4ddf4e 124872da 6c2f632b fed957e9 */
- print_hmac(hmac);
-
- HMAC_SHA1_Init(&ctxt, key2, strlen(key2));
- HMAC_SHA1_Update(&ctxt, testdata2, strlen(testdata2));
- HMAC_SHA1_Final(&ctxt, hmac);
-
- /* Expecting: effcdf6a e5eb2fa2 d27416d5 f184df9c 259a7c79 */
- print_hmac(hmac);
-
- memset(key1, 0xaa, sizeof(key1));
- memset(testdata3, 0xdd, sizeof(testdata3));
- HMAC_SHA1_Init(&ctxt, key1, sizeof(key1));
- HMAC_SHA1_Update(&ctxt, testdata3, sizeof(testdata3));
- HMAC_SHA1_Final(&ctxt, hmac);
-
- /* Expecting: d730594d 167e35d5 956fd800 3d0db3d3 f46dc7bb */
- print_hmac(hmac);
-
- return 0;
-}
-#endif /* HMAC_SHA1_TEST */
View
43 sha-1.1/hmac-sha1.h
@@ -1,43 +0,0 @@
-/*-
- * Copyright (c) 2010 Allan Saddi <allan@saddi.com>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
- *
- * $Id$
- */
-
-#ifndef _APS_HMAC_SHA1_H
-#define _APS_HMAC_SHA1_H
-
-#include "sha1.h"
-
-typedef struct {
- SHA1_Context outer;
- SHA1_Context inner;
-} HMAC_SHA1_Context;
-
-void HMAC_SHA1_Init(HMAC_SHA1_Context *ctxt, void *key, uint32_t keyLen);
-void HMAC_SHA1_Update(HMAC_SHA1_Context *ctxt, void *data, uint32_t len);
-void HMAC_SHA1_Final(HMAC_SHA1_Context *ctxt, uint8_t hmac[SHA1_HASH_SIZE]);
-
-#endif /* !_APS_HMAC_SHA1_H */
View
164 sha-1.1/hmac-sha256.c
@@ -1,164 +0,0 @@
-/*-
- * Copyright (c) 2010, 2011 Allan Saddi <allan@saddi.com>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
- *
- * $Id$
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#else
-# if HAVE_STDINT_H
-# include <stdint.h>
-# endif
-#endif
-#include <string.h>
-
-#include "hmac-sha256.h"
-
-#define HASH_BLOCK_SIZE 64
-
-void
-HMAC_SHA256_Init(HMAC_SHA256_Context *ctxt, void *key, uint32_t keyLen)
-{
- SHA256_Context keyCtxt;
- int i;
- uint8_t pkey[HASH_BLOCK_SIZE], okey[HASH_BLOCK_SIZE], ikey[HASH_BLOCK_SIZE];
-
- /* Ensure key is zero-padded */
- memset(pkey, 0, sizeof(pkey));
-
- if (keyLen > sizeof(pkey)) {
- /* Hash key if > HASH_BLOCK_SIZE */
- SHA256_Init(&keyCtxt);
- SHA256_Update(&keyCtxt, key, keyLen);
- SHA256_Final(&keyCtxt, pkey);
- }
- else {
- memcpy(pkey, key, keyLen);
- }
-
- /* XOR with opad, ipad */
- for (i = 0; i < sizeof(okey); i++) {
- okey[i] = pkey[i] ^ 0x5c;
- }
- for (i = 0; i < sizeof(ikey); i++) {
- ikey[i] = pkey[i] ^ 0x36;
- }
-
- /* Initialize hash contexts */
- SHA256_Init(&ctxt->outer);
- SHA256_Update(&ctxt->outer, okey, sizeof(okey));
- SHA256_Init(&ctxt->inner);
- SHA256_Update(&ctxt->inner, ikey, sizeof(ikey));
-
- /* Burn the stack */
- memset(ikey, 0, sizeof(ikey));
- memset(okey, 0, sizeof(okey));
- memset(pkey, 0, sizeof(pkey));
- memset(&keyCtxt, 0, sizeof(keyCtxt));
-}
-
-void
-HMAC_SHA256_Update(HMAC_SHA256_Context *ctxt, void *data, uint32_t len)
-{
- SHA256_Update(&ctxt->inner, data, len);
-}
-
-void
-HMAC_SHA256_Final(HMAC_SHA256_Context *ctxt, uint8_t hmac[SHA256_HASH_SIZE])
-{
- uint8_t ihash[SHA256_HASH_SIZE];
-
- SHA256_Final(&ctxt->inner, ihash);
- SHA256_Update(&ctxt->outer, ihash, sizeof(ihash));
- SHA256_Final(&ctxt->outer, hmac);
-
- memset(ihash, 0, sizeof(ihash));
-}
-
-#ifdef HMAC_SHA256_TEST
-#include <stdlib.h>
-#include <stdio.h>
-
-static void
-print_hmac(uint8_t hmac[SHA256_HASH_SIZE])
-{
- int i;
-
- for (i = 0; i < SHA256_HASH_SIZE;) {
- printf("%02x", hmac[i++]);
- if (!(i % 4)) printf(" ");
- }
- printf("\n");
-}
-
-int
-main(int argc, char *argv[])
-{
- uint8_t key1[16];
- char *key2 = "Jefe";
- char *testdata1 = "Hi There";
- char *testdata2 = "what do ya want for nothing?";
- uint8_t testdata3[50];
- HMAC_SHA256_Context ctxt;
- uint8_t hmac[SHA256_HASH_SIZE];
-
- memset(key1, 0x0b, sizeof(key1));
- HMAC_SHA256_Init(&ctxt, key1, sizeof(key1));
- HMAC_SHA256_Update(&ctxt, testdata1, strlen(testdata1));
- HMAC_SHA256_Final(&ctxt, hmac);
-
- /* Expecting:
- * 492ce020 fe2534a5 789dc384 8806c78f 4f671139 7f08e7e7 a12ca5a4 483c8aa6
- */
- print_hmac(hmac);
-
- HMAC_SHA256_Init(&ctxt, key2, strlen(key2));
- HMAC_SHA256_Update(&ctxt, testdata2, strlen(testdata2));
- HMAC_SHA256_Final(&ctxt, hmac);
-
- /* Expecting:
- * 5bdcc146 bf60754e 6a042426 089575c7 5a003f08 9d273983 9dec58b9 64ec3843
- */
- print_hmac(hmac);
-
- memset(key1, 0xaa, sizeof(key1));
- memset(testdata3, 0xdd, sizeof(testdata3));
- HMAC_SHA256_Init(&ctxt, key1, sizeof(key1));
- HMAC_SHA256_Update(&ctxt, testdata3, sizeof(testdata3));
- HMAC_SHA256_Final(&ctxt, hmac);
-
- /* Expecting:
- * 7dda3cc1 69743a64 84649f94 f0eda0f9 f2ff496a 9733fb79 6ed5adb4 0a44c3c1
- */
- print_hmac(hmac);
-
- return 0;
-}
-#endif /* HMAC_SHA256_TEST */
View
43 sha-1.1/hmac-sha256.h
@@ -1,43 +0,0 @@
-/*-
- * Copyright (c) 2010, 2011 Allan Saddi <allan@saddi.com>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
- *
- * $Id$
- */
-
-#ifndef _APS_HMAC_SHA256_H
-#define _APS_HMAC_SHA256_H
-
-#include "sha256.h"
-
-typedef struct {
- SHA256_Context outer;
- SHA256_Context inner;
-} HMAC_SHA256_Context;
-
-void HMAC_SHA256_Init(HMAC_SHA256_Context *ctxt, void *key, uint32_t keyLen);
-void HMAC_SHA256_Update(HMAC_SHA256_Context *ctxt, void *data, uint32_t len);
-void HMAC_SHA256_Final(HMAC_SHA256_Context *ctxt, uint8_t hmac[SHA256_HASH_SIZE]);
-
-#endif /* !_APS_HMAC_SHA256_H */
View
170 sha-1.1/hmac-sha384.c
@@ -1,170 +0,0 @@
-/*-
- * Copyright (c) 2010, 2011 Allan Saddi <allan@saddi.com>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
- *
- * $Id$
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#else
-# if HAVE_STDINT_H
-# include <stdint.h>
-# endif
-#endif
-#include <string.h>
-
-#include "hmac-sha384.h"
-
-#define HASH_BLOCK_SIZE 128
-
-void
-HMAC_SHA384_Init(HMAC_SHA384_Context *ctxt, void *key, uint32_t keyLen)
-{
- SHA384_Context keyCtxt;
- int i;
- uint8_t pkey[HASH_BLOCK_SIZE], okey[HASH_BLOCK_SIZE], ikey[HASH_BLOCK_SIZE];
-
- /* Ensure key is zero-padded */
- memset(pkey, 0, sizeof(pkey));
-
- if (keyLen > sizeof(pkey)) {
- /* Hash key if > HASH_BLOCK_SIZE */
- SHA384_Init(&keyCtxt);
- SHA384_Update(&keyCtxt, key, keyLen);
- SHA384_Final(&keyCtxt, pkey);
- }
- else {
- memcpy(pkey, key, keyLen);
- }
-
- /* XOR with opad, ipad */
- for (i = 0; i < sizeof(okey); i++) {
- okey[i] = pkey[i] ^ 0x5c;
- }
- for (i = 0; i < sizeof(ikey); i++) {
- ikey[i] = pkey[i] ^ 0x36;
- }
-
- /* Initialize hash contexts */
- SHA384_Init(&ctxt->outer);
- SHA384_Update(&ctxt->outer, okey, sizeof(okey));
- SHA384_Init(&ctxt->inner);
- SHA384_Update(&ctxt->inner, ikey, sizeof(ikey));
-
- /* Burn the stack */
- memset(ikey, 0, sizeof(ikey));
- memset(okey, 0, sizeof(okey));
- memset(pkey, 0, sizeof(pkey));
- memset(&keyCtxt, 0, sizeof(keyCtxt));
-}
-
-void
-HMAC_SHA384_Update(HMAC_SHA384_Context *ctxt, void *data, uint32_t len)
-{
- SHA384_Update(&ctxt->inner, data, len);
-}
-
-void
-HMAC_SHA384_Final(HMAC_SHA384_Context *ctxt, uint8_t hmac[SHA384_HASH_SIZE])
-{
- uint8_t ihash[SHA384_HASH_SIZE];
-
- SHA384_Final(&ctxt->inner, ihash);
- SHA384_Update(&ctxt->outer, ihash, sizeof(ihash));
- SHA384_Final(&ctxt->outer, hmac);
-
- memset(ihash, 0, sizeof(ihash));
-}
-
-#ifdef HMAC_SHA384_TEST
-#include <stdlib.h>
-#include <stdio.h>
-
-static void
-print_hmac(uint8_t hmac[SHA384_HASH_SIZE])
-{
- int i;
-
- for (i = 0; i < SHA384_HASH_SIZE;) {
- printf("%02x", hmac[i++]);
- if (i == 32)
- printf("\n");
- else if (!(i % 4))
- printf(" ");
- }
- printf("\n");
-}
-
-int
-main(int argc, char *argv[])
-{
- uint8_t key1[16];
- char *key2 = "Jefe";
- char *testdata1 = "Hi There";
- char *testdata2 = "what do ya want for nothing?";
- uint8_t testdata3[50];
- HMAC_SHA384_Context ctxt;
- uint8_t hmac[SHA384_HASH_SIZE];
-
- memset(key1, 0x0b, sizeof(key1));
- HMAC_SHA384_Init(&ctxt, key1, sizeof(key1));
- HMAC_SHA384_Update(&ctxt, testdata1, strlen(testdata1));
- HMAC_SHA384_Final(&ctxt, hmac);
-
- /* Expecting:
- * 7afaa633 e20d379b 02395915 fbc385ff 8dc27dcd 3885e106 8ab942ee ab52ec1f
- * 20ad382a 92370d8b 2e0ac8b8 3c4d53bf
- */
- print_hmac(hmac);
-
- HMAC_SHA384_Init(&ctxt, key2, strlen(key2));
- HMAC_SHA384_Update(&ctxt, testdata2, strlen(testdata2));
- HMAC_SHA384_Final(&ctxt, hmac);
-
- /* Expecting:
- * af45d2e3 76484031 617f78d2 b58a6b1b 9c7ef464 f5a01b47 e42ec373 6322445e
- * 8e2240ca 5e69e2c7 8b3239ec fab21649
- */
- print_hmac(hmac);
-
- memset(key1, 0xaa, sizeof(key1));
- memset(testdata3, 0xdd, sizeof(testdata3));
- HMAC_SHA384_Init(&ctxt, key1, sizeof(key1));
- HMAC_SHA384_Update(&ctxt, testdata3, sizeof(testdata3));
- HMAC_SHA384_Final(&ctxt, hmac);
-
- /* Expecting:
- * 1383e82e 28286b91 f4cc7afb d13d5b5c 6f887c05 e7c45424 84043a37 a5fe4580
- * 2a9470fb 663bd7b6 570fe2f5 03fc92f5
- */
- print_hmac(hmac);
-
- return 0;
-}
-#endif /* HMAC_SHA384_TEST */
View
43 sha-1.1/hmac-sha384.h
@@ -1,43 +0,0 @@
-/*-
- * Copyright (c) 2010, 2011 Allan Saddi <allan@saddi.com>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
- *
- * $Id$
- */
-
-#ifndef _APS_HMAC_SHA384_H
-#define _APS_HMAC_SHA384_H
-
-#include "sha384.h"
-
-typedef struct {
- SHA384_Context outer;
- SHA384_Context inner;
-} HMAC_SHA384_Context;
-
-void HMAC_SHA384_Init(HMAC_SHA384_Context *ctxt, void *key, uint32_t keyLen);
-void HMAC_SHA384_Update(HMAC_SHA384_Context *ctxt, void *data, uint32_t len);
-void HMAC_SHA384_Final(HMAC_SHA384_Context *ctxt, uint8_t hmac[SHA384_HASH_SIZE]);
-
-#endif /* !_APS_HMAC_SHA384_H */
View
170 sha-1.1/hmac-sha512.c
@@ -1,170 +0,0 @@
-/*-
- * Copyright (c) 2010, 2011 Allan Saddi <allan@saddi.com>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
- *
- * $Id$
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#else
-# if HAVE_STDINT_H
-# include <stdint.h>
-# endif
-#endif
-#include <string.h>
-
-#include "hmac-sha512.h"
-
-#define HASH_BLOCK_SIZE 128
-
-void
-HMAC_SHA512_Init(HMAC_SHA512_Context *ctxt, void *key, uint32_t keyLen)
-{
- SHA512_Context keyCtxt;
- int i;
- uint8_t pkey[HASH_BLOCK_SIZE], okey[HASH_BLOCK_SIZE], ikey[HASH_BLOCK_SIZE];
-
- /* Ensure key is zero-padded */
- memset(pkey, 0, sizeof(pkey));
-
- if (keyLen > sizeof(pkey)) {
- /* Hash key if > HASH_BLOCK_SIZE */
- SHA512_Init(&keyCtxt);
- SHA512_Update(&keyCtxt, key, keyLen);
- SHA512_Final(&keyCtxt, pkey);
- }
- else {
- memcpy(pkey, key, keyLen);
- }
-
- /* XOR with opad, ipad */
- for (i = 0; i < sizeof(okey); i++) {
- okey[i] = pkey[i] ^ 0x5c;
- }
- for (i = 0; i < sizeof(ikey); i++) {
- ikey[i] = pkey[i] ^ 0x36;
- }
-
- /* Initialize hash contexts */
- SHA512_Init(&ctxt->outer);
- SHA512_Update(&ctxt->outer, okey, sizeof(okey));
- SHA512_Init(&ctxt->inner);
- SHA512_Update(&ctxt->inner, ikey, sizeof(ikey));
-
- /* Burn the stack */
- memset(ikey, 0, sizeof(ikey));
- memset(okey, 0, sizeof(okey));
- memset(pkey, 0, sizeof(pkey));
- memset(&keyCtxt, 0, sizeof(keyCtxt));
-}
-
-void
-HMAC_SHA512_Update(HMAC_SHA512_Context *ctxt, void *data, uint32_t len)
-{
- SHA512_Update(&ctxt->inner, data, len);
-}
-
-void
-HMAC_SHA512_Final(HMAC_SHA512_Context *ctxt, uint8_t hmac[SHA512_HASH_SIZE])
-{
- uint8_t ihash[SHA512_HASH_SIZE];
-
- SHA512_Final(&ctxt->inner, ihash);
- SHA512_Update(&ctxt->outer, ihash, sizeof(ihash));
- SHA512_Final(&ctxt->outer, hmac);
-
- memset(ihash, 0, sizeof(ihash));
-}
-
-#ifdef HMAC_SHA512_TEST
-#include <stdlib.h>
-#include <stdio.h>
-
-static void
-print_hmac(uint8_t hmac[SHA512_HASH_SIZE])
-{
- int i;
-
- for (i = 0; i < SHA512_HASH_SIZE;) {
- printf("%02x", hmac[i++]);
- if (i == 32)
- printf("\n");
- else if (!(i % 4))
- printf(" ");
- }
- printf("\n");
-}
-
-int
-main(int argc, char *argv[])
-{
- uint8_t key1[16];
- char *key2 = "Jefe";
- char *testdata1 = "Hi There";
- char *testdata2 = "what do ya want for nothing?";
- uint8_t testdata3[50];
- HMAC_SHA512_Context ctxt;
- uint8_t hmac[SHA512_HASH_SIZE];
-
- memset(key1, 0x0b, sizeof(key1));
- HMAC_SHA512_Init(&ctxt, key1, sizeof(key1));
- HMAC_SHA512_Update(&ctxt, testdata1, strlen(testdata1));
- HMAC_SHA512_Final(&ctxt, hmac);
-
- /* Expecting:
- * 7641c48a 3b4aa8f8 87c07b3e 83f96aff b89c978f ed8c96fc bbf4ad59 6eebfe49
- * 6f9f16da 6cd080ba 393c6f36 5ad72b50 d15c71bf b1d6b81f 66a91178 6c6ce932
- */
- print_hmac(hmac);
-
- HMAC_SHA512_Init(&ctxt, key2, strlen(key2));
- HMAC_SHA512_Update(&ctxt, testdata2, strlen(testdata2));
- HMAC_SHA512_Final(&ctxt, hmac);
-
- /* Expecting:
- * 164b7a7b fcf819e2 e395fbe7 3b56e0a3 87bd6422 2e831fd6 10270cd7 ea250554
- * 9758bf75 c05a994a 6d034f65 f8f0e6fd caeab1a3 4d4a6b4b 636e070a 38bce737
- */
- print_hmac(hmac);
-
- memset(key1, 0xaa, sizeof(key1));
- memset(testdata3, 0xdd, sizeof(testdata3));
- HMAC_SHA512_Init(&ctxt, key1, sizeof(key1));
- HMAC_SHA512_Update(&ctxt, testdata3, sizeof(testdata3));
- HMAC_SHA512_Final(&ctxt, hmac);
-
- /* Expecting:
- * ad9b5c7d e7269373 7cd5e9d9 f41170d1 8841fec1 201c1c1b 02e05cae 11671800
- * 9f771cad 9946ddbf 7e3cde3e 818d9ae8 5d91b2ba dae94172 d096a44a 79c91e86
- */
- print_hmac(hmac);
-
- return 0;
-}
-#endif /* HMAC_SHA512_TEST */
View
43 sha-1.1/hmac-sha512.h
@@ -1,43 +0,0 @@
-/*-
- * Copyright (c) 2010, 2011 Allan Saddi <allan@saddi.com>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
- *
- * $Id$
- */
-
-#ifndef _APS_HMAC_SHA512_H
-#define _APS_HMAC_SHA512_H
-
-#include "sha512.h"
-
-typedef struct {
- SHA512_Context outer;
- SHA512_Context inner;
-} HMAC_SHA512_Context;
-
-void HMAC_SHA512_Init(HMAC_SHA512_Context *ctxt, void *key, uint32_t keyLen);
-void HMAC_SHA512_Update(HMAC_SHA512_Context *ctxt, void *data, uint32_t len);
-void HMAC_SHA512_Final(HMAC_SHA512_Context *ctxt, uint8_t hmac[SHA512_HASH_SIZE]);
-
-#endif /* !_APS_HMAC_SHA512_H */
View
527 sha-1.1/install-sh
@@ -1,527 +0,0 @@
-#!/bin/sh
-# install - install a program, script, or datafile
-
-scriptversion=2011-01-19.21; # UTC
-
-# This originates from X11R5 (mit/util/scripts/install.sh), which was
-# later released in X11R6 (xc/config/util/install.sh) with the
-# following copyright and license.
-#
-# Copyright (C) 1994 X Consortium
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to
-# deal in the Software without restriction, including without limitation the
-# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-# sell copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
-# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-# Except as contained in this notice, the name of the X Consortium shall not
-# be used in advertising or otherwise to promote the sale, use or other deal-
-# ings in this Software without prior written authorization from the X Consor-
-# tium.
-#
-#
-# FSF changes to this file are in the public domain.
-#
-# Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
-# when there is no Makefile.
-#
-# This script is compatible with the BSD install script, but was written
-# from scratch.
-
-nl='
-'
-IFS=" "" $nl"
-
-# set DOITPROG to echo to test this script
-
-# Don't use :- since 4.3BSD and earlier shells don't like it.
-doit=${DOITPROG-}
-if test -z "$doit"; then
- doit_exec=exec
-else
- doit_exec=$doit
-fi
-
-# Put in absolute file names if you don't have them in your path;
-# or use environment vars.
-
-chgrpprog=${CHGRPPROG-chgrp}
-chmodprog=${CHMODPROG-chmod}
-chownprog=${CHOWNPROG-chown}
-cmpprog=${CMPPROG-cmp}
-cpprog=${CPPROG-cp}
-mkdirprog=${MKDIRPROG-mkdir}
-mvprog=${MVPROG-mv}
-rmprog=${RMPROG-rm}
-stripprog=${STRIPPROG-strip}
-
-posix_glob='?'
-initialize_posix_glob='
- test "$posix_glob" != "?" || {
- if (set -f) 2>/dev/null; then
- posix_glob=
- else
- posix_glob=:
- fi
- }
-'
-
-posix_mkdir=
-
-# Desired mode of installed file.
-mode=0755
-
-chgrpcmd=
-chmodcmd=$chmodprog
-chowncmd=
-mvcmd=$mvprog
-rmcmd="$rmprog -f"
-stripcmd=
-
-src=
-dst=
-dir_arg=
-dst_arg=
-
-copy_on_change=false
-no_target_directory=
-
-usage="\
-Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
- or: $0 [OPTION]... SRCFILES... DIRECTORY
- or: $0 [OPTION]... -t DIRECTORY SRCFILES...
- or: $0 [OPTION]... -d DIRECTORIES...
-
-In the 1st form, copy SRCFILE to DSTFILE.
-In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
-In the 4th, create DIRECTORIES.
-
-Options:
- --help display this help and exit.
- --version display version info and exit.
-
- -c (ignored)
- -C install only if different (preserve the last data modification time)
- -d create directories instead of installing files.
- -g GROUP $chgrpprog installed files to GROUP.
- -m MODE $chmodprog installed files to MODE.
- -o USER $chownprog installed files to USER.
- -s $stripprog installed files.
- -t DIRECTORY install into DIRECTORY.
- -T report an error if DSTFILE is a directory.
-
-Environment variables override the default commands:
- CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
- RMPROG STRIPPROG
-"
-
-while test $# -ne 0; do
- case $1 in
- -c) ;;
-
- -C) copy_on_change=true;;
-
- -d) dir_arg=true;;
-
- -g) chgrpcmd="$chgrpprog $2"
- shift;;
-
- --help) echo "$usage"; exit $?;;
-
- -m) mode=$2
- case $mode in
- *' '* | *' '* | *'
-'* | *'*'* | *'?'* | *'['*)
- echo "$0: invalid mode: $mode" >&2
- exit 1;;
- esac
- shift;;
-
- -o) chowncmd="$chownprog $2"
- shift;;
-
- -s) stripcmd=$stripprog;;
-
- -t) dst_arg=$2
- # Protect names problematic for `test' and other utilities.
- case $dst_arg in
- -* | [=\(\)!]) dst_arg=./$dst_arg;;
- esac
- shift;;
-
- -T) no_target_directory=true;;
-
- --version) echo "$0 $scriptversion"; exit $?;;
-
- --) shift
- break;;
-
- -*) echo "$0: invalid option: $1" >&2
- exit 1;;
-
- *) break;;
- esac
- shift
-done
-
-if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
- # When -d is used, all remaining arguments are directories to create.
- # When -t is used, the destination is already specified.
- # Otherwise, the last argument is the destination. Remove it from $@.
- for arg
- do
- if test -n "$dst_arg"; then
- # $@ is not empty: it contains at least $arg.
- set fnord "$@" "$dst_arg"
- shift # fnord
- fi
- shift # arg
- dst_arg=$arg
- # Protect names problematic for `test' and other utilities.
- case $dst_arg in
- -* | [=\(\)!]) dst_arg=./$dst_arg;;
- esac
- done
-fi
-
-if test $# -eq 0; then
- if test -z "$dir_arg"; then
- echo "$0: no input file specified." >&2
- exit 1
- fi
- # It's OK to call `install-sh -d' without argument.
- # This can happen when creating conditional directories.
- exit 0
-fi
-
-if test -z "$dir_arg"; then
- do_exit='(exit $ret); exit $ret'
- trap "ret=129; $do_exit" 1
- trap "ret=130; $do_exit" 2
- trap "ret=141; $do_exit" 13
- trap "ret=143; $do_exit" 15
-
- # Set umask so as not to create temps with too-generous modes.
- # However, 'strip' requires both read and write access to temps.
- case $mode in
- # Optimize common cases.
- *644) cp_umask=133;;
- *755) cp_umask=22;;
-
- *[0-7])
- if test -z "$stripcmd"; then
- u_plus_rw=
- else
- u_plus_rw='% 200'
- fi
- cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
- *)
- if test -z "$stripcmd"; then
- u_plus_rw=
- else
- u_plus_rw=,u+rw
- fi
- cp_umask=$mode$u_plus_rw;;
- esac
-fi
-
-for src
-do
- # Protect names problematic for `test' and other utilities.
- case $src in
- -* | [=\(\)!]) src=./$src;;
- esac
-
- if test -n "$dir_arg"; then
- dst=$src
- dstdir=$dst
- test -d "$dstdir"
- dstdir_status=$?
- else
-
- # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
- # might cause directories to be created, which would be especially bad
- # if $src (and thus $dsttmp) contains '*'.
- if test ! -f "$src" && test ! -d "$src"; then
- echo "$0: $src does not exist." >&2
- exit 1
- fi
-
- if test -z "$dst_arg"; then
- echo "$0: no destination specified." >&2
- exit 1
- fi
- dst=$dst_arg
-
- # If destination is a directory, append the input filename; won't work
- # if double slashes aren't ignored.
- if test -d "$dst"; then
- if test -n "$no_target_directory"; then
- echo "$0: $dst_arg: Is a directory" >&2
- exit 1
- fi
- dstdir=$dst
- dst=$dstdir/`basename "$src"`
- dstdir_status=0
- else
- # Prefer dirname, but fall back on a substitute if dirname fails.
- dstdir=`
- (dirname "$dst") 2>/dev/null ||
- expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
- X"$dst" : 'X\(//\)[^/]' \| \
- X"$dst" : 'X\(//\)$' \| \
- X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
- echo X"$dst" |
- sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
- s//\1/
- q
- }
- /^X\(\/\/\)[^/].*/{
- s//\1/
- q
- }
- /^X\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'
- `
-
- test -d "$dstdir"
- dstdir_status=$?
- fi
- fi
-
- obsolete_mkdir_used=false
-
- if test $dstdir_status != 0; then
- case $posix_mkdir in
- '')
- # Create intermediate dirs using mode 755 as modified by the umask.
- # This is like FreeBSD 'install' as of 1997-10-28.
- umask=`umask`
- case $stripcmd.$umask in
- # Optimize common cases.
- *[2367][2367]) mkdir_umask=$umask;;
- .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
-
- *[0-7])
- mkdir_umask=`expr $umask + 22 \
- - $umask % 100 % 40 + $umask % 20 \
- - $umask % 10 % 4 + $umask % 2
- `;;
- *) mkdir_umask=$umask,go-w;;
- esac
-
- # With -d, create the new directory with the user-specified mode.
- # Otherwise, rely on $mkdir_umask.
- if test -n "$dir_arg"; then
- mkdir_mode=-m$mode
- else
- mkdir_mode=
- fi
-
- posix_mkdir=false
- case $umask in
- *[123567][0-7][0-7])
- # POSIX mkdir -p sets u+wx bits regardless of umask, which
- # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
- ;;
- *)
- tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
- trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
-
- if (umask $mkdir_umask &&
- exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
- then
- if test -z "$dir_arg" || {
- # Check for POSIX incompatibilities with -m.
- # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
- # other-writeable bit of parent directory when it shouldn't.
- # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
- ls_ld_tmpdir=`ls -ld "$tmpdir"`
- case $ls_ld_tmpdir in
- d????-?r-*) different_mode=700;;
- d????-?--*) different_mode=755;;
- *) false;;