[Cmake-commits] CMake branch, next, updated. v3.7.0-rc3-1023-g87cffe8

Brad King brad.king at kitware.com
Thu Nov 10 08:31:21 EST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  87cffe87f286e8ea9d7628560b3a00451eb95760 (commit)
       via  cd8a57ae9b4e7f811d30e1c5b225d36c7a049429 (commit)
       via  71180fc8aa1db84260552f494578401e3ddb6a84 (commit)
       via  3216e94cef3cd4afa558d9adef29921a9330935d (commit)
       via  5420278dc884c0382f271872b67c33978f3fe6b8 (commit)
       via  9a596b33bbfdb274ccf7f678c78cb8826c7c363b (commit)
       via  47f91a6183a6bb65a423d5acb1b75c4b39c17a87 (commit)
       via  d0ff3e701c63caab5a44c48ac70e3ab75af9ee88 (commit)
       via  465a85fb4615f4cfa20058c534bf3bfe71df1732 (commit)
       via  fc2cb74feedf2637e4b2cc153ede7b0726b9a7d3 (commit)
       via  0bd333bc2eb6590f939ccabb7caf102f13443600 (commit)
       via  7189d62c32e6f53dab5637f928917e59055f5e41 (commit)
       via  af7ebf8ad3b2b773dfe636a189a82998b1dc63e1 (commit)
       via  bb01f20e993bbd19b00e07ff0094b155aa0859de (commit)
       via  31bb727f3b239b541e1ff5679b3c461e9a05f227 (commit)
       via  53048afa8dc24327d82a1ff0f78801e1f344a4b6 (commit)
      from  404e3ebc4f512d912a07d12de897931463c9df3c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=87cffe87f286e8ea9d7628560b3a00451eb95760
commit 87cffe87f286e8ea9d7628560b3a00451eb95760
Merge: 404e3eb cd8a57a
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 10 08:31:12 2016 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Nov 10 08:31:12 2016 -0500

    Merge topic 'import-librhash' into next
    
    cd8a57ae Add option to build CMake against a system librhash
    71180fc8 FindLibRHash: Add module to find the librhash package
    3216e94c Remove unused cm_sha2 infrastructure
    5420278d Port hash computation to cmCryptoHash
    9a596b33 cmCryptoHash: Re-implement in terms of librhash
    47f91a61 cmCryptoHash: Avoid using subclasses at client sites
    d0ff3e70 librhash: Port to KWIML for ABI and integer type information
    465a85fb librhash: Avoid signed left-shift overflow
    fc2cb74f librhash: Implement bswap_32 as a function even in strict C90 mode
    0bd333bc librhash: Implement bswap_64 even in strict C90 mode
    7189d62c librhash: Use __builtin_bswap{32,64} on Clang
    af7ebf8a librhash: Install COPYING file with CMake documentation
    bb01f20e librhash: Disable warnings to avoid changing 3rd party code
    31bb727f librhash: Build the library within CMake
    53048afa librhash: Remove source fragments not needed for CMake


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cd8a57ae9b4e7f811d30e1c5b225d36c7a049429
commit cd8a57ae9b4e7f811d30e1c5b225d36c7a049429
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 13:31:33 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:38 2016 -0500

    Add option to build CMake against a system librhash
    
    Create a CMAKE_USE_SYSTEM_LIBRHASH option.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 82a34d3..7aa8010 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -104,7 +104,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
 
   # Allow the user to enable/disable all system utility library options by
   # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
-  set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBUV ZLIB)
+  set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB)
   foreach(util ${UTILITIES})
     if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
         AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
@@ -144,6 +144,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
     "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
   option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
   option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
+  option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
   option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
 
   # For now use system KWIML only if explicitly requested rather
@@ -298,9 +299,22 @@ macro (CMAKE_BUILD_UTILITIES)
     add_subdirectory(Utilities/KWIML)
   endif()
 
-  set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
-  add_subdirectory(Utilities/cmlibrhash)
-  CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
+  if(CMAKE_USE_SYSTEM_LIBRHASH)
+    if(NOT CMAKE_VERSION VERSION_LESS 3.0)
+      find_package(LibRHash)
+    else()
+      message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBRHASH requires CMake >= 3.0")
+    endif()
+    if(NOT LibRHash_FOUND)
+      message(FATAL_ERROR
+        "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
+    endif()
+    set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
+  else()
+    set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
+    add_subdirectory(Utilities/cmlibrhash)
+    CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
+  endif()
 
   #---------------------------------------------------------------------
   # Build zlib library for Curl, CMake, and CTest.
diff --git a/Utilities/cmThirdParty.h.in b/Utilities/cmThirdParty.h.in
index 210e727..a547f0d 100644
--- a/Utilities/cmThirdParty.h.in
+++ b/Utilities/cmThirdParty.h.in
@@ -13,6 +13,7 @@
 #cmakedefine CMAKE_USE_SYSTEM_LIBLZMA
 #cmakedefine CMAKE_USE_SYSTEM_FORM
 #cmakedefine CMAKE_USE_SYSTEM_JSONCPP
+#cmakedefine CMAKE_USE_SYSTEM_LIBRHASH
 #cmakedefine CMAKE_USE_SYSTEM_LIBUV
 #cmakedefine CTEST_USE_XMLRPC
 
diff --git a/Utilities/cm_rhash.h b/Utilities/cm_rhash.h
index 23d5409..c793627 100644
--- a/Utilities/cm_rhash.h
+++ b/Utilities/cm_rhash.h
@@ -3,6 +3,12 @@
 #ifndef cm_rhash_h
 #define cm_rhash_h
 
+/* Use the LibRHash library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_LIBRHASH
+#include <rhash.h>
+#else
 #include <cmlibrhash/librhash/rhash.h>
+#endif
 
 #endif
diff --git a/bootstrap b/bootstrap
index 4ce0dee..d54380a 100755
--- a/bootstrap
+++ b/bootstrap
@@ -493,6 +493,8 @@ Configuration:
   --no-system-liblzma     use cmake-provided liblzma library (default)
   --system-libarchive     use system-installed libarchive library
   --no-system-libarchive  use cmake-provided libarchive library (default)
+  --system-librhash       use system-installed librhash library
+  --no-system-librhash    use cmake-provided librhash library (default)
 
   --qt-gui                build the Qt-based GUI (requires Qt >= 4.2)
   --no-qt-gui             do not build the Qt-based GUI (default)
@@ -726,10 +728,10 @@ while test $# != 0; do
   --init=*) cmake_init_file=`cmake_arg "$1"` ;;
   --system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=1" ;;
   --no-system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=0" ;;
-  --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-zlib|--system-liblzma)
+  --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-librhash|--system-zlib|--system-liblzma)
     lib=`cmake_arg "$1" "--system-"`
     cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=1" ;;
-  --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-zlib|--no-system-liblzma)
+  --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-librhash|--no-system-zlib|--no-system-liblzma)
     lib=`cmake_arg "$1" "--no-system-"`
     cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=0" ;;
   --qt-gui) cmake_bootstrap_qt_gui="1" ;;

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=71180fc8aa1db84260552f494578401e3ddb6a84
commit 71180fc8aa1db84260552f494578401e3ddb6a84
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 13:29:31 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:38 2016 -0500

    FindLibRHash: Add module to find the librhash package
    
    Add it to a private source directory that is not installed so that we
    can use it for building CMake itself.  This will allow it to mature
    before being distributed publicly.

diff --git a/Source/Modules/FindLibRHash.cmake b/Source/Modules/FindLibRHash.cmake
new file mode 100644
index 0000000..86c6189
--- /dev/null
+++ b/Source/Modules/FindLibRHash.cmake
@@ -0,0 +1,73 @@
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#[=======================================================================[.rst:
+FindLibRHash
+------------
+
+Find LibRHash include directory and library.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+An :ref:`imported target <Imported targets>` named
+``LibRHash::LibRHash`` is provided if LibRHash has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables:
+
+``LibRHash_FOUND``
+  True if LibRHash was found, false otherwise.
+``LibRHash_INCLUDE_DIRS``
+  Include directories needed to include LibRHash headers.
+``LibRHash_LIBRARIES``
+  Libraries needed to link to LibRHash.
+
+Cache Variables
+^^^^^^^^^^^^^^^
+
+This module uses the following cache variables:
+
+``LibRHash_LIBRARY``
+  The location of the LibRHash library file.
+``LibRHash_INCLUDE_DIR``
+  The location of the LibRHash include directory containing ``rhash.h``.
+
+The cache variables should not be used by project code.
+They may be set by end users to point at LibRHash components.
+#]=======================================================================]
+
+#-----------------------------------------------------------------------------
+find_library(LibRHash_LIBRARY
+  NAMES rhash
+  )
+mark_as_advanced(LibRHash_LIBRARY)
+
+find_path(LibRHash_INCLUDE_DIR
+  NAMES rhash.h
+  )
+mark_as_advanced(LibRHash_INCLUDE_DIR)
+
+#-----------------------------------------------------------------------------
+include(${CMAKE_CURRENT_LIST_DIR}/../../Modules/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibRHash
+  FOUND_VAR LibRHash_FOUND
+  REQUIRED_VARS LibRHash_LIBRARY LibRHash_INCLUDE_DIR
+  )
+set(LIBRHASH_FOUND ${LibRHash_FOUND})
+
+#-----------------------------------------------------------------------------
+# Provide documented result variables and targets.
+if(LibRHash_FOUND)
+  set(LibRHash_INCLUDE_DIRS ${LibRHash_INCLUDE_DIR})
+  set(LibRHash_LIBRARIES ${LibRHash_LIBRARY})
+  if(NOT TARGET LibRHash::LibRHash)
+    add_library(LibRHash::LibRHash UNKNOWN IMPORTED)
+    set_target_properties(LibRHash::LibRHash PROPERTIES
+      IMPORTED_LOCATION "${LibRHash_LIBRARY}"
+      INTERFACE_INCLUDE_DIRECTORIES "${LibRHash_INCLUDE_DIRS}"
+      )
+  endif()
+endif()
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 5d72e5c..3a3c76c 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1377,6 +1377,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
     add_subdirectory(FindJsonCpp)
   endif()
 
+  if(CMake_TEST_FindLibRHash)
+    add_subdirectory(FindLibRHash)
+  endif()
+
   if(CMake_TEST_FindLibUV)
     add_subdirectory(FindLibUV)
   endif()
diff --git a/Tests/FindLibRHash/CMakeLists.txt b/Tests/FindLibRHash/CMakeLists.txt
new file mode 100644
index 0000000..4d3954d
--- /dev/null
+++ b/Tests/FindLibRHash/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindLibRHash.Test COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindLibRHash/Test"
+  "${CMake_BINARY_DIR}/Tests/FindLibRHash/Test"
+  ${build_generator_args}
+  --build-project TestFindLibRHash
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )
diff --git a/Tests/FindLibRHash/Test/CMakeLists.txt b/Tests/FindLibRHash/Test/CMakeLists.txt
new file mode 100644
index 0000000..37e062a
--- /dev/null
+++ b/Tests/FindLibRHash/Test/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.7)
+project(TestFindLibRHash C)
+include(CTest)
+
+# CMake does not actually provide FindLibRHash publicly.
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../Source/Modules)
+
+find_package(LibRHash REQUIRED)
+
+add_executable(test_librhash_tgt main.c)
+target_link_libraries(test_librhash_tgt LibRHash::LibRHash)
+add_test(NAME test_librhash_tgt COMMAND test_librhash_tgt)
+
+add_executable(test_librhash_var main.c)
+target_include_directories(test_librhash_var PRIVATE ${LibRHash_INCLUDE_DIRS})
+target_link_libraries(test_librhash_var PRIVATE ${LibRHash_LIBRARIES})
+add_test(NAME test_librhash_var COMMAND test_librhash_var)
diff --git a/Tests/FindLibRHash/Test/main.c b/Tests/FindLibRHash/Test/main.c
new file mode 100644
index 0000000..201dced
--- /dev/null
+++ b/Tests/FindLibRHash/Test/main.c
@@ -0,0 +1,7 @@
+#include <rhash.h>
+
+int main()
+{
+  rhash_library_init();
+  return 0;
+}

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3216e94cef3cd4afa558d9adef29921a9330935d
commit 3216e94cef3cd4afa558d9adef29921a9330935d
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 13:28:03 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:38 2016 -0500

    Remove unused cm_sha2 infrastructure
    
    All clients of `cm_sha2` have been ported to `cmCryptoHash`, which now
    uses librhash internally.

diff --git a/CTestCustom.cmake.in b/CTestCustom.cmake.in
index 48dd3de..07a9fdb 100644
--- a/CTestCustom.cmake.in
+++ b/CTestCustom.cmake.in
@@ -17,7 +17,6 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
   "Utilities.cmbzip2."
   "Source.CTest.Curl"
   "Source.CursesDialog.form"
-  "Source.cm_sha2.*warning.*cast increases required alignment of target type"
   "Utilities.cmcurl"
   "Utilities.cmexpat."
   "Utilities.cmlibarchive"
@@ -84,7 +83,6 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
   "warning: Value stored to 'yytoken' is never read"
   "index_encoder.c.241.2. warning: Value stored to .out_start. is never read"
   "index.c.*warning: Access to field.*results in a dereference of a null pointer.*loaded from variable.*"
-  "cm_sha2.*warning: Value stored to.*is never read"
   "cmFortranLexer.cxx:[0-9]+:[0-9]+: warning: Call to 'realloc' has an allocation size of 0 bytes"
   "testProcess.*warning: Dereference of null pointer .loaded from variable .invalidAddress.."
   "liblzma/simple/x86.c:[0-9]+:[0-9]+: warning: The result of the '<<' expression is undefined"
diff --git a/Source/.gitattributes b/Source/.gitattributes
index 5002b2a..e9e35bd 100644
--- a/Source/.gitattributes
+++ b/Source/.gitattributes
@@ -1,6 +1,3 @@
-# Preserve upstream indentation style.
-cm_sha2.*        whitespace=indent-with-non-tab
-
 # Preserve indentation style in generated code.
 cmListFileLexer.c       whitespace=-tab-in-indent,-indent-with-non-tab
 cmFortranLexer.cxx      whitespace=-tab-in-indent,-indent-with-non-tab
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 879272c..718b022 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -626,8 +626,6 @@ set(SRCS
   cm_auto_ptr.hxx
   cm_get_date.h
   cm_get_date.c
-  cm_sha2.h
-  cm_sha2.c
   cm_utf8.h
   cm_utf8.c
   cm_codecvt.hxx
diff --git a/Source/cm_sha2.c b/Source/cm_sha2.c
deleted file mode 100644
index 649c39a..0000000
--- a/Source/cm_sha2.c
+++ /dev/null
@@ -1,1613 +0,0 @@
-/*
- * FILE:	sha2.c
- * AUTHOR:	Aaron D. Gifford
- *		http://www.aarongifford.com/computers/sha.html
- *
- * Copyright (c) 2000-2003, 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.
- *
- * $Id: sha2.c,v 1.4 2004/01/07 22:58:18 adg Exp $
- */
-
-#include <string.h>	/* memcpy()/memset() or bcopy()/bzero() */
-#include <assert.h>	/* assert() */
-#include "cm_sha2.h"	/* "sha2.h" -> "cm_sha2.h" renamed for CMake */
-
-/*
- * ASSERT NOTE:
- * Some sanity checking code is included using assert().  On my FreeBSD
- * system, this additional code can be removed by compiling with NDEBUG
- * defined.  Check your own systems manpage on assert() to see how to
- * compile WITHOUT the sanity checking code on your system.
- *
- * UNROLLED TRANSFORM LOOP NOTE:
- * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
- * loop version for the hash transform rounds (defined using macros
- * later in this file).  Either define on the command line, for example:
- *
- *   cc -DSHA2_UNROLL_TRANSFORM -o sha2 sha2.c sha2prog.c
- *
- * or define below:
- *
- *   #define SHA2_UNROLL_TRANSFORM
- *
- */
-
-
-/*** SHA-224/256/384/512 Machine Architecture Definitions *************/
-/*
- * BYTE_ORDER NOTE:
- *
- * Please make sure that your system defines BYTE_ORDER.  If your
- * architecture is little-endian, make sure it also defines
- * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
- * equivilent.
- *
- * If your system does not define the above, then you can do so by
- * hand like this:
- *
- *   #define LITTLE_ENDIAN 1234
- *   #define BIG_ENDIAN    4321
- *
- * And for little-endian machines, add:
- *
- *   #define BYTE_ORDER LITTLE_ENDIAN
- *
- * Or for big-endian machines:
- *
- *   #define BYTE_ORDER BIG_ENDIAN
- *
- * The FreeBSD machine this was written on defines BYTE_ORDER
- * appropriately by including <sys/types.h> (which in turn includes
- * <machine/endian.h> where the appropriate definitions are actually
- * made).
- */
-#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
-/* CMake modification: use byte order from KWIML.  */
-# undef BYTE_ORDER
-# undef BIG_ENDIAN
-# undef LITTLE_ENDIAN
-# define BYTE_ORDER    KWIML_ABI_ENDIAN_ID
-# define BIG_ENDIAN    KWIML_ABI_ENDIAN_ID_BIG
-# define LITTLE_ENDIAN KWIML_ABI_ENDIAN_ID_LITTLE
-#endif
-
-/* CMake modification: use types computed in header.  */
-typedef cm_sha2_uint8_t  sha_byte;	/* Exactly 1 byte */
-typedef cm_sha2_uint32_t sha_word32;	/* Exactly 4 bytes */
-typedef cm_sha2_uint64_t sha_word64;	/* Exactly 8 bytes */
-#define SHA_UINT32_C(x) KWIML_INT_UINT32_C(x)
-#define SHA_UINT64_C(x) KWIML_INT_UINT64_C(x)
-#if defined(__clang__)
-# pragma clang diagnostic ignored "-Wcast-align"
-#endif
-
-/*** ENDIAN REVERSAL MACROS *******************************************/
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define REVERSE32(w,x)	{ \
-	sha_word32 tmp = (w); \
-	tmp = (tmp >> 16) | (tmp << 16); \
-	(x) = ((tmp & SHA_UINT32_C(0xff00ff00)) >> 8) | \
-	      ((tmp & SHA_UINT32_C(0x00ff00ff)) << 8); \
-}
-#define REVERSE64(w,x)	{ \
-	sha_word64 tmp = (w); \
-	tmp = (tmp >> 32) | (tmp << 32); \
-	tmp = ((tmp & SHA_UINT64_C(0xff00ff00ff00ff00)) >> 8) | \
-	      ((tmp & SHA_UINT64_C(0x00ff00ff00ff00ff)) << 8); \
-	(x) = ((tmp & SHA_UINT64_C(0xffff0000ffff0000)) >> 16) | \
-	      ((tmp & SHA_UINT64_C(0x0000ffff0000ffff)) << 16); \
-}
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-
-/*
- * Macro for incrementally adding the unsigned 64-bit integer n to the
- * unsigned 128-bit integer (represented using a two-element array of
- * 64-bit words):
- */
-#define ADDINC128(w,n)	{ \
-	(w)[0] += (sha_word64)(n); \
-	if ((w)[0] < (n)) { \
-		(w)[1]++; \
-	} \
-}
-
-/*
- * Macros for copying blocks of memory and for zeroing out ranges
- * of memory.  Using these macros makes it easy to switch from
- * using memset()/memcpy() and using bzero()/bcopy().
- *
- * Please define either SHA2_USE_MEMSET_MEMCPY or define
- * SHA2_USE_BZERO_BCOPY depending on which function set you
- * choose to use:
- */
-#if !defined(SHA2_USE_MEMSET_MEMCPY) && !defined(SHA2_USE_BZERO_BCOPY)
-/* Default to memset()/memcpy() if no option is specified */
-#define	SHA2_USE_MEMSET_MEMCPY	1
-#endif
-#if defined(SHA2_USE_MEMSET_MEMCPY) && defined(SHA2_USE_BZERO_BCOPY)
-/* Abort with an error if BOTH options are defined */
-#error Define either SHA2_USE_MEMSET_MEMCPY or SHA2_USE_BZERO_BCOPY, not both!
-#endif
-
-#ifdef SHA2_USE_MEMSET_MEMCPY
-#define MEMSET_BZERO(p,l)	memset((p), 0, (l))
-#define MEMCPY_BCOPY(d,s,l)	memcpy((d), (s), (l))
-#endif
-#ifdef SHA2_USE_BZERO_BCOPY
-#define MEMSET_BZERO(p,l)	bzero((p), (l))
-#define MEMCPY_BCOPY(d,s,l)	bcopy((s), (d), (l))
-#endif
-
-
-/*** THE SIX LOGICAL FUNCTIONS ****************************************/
-/*
- * Bit shifting and rotation (used by the six SHA-XYZ logical functions:
- *
- *   NOTE:  In the original SHA-256/384/512 document, the shift-right
- *   function was named R and the rotate-right function was called S.
- *   (See: http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf on the
- *   web.)
- *
- *   The newer NIST FIPS 180-2 document uses a much clearer naming
- *   scheme, SHR for shift-right, ROTR for rotate-right, and ROTL for
- *   rotate-left.  (See:
- *   http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
- *   on the web.)
- *
- *   WARNING: These macros must be used cautiously, since they reference
- *   supplied parameters sometimes more than once, and thus could have
- *   unexpected side-effects if used without taking this into account.
- */
-/* Shift-right (used in SHA-256, SHA-384, and SHA-512): */
-#define SHR(b,x) 		((x) >> (b))
-/* 32-bit Rotate-right (used in SHA-256): */
-#define ROTR32(b,x)	(((x) >> (b)) | ((x) << (32 - (b))))
-/* 64-bit Rotate-right (used in SHA-384 and SHA-512): */
-#define ROTR64(b,x)	(((x) >> (b)) | ((x) << (64 - (b))))
-/* 32-bit Rotate-left (used in SHA-1): */
-#define ROTL32(b,x)	(((x) << (b)) | ((x) >> (32 - (b))))
-
-/* Two logical functions used in SHA-1, SHA-254, SHA-256, SHA-384, and SHA-512: */
-#define Ch(x,y,z)	(((x) & (y)) ^ ((~(x)) & (z)))
-#define Maj(x,y,z)	(((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
-
-/* Function used in SHA-1: */
-#define Parity(x,y,z)	((x) ^ (y) ^ (z))
-
-/* Four logical functions used in SHA-256: */
-#define Sigma0_256(x)	(ROTR32(2,  (x)) ^ ROTR32(13, (x)) ^ ROTR32(22, (x)))
-#define Sigma1_256(x)	(ROTR32(6,  (x)) ^ ROTR32(11, (x)) ^ ROTR32(25, (x)))
-#define sigma0_256(x)	(ROTR32(7,  (x)) ^ ROTR32(18, (x)) ^ SHR(   3 , (x)))
-#define sigma1_256(x)	(ROTR32(17, (x)) ^ ROTR32(19, (x)) ^ SHR(   10, (x)))
-
-/* Four of six logical functions used in SHA-384 and SHA-512: */
-#define Sigma0_512(x)	(ROTR64(28, (x)) ^ ROTR64(34, (x)) ^ ROTR64(39, (x)))
-#define Sigma1_512(x)	(ROTR64(14, (x)) ^ ROTR64(18, (x)) ^ ROTR64(41, (x)))
-#define sigma0_512(x)	(ROTR64( 1, (x)) ^ ROTR64( 8, (x)) ^ SHR(    7, (x)))
-#define sigma1_512(x)	(ROTR64(19, (x)) ^ ROTR64(61, (x)) ^ SHR(    6, (x)))
-
-/*** INTERNAL FUNCTION PROTOTYPES *************************************/
-
-/* SHA-224 and SHA-256: */
-void SHA256_Internal_Init(SHA_CTX*, const sha_word32*);
-void SHA256_Internal_Last(SHA_CTX*);
-void SHA256_Internal_Transform(SHA_CTX*, const sha_word32*);
-
-/* SHA-384 and SHA-512: */
-void SHA512_Internal_Init(SHA_CTX*, const sha_word64*);
-void SHA512_Internal_Last(SHA_CTX*);
-void SHA512_Internal_Transform(SHA_CTX*, const sha_word64*);
-
-
-/*** SHA2 INITIAL HASH VALUES AND CONSTANTS ***************************/
-
-/* Hash constant words K for SHA-1: */
-#define K1_0_TO_19	SHA_UINT32_C(0x5a827999)
-#define K1_20_TO_39	SHA_UINT32_C(0x6ed9eba1)
-#define K1_40_TO_59	SHA_UINT32_C(0x8f1bbcdc)
-#define K1_60_TO_79	SHA_UINT32_C(0xca62c1d6)
-
-/* Initial hash value H for SHA-1: */
-static const sha_word32 sha1_initial_hash_value[5] = {
-	SHA_UINT32_C(0x67452301),
-	SHA_UINT32_C(0xefcdab89),
-	SHA_UINT32_C(0x98badcfe),
-	SHA_UINT32_C(0x10325476),
-	SHA_UINT32_C(0xc3d2e1f0)
-};
-
-/* Hash constant words K for SHA-224 and SHA-256: */
-static const sha_word32 K256[64] = {
-	SHA_UINT32_C(0x428a2f98), SHA_UINT32_C(0x71374491),
-	SHA_UINT32_C(0xb5c0fbcf), SHA_UINT32_C(0xe9b5dba5),
-	SHA_UINT32_C(0x3956c25b), SHA_UINT32_C(0x59f111f1),
-	SHA_UINT32_C(0x923f82a4), SHA_UINT32_C(0xab1c5ed5),
-	SHA_UINT32_C(0xd807aa98), SHA_UINT32_C(0x12835b01),
-	SHA_UINT32_C(0x243185be), SHA_UINT32_C(0x550c7dc3),
-	SHA_UINT32_C(0x72be5d74), SHA_UINT32_C(0x80deb1fe),
-	SHA_UINT32_C(0x9bdc06a7), SHA_UINT32_C(0xc19bf174),
-	SHA_UINT32_C(0xe49b69c1), SHA_UINT32_C(0xefbe4786),
-	SHA_UINT32_C(0x0fc19dc6), SHA_UINT32_C(0x240ca1cc),
-	SHA_UINT32_C(0x2de92c6f), SHA_UINT32_C(0x4a7484aa),
-	SHA_UINT32_C(0x5cb0a9dc), SHA_UINT32_C(0x76f988da),
-	SHA_UINT32_C(0x983e5152), SHA_UINT32_C(0xa831c66d),
-	SHA_UINT32_C(0xb00327c8), SHA_UINT32_C(0xbf597fc7),
-	SHA_UINT32_C(0xc6e00bf3), SHA_UINT32_C(0xd5a79147),
-	SHA_UINT32_C(0x06ca6351), SHA_UINT32_C(0x14292967),
-	SHA_UINT32_C(0x27b70a85), SHA_UINT32_C(0x2e1b2138),
-	SHA_UINT32_C(0x4d2c6dfc), SHA_UINT32_C(0x53380d13),
-	SHA_UINT32_C(0x650a7354), SHA_UINT32_C(0x766a0abb),
-	SHA_UINT32_C(0x81c2c92e), SHA_UINT32_C(0x92722c85),
-	SHA_UINT32_C(0xa2bfe8a1), SHA_UINT32_C(0xa81a664b),
-	SHA_UINT32_C(0xc24b8b70), SHA_UINT32_C(0xc76c51a3),
-	SHA_UINT32_C(0xd192e819), SHA_UINT32_C(0xd6990624),
-	SHA_UINT32_C(0xf40e3585), SHA_UINT32_C(0x106aa070),
-	SHA_UINT32_C(0x19a4c116), SHA_UINT32_C(0x1e376c08),
-	SHA_UINT32_C(0x2748774c), SHA_UINT32_C(0x34b0bcb5),
-	SHA_UINT32_C(0x391c0cb3), SHA_UINT32_C(0x4ed8aa4a),
-	SHA_UINT32_C(0x5b9cca4f), SHA_UINT32_C(0x682e6ff3),
-	SHA_UINT32_C(0x748f82ee), SHA_UINT32_C(0x78a5636f),
-	SHA_UINT32_C(0x84c87814), SHA_UINT32_C(0x8cc70208),
-	SHA_UINT32_C(0x90befffa), SHA_UINT32_C(0xa4506ceb),
-	SHA_UINT32_C(0xbef9a3f7), SHA_UINT32_C(0xc67178f2)
-};
-
-/* Initial hash value H for SHA-224: */
-static const sha_word32 sha224_initial_hash_value[8] = {
-	SHA_UINT32_C(0xc1059ed8),
-	SHA_UINT32_C(0x367cd507),
-	SHA_UINT32_C(0x3070dd17),
-	SHA_UINT32_C(0xf70e5939),
-	SHA_UINT32_C(0xffc00b31),
-	SHA_UINT32_C(0x68581511),
-	SHA_UINT32_C(0x64f98fa7),
-	SHA_UINT32_C(0xbefa4fa4)
-};
-
-/* Initial hash value H for SHA-256: */
-static const sha_word32 sha256_initial_hash_value[8] = {
-	SHA_UINT32_C(0x6a09e667),
-	SHA_UINT32_C(0xbb67ae85),
-	SHA_UINT32_C(0x3c6ef372),
-	SHA_UINT32_C(0xa54ff53a),
-	SHA_UINT32_C(0x510e527f),
-	SHA_UINT32_C(0x9b05688c),
-	SHA_UINT32_C(0x1f83d9ab),
-	SHA_UINT32_C(0x5be0cd19)
-};
-
-/* Hash constant words K for SHA-384 and SHA-512: */
-static const sha_word64 K512[80] = {
-	SHA_UINT64_C(0x428a2f98d728ae22), SHA_UINT64_C(0x7137449123ef65cd),
-	SHA_UINT64_C(0xb5c0fbcfec4d3b2f), SHA_UINT64_C(0xe9b5dba58189dbbc),
-	SHA_UINT64_C(0x3956c25bf348b538), SHA_UINT64_C(0x59f111f1b605d019),
-	SHA_UINT64_C(0x923f82a4af194f9b), SHA_UINT64_C(0xab1c5ed5da6d8118),
-	SHA_UINT64_C(0xd807aa98a3030242), SHA_UINT64_C(0x12835b0145706fbe),
-	SHA_UINT64_C(0x243185be4ee4b28c), SHA_UINT64_C(0x550c7dc3d5ffb4e2),
-	SHA_UINT64_C(0x72be5d74f27b896f), SHA_UINT64_C(0x80deb1fe3b1696b1),
-	SHA_UINT64_C(0x9bdc06a725c71235), SHA_UINT64_C(0xc19bf174cf692694),
-	SHA_UINT64_C(0xe49b69c19ef14ad2), SHA_UINT64_C(0xefbe4786384f25e3),
-	SHA_UINT64_C(0x0fc19dc68b8cd5b5), SHA_UINT64_C(0x240ca1cc77ac9c65),
-	SHA_UINT64_C(0x2de92c6f592b0275), SHA_UINT64_C(0x4a7484aa6ea6e483),
-	SHA_UINT64_C(0x5cb0a9dcbd41fbd4), SHA_UINT64_C(0x76f988da831153b5),
-	SHA_UINT64_C(0x983e5152ee66dfab), SHA_UINT64_C(0xa831c66d2db43210),
-	SHA_UINT64_C(0xb00327c898fb213f), SHA_UINT64_C(0xbf597fc7beef0ee4),
-	SHA_UINT64_C(0xc6e00bf33da88fc2), SHA_UINT64_C(0xd5a79147930aa725),
-	SHA_UINT64_C(0x06ca6351e003826f), SHA_UINT64_C(0x142929670a0e6e70),
-	SHA_UINT64_C(0x27b70a8546d22ffc), SHA_UINT64_C(0x2e1b21385c26c926),
-	SHA_UINT64_C(0x4d2c6dfc5ac42aed), SHA_UINT64_C(0x53380d139d95b3df),
-	SHA_UINT64_C(0x650a73548baf63de), SHA_UINT64_C(0x766a0abb3c77b2a8),
-	SHA_UINT64_C(0x81c2c92e47edaee6), SHA_UINT64_C(0x92722c851482353b),
-	SHA_UINT64_C(0xa2bfe8a14cf10364), SHA_UINT64_C(0xa81a664bbc423001),
-	SHA_UINT64_C(0xc24b8b70d0f89791), SHA_UINT64_C(0xc76c51a30654be30),
-	SHA_UINT64_C(0xd192e819d6ef5218), SHA_UINT64_C(0xd69906245565a910),
-	SHA_UINT64_C(0xf40e35855771202a), SHA_UINT64_C(0x106aa07032bbd1b8),
-	SHA_UINT64_C(0x19a4c116b8d2d0c8), SHA_UINT64_C(0x1e376c085141ab53),
-	SHA_UINT64_C(0x2748774cdf8eeb99), SHA_UINT64_C(0x34b0bcb5e19b48a8),
-	SHA_UINT64_C(0x391c0cb3c5c95a63), SHA_UINT64_C(0x4ed8aa4ae3418acb),
-	SHA_UINT64_C(0x5b9cca4f7763e373), SHA_UINT64_C(0x682e6ff3d6b2b8a3),
-	SHA_UINT64_C(0x748f82ee5defb2fc), SHA_UINT64_C(0x78a5636f43172f60),
-	SHA_UINT64_C(0x84c87814a1f0ab72), SHA_UINT64_C(0x8cc702081a6439ec),
-	SHA_UINT64_C(0x90befffa23631e28), SHA_UINT64_C(0xa4506cebde82bde9),
-	SHA_UINT64_C(0xbef9a3f7b2c67915), SHA_UINT64_C(0xc67178f2e372532b),
-	SHA_UINT64_C(0xca273eceea26619c), SHA_UINT64_C(0xd186b8c721c0c207),
-	SHA_UINT64_C(0xeada7dd6cde0eb1e), SHA_UINT64_C(0xf57d4f7fee6ed178),
-	SHA_UINT64_C(0x06f067aa72176fba), SHA_UINT64_C(0x0a637dc5a2c898a6),
-	SHA_UINT64_C(0x113f9804bef90dae), SHA_UINT64_C(0x1b710b35131c471b),
-	SHA_UINT64_C(0x28db77f523047d84), SHA_UINT64_C(0x32caab7b40c72493),
-	SHA_UINT64_C(0x3c9ebe0a15c9bebc), SHA_UINT64_C(0x431d67c49c100d4c),
-	SHA_UINT64_C(0x4cc5d4becb3e42b6), SHA_UINT64_C(0x597f299cfc657e2a),
-	SHA_UINT64_C(0x5fcb6fab3ad6faec), SHA_UINT64_C(0x6c44198c4a475817)
-};
-
-/* Initial hash value H for SHA-384 */
-static const sha_word64 sha384_initial_hash_value[8] = {
-	SHA_UINT64_C(0xcbbb9d5dc1059ed8),
-	SHA_UINT64_C(0x629a292a367cd507),
-	SHA_UINT64_C(0x9159015a3070dd17),
-	SHA_UINT64_C(0x152fecd8f70e5939),
-	SHA_UINT64_C(0x67332667ffc00b31),
-	SHA_UINT64_C(0x8eb44a8768581511),
-	SHA_UINT64_C(0xdb0c2e0d64f98fa7),
-	SHA_UINT64_C(0x47b5481dbefa4fa4)
-};
-
-/* Initial hash value H for SHA-512 */
-static const sha_word64 sha512_initial_hash_value[8] = {
-	SHA_UINT64_C(0x6a09e667f3bcc908),
-	SHA_UINT64_C(0xbb67ae8584caa73b),
-	SHA_UINT64_C(0x3c6ef372fe94f82b),
-	SHA_UINT64_C(0xa54ff53a5f1d36f1),
-	SHA_UINT64_C(0x510e527fade682d1),
-	SHA_UINT64_C(0x9b05688c2b3e6c1f),
-	SHA_UINT64_C(0x1f83d9abfb41bd6b),
-	SHA_UINT64_C(0x5be0cd19137e2179)
-};
-
-/*
- * Constant used by SHA224/256/384/512_End() functions for converting the
- * digest to a readable hexadecimal character string:
- */
-static const char *sha_hex_digits = "0123456789abcdef";
-
-
-/*** SHA-1: ***********************************************************/
-void SHA1_Init(SHA_CTX* context) {
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	MEMCPY_BCOPY(context->s1.state, sha1_initial_hash_value, sizeof(sha_word32) * 5);
-	MEMSET_BZERO(context->s1.buffer, 64);
-	context->s1.bitcount = 0;
-}
-
-#ifdef SHA2_UNROLL_TRANSFORM
-
-/* Unrolled SHA-1 round macros: */
-
-#if BYTE_ORDER == LITTLE_ENDIAN
-
-#define ROUND1_0_TO_15(a,b,c,d,e)				\
-	REVERSE32(*data++, W1[j]);				\
-	(e) = ROTL32(5, (a)) + Ch((b), (c), (d)) + (e) +	\
-	     K1_0_TO_19 + W1[j];	\
-	(b) = ROTL32(30, (b));		\
-	j++;
-
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
-
-#define ROUND1_0_TO_15(a,b,c,d,e)				\
-	(e) = ROTL32(5, (a)) + Ch((b), (c), (d)) + (e) +	\
-	     K1_0_TO_19 + ( W1[j] = *data++ );		\
-	(b) = ROTL32(30, (b));	\
-	j++;
-
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-
-#define ROUND1_16_TO_19(a,b,c,d,e)	\
-	T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];	\
-	(e) = ROTL32(5, a) + Ch(b,c,d) + e + K1_0_TO_19 + ( W1[j&0x0f] = ROTL32(1, T1) );	\
-	(b) = ROTL32(30, b);	\
-	j++;
-
-#define ROUND1_20_TO_39(a,b,c,d,e)	\
-	T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];	\
-	(e) = ROTL32(5, a) + Parity(b,c,d) + e + K1_20_TO_39 + ( W1[j&0x0f] = ROTL32(1, T1) );	\
-	(b) = ROTL32(30, b);	\
-	j++;
-
-#define ROUND1_40_TO_59(a,b,c,d,e)	\
-	T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];	\
-	(e) = ROTL32(5, a) + Maj(b,c,d) + e + K1_40_TO_59 + ( W1[j&0x0f] = ROTL32(1, T1) );	\
-	(b) = ROTL32(30, b);	\
-	j++;
-
-#define ROUND1_60_TO_79(a,b,c,d,e)	\
-	T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];	\
-	(e) = ROTL32(5, a) + Parity(b,c,d) + e + K1_60_TO_79 + ( W1[j&0x0f] = ROTL32(1, T1) );	\
-	(b) = ROTL32(30, b);	\
-	j++;
-
-void SHA1_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
-	sha_word32	a, b, c, d, e;
-	sha_word32	T1, *W1;
-	int		j;
-
-	W1 = (sha_word32*)context->s1.buffer;
-
-	/* Initialize registers with the prev. intermediate value */
-	a = context->s1.state[0];
-	b = context->s1.state[1];
-	c = context->s1.state[2];
-	d = context->s1.state[3];
-	e = context->s1.state[4];
-
-	j = 0;
-
-	/* Rounds 0 to 15 unrolled: */
-	ROUND1_0_TO_15(a,b,c,d,e);
-	ROUND1_0_TO_15(e,a,b,c,d);
-	ROUND1_0_TO_15(d,e,a,b,c);
-	ROUND1_0_TO_15(c,d,e,a,b);
-	ROUND1_0_TO_15(b,c,d,e,a);
-	ROUND1_0_TO_15(a,b,c,d,e);
-	ROUND1_0_TO_15(e,a,b,c,d);
-	ROUND1_0_TO_15(d,e,a,b,c);
-	ROUND1_0_TO_15(c,d,e,a,b);
-	ROUND1_0_TO_15(b,c,d,e,a);
-	ROUND1_0_TO_15(a,b,c,d,e);
-	ROUND1_0_TO_15(e,a,b,c,d);
-	ROUND1_0_TO_15(d,e,a,b,c);
-	ROUND1_0_TO_15(c,d,e,a,b);
-	ROUND1_0_TO_15(b,c,d,e,a);
-	ROUND1_0_TO_15(a,b,c,d,e);
-
-	/* Rounds 16 to 19 unrolled: */
-	ROUND1_16_TO_19(e,a,b,c,d);
-	ROUND1_16_TO_19(d,e,a,b,c);
-	ROUND1_16_TO_19(c,d,e,a,b);
-	ROUND1_16_TO_19(b,c,d,e,a);
-
-	/* Rounds 20 to 39 unrolled: */
-	ROUND1_20_TO_39(a,b,c,d,e);
-	ROUND1_20_TO_39(e,a,b,c,d);
-	ROUND1_20_TO_39(d,e,a,b,c);
-	ROUND1_20_TO_39(c,d,e,a,b);
-	ROUND1_20_TO_39(b,c,d,e,a);
-	ROUND1_20_TO_39(a,b,c,d,e);
-	ROUND1_20_TO_39(e,a,b,c,d);
-	ROUND1_20_TO_39(d,e,a,b,c);
-	ROUND1_20_TO_39(c,d,e,a,b);
-	ROUND1_20_TO_39(b,c,d,e,a);
-	ROUND1_20_TO_39(a,b,c,d,e);
-	ROUND1_20_TO_39(e,a,b,c,d);
-	ROUND1_20_TO_39(d,e,a,b,c);
-	ROUND1_20_TO_39(c,d,e,a,b);
-	ROUND1_20_TO_39(b,c,d,e,a);
-	ROUND1_20_TO_39(a,b,c,d,e);
-	ROUND1_20_TO_39(e,a,b,c,d);
-	ROUND1_20_TO_39(d,e,a,b,c);
-	ROUND1_20_TO_39(c,d,e,a,b);
-	ROUND1_20_TO_39(b,c,d,e,a);
-
-	/* Rounds 40 to 59 unrolled: */
-	ROUND1_40_TO_59(a,b,c,d,e);
-	ROUND1_40_TO_59(e,a,b,c,d);
-	ROUND1_40_TO_59(d,e,a,b,c);
-	ROUND1_40_TO_59(c,d,e,a,b);
-	ROUND1_40_TO_59(b,c,d,e,a);
-	ROUND1_40_TO_59(a,b,c,d,e);
-	ROUND1_40_TO_59(e,a,b,c,d);
-	ROUND1_40_TO_59(d,e,a,b,c);
-	ROUND1_40_TO_59(c,d,e,a,b);
-	ROUND1_40_TO_59(b,c,d,e,a);
-	ROUND1_40_TO_59(a,b,c,d,e);
-	ROUND1_40_TO_59(e,a,b,c,d);
-	ROUND1_40_TO_59(d,e,a,b,c);
-	ROUND1_40_TO_59(c,d,e,a,b);
-	ROUND1_40_TO_59(b,c,d,e,a);
-	ROUND1_40_TO_59(a,b,c,d,e);
-	ROUND1_40_TO_59(e,a,b,c,d);
-	ROUND1_40_TO_59(d,e,a,b,c);
-	ROUND1_40_TO_59(c,d,e,a,b);
-	ROUND1_40_TO_59(b,c,d,e,a);
-
-	/* Rounds 60 to 79 unrolled: */
-	ROUND1_60_TO_79(a,b,c,d,e);
-	ROUND1_60_TO_79(e,a,b,c,d);
-	ROUND1_60_TO_79(d,e,a,b,c);
-	ROUND1_60_TO_79(c,d,e,a,b);
-	ROUND1_60_TO_79(b,c,d,e,a);
-	ROUND1_60_TO_79(a,b,c,d,e);
-	ROUND1_60_TO_79(e,a,b,c,d);
-	ROUND1_60_TO_79(d,e,a,b,c);
-	ROUND1_60_TO_79(c,d,e,a,b);
-	ROUND1_60_TO_79(b,c,d,e,a);
-	ROUND1_60_TO_79(a,b,c,d,e);
-	ROUND1_60_TO_79(e,a,b,c,d);
-	ROUND1_60_TO_79(d,e,a,b,c);
-	ROUND1_60_TO_79(c,d,e,a,b);
-	ROUND1_60_TO_79(b,c,d,e,a);
-	ROUND1_60_TO_79(a,b,c,d,e);
-	ROUND1_60_TO_79(e,a,b,c,d);
-	ROUND1_60_TO_79(d,e,a,b,c);
-	ROUND1_60_TO_79(c,d,e,a,b);
-	ROUND1_60_TO_79(b,c,d,e,a);
-
-	/* Compute the current intermediate hash value */
-	context->s1.state[0] += a;
-	context->s1.state[1] += b;
-	context->s1.state[2] += c;
-	context->s1.state[3] += d;
-	context->s1.state[4] += e;
-
-	/* Clean up */
-	a = b = c = d = e = T1 = 0;
-}
-
-#else  /* SHA2_UNROLL_TRANSFORM */
-
-void SHA1_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
-	sha_word32	a, b, c, d, e;
-	sha_word32	T1, *W1;
-	int		j;
-
-	W1 = (sha_word32*)context->s1.buffer;
-
-	/* Initialize registers with the prev. intermediate value */
-	a = context->s1.state[0];
-	b = context->s1.state[1];
-	c = context->s1.state[2];
-	d = context->s1.state[3];
-	e = context->s1.state[4];
-	j = 0;
-	do {
-#if BYTE_ORDER == LITTLE_ENDIAN
-		T1 = data[j];
-		/* Copy data while converting to host byte order */
-		REVERSE32(*data++, W1[j]);
-		T1 = ROTL32(5, a) + Ch(b, c, d) + e + K1_0_TO_19 + W1[j];
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
-		T1 = ROTL32(5, a) + Ch(b, c, d) + e + K1_0_TO_19 + (W1[j] = *data++);
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-		e = d;
-		d = c;
-		c = ROTL32(30, b);
-		b = a;
-		a = T1;
-		j++;
-	} while (j < 16);
-
-	do {
-		T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
-		T1 = ROTL32(5, a) + Ch(b,c,d) + e + K1_0_TO_19 + (W1[j&0x0f] = ROTL32(1, T1));
-		e = d;
-		d = c;
-		c = ROTL32(30, b);
-		b = a;
-		a = T1;
-		j++;
-	} while (j < 20);
-
-	do {
-		T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
-		T1 = ROTL32(5, a) + Parity(b,c,d) + e + K1_20_TO_39 + (W1[j&0x0f] = ROTL32(1, T1));
-		e = d;
-		d = c;
-		c = ROTL32(30, b);
-		b = a;
-		a = T1;
-		j++;
-	} while (j < 40);
-
-	do {
-		T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
-		T1 = ROTL32(5, a) + Maj(b,c,d) + e + K1_40_TO_59 + (W1[j&0x0f] = ROTL32(1, T1));
-		e = d;
-		d = c;
-		c = ROTL32(30, b);
-		b = a;
-		a = T1;
-		j++;
-	} while (j < 60);
-
-	do {
-		T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
-		T1 = ROTL32(5, a) + Parity(b,c,d) + e + K1_60_TO_79 + (W1[j&0x0f] = ROTL32(1, T1));
-		e = d;
-		d = c;
-		c = ROTL32(30, b);
-		b = a;
-		a = T1;
-		j++;
-	} while (j < 80);
-
-
-	/* Compute the current intermediate hash value */
-	context->s1.state[0] += a;
-	context->s1.state[1] += b;
-	context->s1.state[2] += c;
-	context->s1.state[3] += d;
-	context->s1.state[4] += e;
-
-	/* Clean up */
-	a = b = c = d = e = T1 = 0;
-}
-
-#endif /* SHA2_UNROLL_TRANSFORM */
-
-void SHA1_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
-	unsigned int	freespace, usedspace;
-	if (len == 0) {
-		/* Calling with no data is valid - we do nothing */
-		return;
-	}
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0 && data != (sha_byte*)0);
-
-	usedspace = (unsigned int)((context->s1.bitcount >> 3) % 64);
-	if (usedspace > 0) {
-		/* Calculate how much free space is available in the buffer */
-		freespace = 64 - usedspace;
-
-		if (len >= freespace) {
-			/* Fill the buffer completely and process it */
-			MEMCPY_BCOPY(&context->s1.buffer[usedspace], data, freespace);
-			context->s1.bitcount += freespace << 3;
-			len -= freespace;
-			data += freespace;
-			SHA1_Internal_Transform(context, (const sha_word32*)context->s1.buffer);
-		} else {
-			/* The buffer is not yet full */
-			MEMCPY_BCOPY(&context->s1.buffer[usedspace], data, len);
-			context->s1.bitcount += len << 3;
-			/* Clean up: */
-			usedspace = freespace = 0;
-			return;
-		}
-	}
-	while (len >= 64) {
-		/* Process as many complete blocks as we can */
-		SHA1_Internal_Transform(context, (const sha_word32*)data);
-		context->s1.bitcount += 512;
-		len -= 64;
-		data += 64;
-	}
-	if (len > 0) {
-		/* There's left-overs, so save 'em */
-		MEMCPY_BCOPY(context->s1.buffer, data, len);
-		context->s1.bitcount += len << 3;
-	}
-	/* Clean up: */
-	usedspace = freespace = 0;
-}
-
-void SHA1_Final(sha_byte digest[], SHA_CTX* context) {
-	sha_word32	*d = (sha_word32*)digest;
-	unsigned int	usedspace;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	if (digest == (sha_byte*)0) {
-		/*
-		 * No digest buffer, so we can do nothing
-		 * except clean up and go home
-		 */
-		MEMSET_BZERO(context, sizeof(*context));
-		return;
-	}
-
-	usedspace = (unsigned int)((context->s1.bitcount >> 3) % 64);
-	if (usedspace == 0) {
-		/* Set-up for the last transform: */
-		MEMSET_BZERO(context->s1.buffer, 56);
-
-		/* Begin padding with a 1 bit: */
-		*context->s1.buffer = 0x80;
-	} else {
-		/* Begin padding with a 1 bit: */
-		context->s1.buffer[usedspace++] = 0x80;
-
-		if (usedspace <= 56) {
-			/* Set-up for the last transform: */
-			MEMSET_BZERO(&context->s1.buffer[usedspace], 56 - usedspace);
-		} else {
-			if (usedspace < 64) {
-				MEMSET_BZERO(&context->s1.buffer[usedspace], 64 - usedspace);
-			}
-			/* Do second-to-last transform: */
-			SHA1_Internal_Transform(context, (const sha_word32*)context->s1.buffer);
-
-			/* And set-up for the last transform: */
-			MEMSET_BZERO(context->s1.buffer, 56);
-		}
-		/* Clean up: */
-		usedspace = 0;
-	}
-	/* Set the bit count: */
-#if BYTE_ORDER == LITTLE_ENDIAN
-	/* Convert FROM host byte order */
-	REVERSE64(context->s1.bitcount,context->s1.bitcount);
-#endif
-	MEMCPY_BCOPY(&context->s1.buffer[56], &context->s1.bitcount,
-		     sizeof(sha_word64));
-
-	/* Final transform: */
-	SHA1_Internal_Transform(context, (const sha_word32*)context->s1.buffer);
-
-	/* Save the hash data for output: */
-#if BYTE_ORDER == LITTLE_ENDIAN
-	{
-		/* Convert TO host byte order */
-		int	j;
-		for (j = 0; j < (SHA1_DIGEST_LENGTH >> 2); j++) {
-			REVERSE32(context->s1.state[j],context->s1.state[j]);
-			*d++ = context->s1.state[j];
-		}
-	}
-#else
-	MEMCPY_BCOPY(d, context->s1.state, SHA1_DIGEST_LENGTH);
-#endif
-
-	/* Clean up: */
-	MEMSET_BZERO(context, sizeof(*context));
-}
-
-char *SHA1_End(SHA_CTX* context, char buffer[]) {
-	sha_byte	digest[SHA1_DIGEST_LENGTH], *d = digest;
-	int		i;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	if (buffer != (char*)0) {
-		SHA1_Final(digest, context);
-
-		for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
-			*buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
-			*buffer++ = sha_hex_digits[*d & 0x0f];
-			d++;
-		}
-		*buffer = (char)0;
-	} else {
-		MEMSET_BZERO(context, sizeof(*context));
-	}
-	MEMSET_BZERO(digest, SHA1_DIGEST_LENGTH);
-	return buffer;
-}
-
-char* SHA1_Data(const sha_byte* data, size_t len, char digest[SHA1_DIGEST_STRING_LENGTH]) {
-	SHA_CTX	context;
-
-	SHA1_Init(&context);
-	SHA1_Update(&context, data, len);
-	return SHA1_End(&context, digest);
-}
-
-
-/*** SHA-256: *********************************************************/
-void SHA256_Internal_Init(SHA_CTX* context, const sha_word32* ihv) {
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	MEMCPY_BCOPY(context->s256.state, ihv, sizeof(sha_word32) * 8);
-	MEMSET_BZERO(context->s256.buffer, 64);
-	context->s256.bitcount = 0;
-}
-
-void SHA256_Init(SHA_CTX* context) {
-	SHA256_Internal_Init(context, sha256_initial_hash_value);
-}
-
-#ifdef SHA2_UNROLL_TRANSFORM
-
-/* Unrolled SHA-256 round macros: */
-
-#if BYTE_ORDER == LITTLE_ENDIAN
-
-#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h)	\
-	REVERSE32(*data++, W256[j]); \
-	T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
-	     K256[j] + W256[j]; \
-	(d) += T1; \
-	(h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
-	j++
-
-
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
-
-#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h)	\
-	T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
-	     K256[j] + (W256[j] = *data++); \
-	(d) += T1; \
-	(h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
-	j++
-
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-
-#define ROUND256(a,b,c,d,e,f,g,h)	\
-	s0 = W256[(j+1)&0x0f]; \
-	s0 = sigma0_256(s0); \
-	s1 = W256[(j+14)&0x0f]; \
-	s1 = sigma1_256(s1); \
-	T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + K256[j] + \
-	     (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \
-	(d) += T1; \
-	(h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
-	j++
-
-void SHA256_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
-	sha_word32	a, b, c, d, e, f, g, h, s0, s1;
-	sha_word32	T1, *W256;
-	int		j;
-
-	W256 = (sha_word32*)context->s256.buffer;
-
-	/* Initialize registers with the prev. intermediate value */
-	a = context->s256.state[0];
-	b = context->s256.state[1];
-	c = context->s256.state[2];
-	d = context->s256.state[3];
-	e = context->s256.state[4];
-	f = context->s256.state[5];
-	g = context->s256.state[6];
-	h = context->s256.state[7];
-
-	j = 0;
-	do {
-		/* Rounds 0 to 15 (unrolled): */
-		ROUND256_0_TO_15(a,b,c,d,e,f,g,h);
-		ROUND256_0_TO_15(h,a,b,c,d,e,f,g);
-		ROUND256_0_TO_15(g,h,a,b,c,d,e,f);
-		ROUND256_0_TO_15(f,g,h,a,b,c,d,e);
-		ROUND256_0_TO_15(e,f,g,h,a,b,c,d);
-		ROUND256_0_TO_15(d,e,f,g,h,a,b,c);
-		ROUND256_0_TO_15(c,d,e,f,g,h,a,b);
-		ROUND256_0_TO_15(b,c,d,e,f,g,h,a);
-	} while (j < 16);
-
-	/* Now for the remaining rounds to 64: */
-	do {
-		ROUND256(a,b,c,d,e,f,g,h);
-		ROUND256(h,a,b,c,d,e,f,g);
-		ROUND256(g,h,a,b,c,d,e,f);
-		ROUND256(f,g,h,a,b,c,d,e);
-		ROUND256(e,f,g,h,a,b,c,d);
-		ROUND256(d,e,f,g,h,a,b,c);
-		ROUND256(c,d,e,f,g,h,a,b);
-		ROUND256(b,c,d,e,f,g,h,a);
-	} while (j < 64);
-
-	/* Compute the current intermediate hash value */
-	context->s256.state[0] += a;
-	context->s256.state[1] += b;
-	context->s256.state[2] += c;
-	context->s256.state[3] += d;
-	context->s256.state[4] += e;
-	context->s256.state[5] += f;
-	context->s256.state[6] += g;
-	context->s256.state[7] += h;
-
-	/* Clean up */
-	a = b = c = d = e = f = g = h = T1 = 0;
-}
-
-#else /* SHA2_UNROLL_TRANSFORM */
-
-void SHA256_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
-	sha_word32	a, b, c, d, e, f, g, h, s0, s1;
-	sha_word32	T1, T2, *W256;
-	int		j;
-
-	W256 = (sha_word32*)context->s256.buffer;
-
-	/* Initialize registers with the prev. intermediate value */
-	a = context->s256.state[0];
-	b = context->s256.state[1];
-	c = context->s256.state[2];
-	d = context->s256.state[3];
-	e = context->s256.state[4];
-	f = context->s256.state[5];
-	g = context->s256.state[6];
-	h = context->s256.state[7];
-
-	j = 0;
-	do {
-#if BYTE_ORDER == LITTLE_ENDIAN
-		/* Copy data while converting to host byte order */
-		REVERSE32(*data++,W256[j]);
-		/* Apply the SHA-256 compression function to update a..h */
-		T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j];
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
-		/* Apply the SHA-256 compression function to update a..h with copy */
-		T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j] = *data++);
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-		T2 = Sigma0_256(a) + Maj(a, b, c);
-		h = g;
-		g = f;
-		f = e;
-		e = d + T1;
-		d = c;
-		c = b;
-		b = a;
-		a = T1 + T2;
-
-		j++;
-	} while (j < 16);
-
-	do {
-		/* Part of the message block expansion: */
-		s0 = W256[(j+1)&0x0f];
-		s0 = sigma0_256(s0);
-		s1 = W256[(j+14)&0x0f];
-		s1 = sigma1_256(s1);
-
-		/* Apply the SHA-256 compression function to update a..h */
-		T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
-		     (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
-		T2 = Sigma0_256(a) + Maj(a, b, c);
-		h = g;
-		g = f;
-		f = e;
-		e = d + T1;
-		d = c;
-		c = b;
-		b = a;
-		a = T1 + T2;
-
-		j++;
-	} while (j < 64);
-
-	/* Compute the current intermediate hash value */
-	context->s256.state[0] += a;
-	context->s256.state[1] += b;
-	context->s256.state[2] += c;
-	context->s256.state[3] += d;
-	context->s256.state[4] += e;
-	context->s256.state[5] += f;
-	context->s256.state[6] += g;
-	context->s256.state[7] += h;
-
-	/* Clean up */
-	a = b = c = d = e = f = g = h = T1 = T2 = 0;
-}
-
-#endif /* SHA2_UNROLL_TRANSFORM */
-
-void SHA256_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
-	unsigned int	freespace, usedspace;
-
-	if (len == 0) {
-		/* Calling with no data is valid - we do nothing */
-		return;
-	}
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0 && data != (sha_byte*)0);
-
-	usedspace = (unsigned int)((context->s256.bitcount >> 3) % 64);
-	if (usedspace > 0) {
-		/* Calculate how much free space is available in the buffer */
-		freespace = 64 - usedspace;
-
-		if (len >= freespace) {
-			/* Fill the buffer completely and process it */
-			MEMCPY_BCOPY(&context->s256.buffer[usedspace], data, freespace);
-			context->s256.bitcount += freespace << 3;
-			len -= freespace;
-			data += freespace;
-			SHA256_Internal_Transform(context, (const sha_word32*)context->s256.buffer);
-		} else {
-			/* The buffer is not yet full */
-			MEMCPY_BCOPY(&context->s256.buffer[usedspace], data, len);
-			context->s256.bitcount += len << 3;
-			/* Clean up: */
-			usedspace = freespace = 0;
-			return;
-		}
-	}
-	while (len >= 64) {
-		/* Process as many complete blocks as we can */
-		SHA256_Internal_Transform(context, (const sha_word32*)data);
-		context->s256.bitcount += 512;
-		len -= 64;
-		data += 64;
-	}
-	if (len > 0) {
-		/* There's left-overs, so save 'em */
-		MEMCPY_BCOPY(context->s256.buffer, data, len);
-		context->s256.bitcount += len << 3;
-	}
-	/* Clean up: */
-	usedspace = freespace = 0;
-}
-
-void SHA256_Internal_Last(SHA_CTX* context) {
-	unsigned int	usedspace;
-
-	usedspace = (unsigned int)((context->s256.bitcount >> 3) % 64);
-#if BYTE_ORDER == LITTLE_ENDIAN
-	/* Convert FROM host byte order */
-	REVERSE64(context->s256.bitcount,context->s256.bitcount);
-#endif
-	if (usedspace > 0) {
-		/* Begin padding with a 1 bit: */
-		context->s256.buffer[usedspace++] = 0x80;
-
-		if (usedspace <= 56) {
-			/* Set-up for the last transform: */
-			MEMSET_BZERO(&context->s256.buffer[usedspace], 56 - usedspace);
-		} else {
-			if (usedspace < 64) {
-				MEMSET_BZERO(&context->s256.buffer[usedspace], 64 - usedspace);
-			}
-			/* Do second-to-last transform: */
-			SHA256_Internal_Transform(context, (const sha_word32*)context->s256.buffer);
-
-			/* And set-up for the last transform: */
-			MEMSET_BZERO(context->s256.buffer, 56);
-		}
-		/* Clean up: */
-		usedspace = 0;
-	} else {
-		/* Set-up for the last transform: */
-		MEMSET_BZERO(context->s256.buffer, 56);
-
-		/* Begin padding with a 1 bit: */
-		*context->s256.buffer = 0x80;
-	}
-	/* Set the bit count: */
-	MEMCPY_BCOPY(&context->s256.buffer[56], &context->s256.bitcount,
-		     sizeof(sha_word64));
-
-	/* Final transform: */
-	SHA256_Internal_Transform(context, (const sha_word32*)context->s256.buffer);
-}
-
-void SHA256_Final(sha_byte digest[], SHA_CTX* context) {
-	sha_word32	*d = (sha_word32*)digest;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	/* If no digest buffer is passed, we don't bother doing this: */
-	if (digest != (sha_byte*)0) {
-		SHA256_Internal_Last(context);
-
-		/* Save the hash data for output: */
-#if BYTE_ORDER == LITTLE_ENDIAN
-		{
-			/* Convert TO host byte order */
-			int	j;
-			for (j = 0; j < (SHA256_DIGEST_LENGTH >> 2); j++) {
-				REVERSE32(context->s256.state[j],context->s256.state[j]);
-				*d++ = context->s256.state[j];
-			}
-		}
-#else
-		MEMCPY_BCOPY(d, context->s256.state, SHA256_DIGEST_LENGTH);
-#endif
-	}
-
-	/* Clean up state data: */
-	MEMSET_BZERO(context, sizeof(*context));
-}
-
-char *SHA256_End(SHA_CTX* context, char buffer[]) {
-	sha_byte	digest[SHA256_DIGEST_LENGTH], *d = digest;
-	int		i;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	if (buffer != (char*)0) {
-		SHA256_Final(digest, context);
-
-		for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
-			*buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
-			*buffer++ = sha_hex_digits[*d & 0x0f];
-			d++;
-		}
-		*buffer = (char)0;
-	} else {
-		MEMSET_BZERO(context, sizeof(*context));
-	}
-	MEMSET_BZERO(digest, SHA256_DIGEST_LENGTH);
-	return buffer;
-}
-
-char* SHA256_Data(const sha_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH]) {
-	SHA_CTX	context;
-
-	SHA256_Init(&context);
-	SHA256_Update(&context, data, len);
-	return SHA256_End(&context, digest);
-}
-
-
-/*** SHA-224: *********************************************************/
-void SHA224_Init(SHA_CTX* context) {
-	SHA256_Internal_Init(context, sha224_initial_hash_value);
-}
-
-void SHA224_Internal_Transform(SHA_CTX* context, const sha_word32* data) {
-	SHA256_Internal_Transform(context, data);
-}
-
-void SHA224_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
-	SHA256_Update(context, data, len);
-}
-
-void SHA224_Final(sha_byte digest[], SHA_CTX* context) {
-	sha_word32	*d = (sha_word32*)digest;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	/* If no digest buffer is passed, we don't bother doing this: */
-	if (digest != (sha_byte*)0) {
-		SHA256_Internal_Last(context);
-
-		/* Save the hash data for output: */
-#if BYTE_ORDER == LITTLE_ENDIAN
-		{
-			/* Convert TO host byte order */
-			int	j;
-			for (j = 0; j < (SHA224_DIGEST_LENGTH >> 2); j++) {
-				REVERSE32(context->s256.state[j],context->s256.state[j]);
-				*d++ = context->s256.state[j];
-			}
-		}
-#else
-		MEMCPY_BCOPY(d, context->s256.state, SHA224_DIGEST_LENGTH);
-#endif
-	}
-
-	/* Clean up state data: */
-	MEMSET_BZERO(context, sizeof(*context));
-}
-
-char *SHA224_End(SHA_CTX* context, char buffer[]) {
-	sha_byte	digest[SHA224_DIGEST_LENGTH], *d = digest;
-	int		i;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	if (buffer != (char*)0) {
-		SHA224_Final(digest, context);
-
-		for (i = 0; i < SHA224_DIGEST_LENGTH; i++) {
-			*buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
-			*buffer++ = sha_hex_digits[*d & 0x0f];
-			d++;
-		}
-		*buffer = (char)0;
-	} else {
-		MEMSET_BZERO(context, sizeof(*context));
-	}
-	MEMSET_BZERO(digest, SHA224_DIGEST_LENGTH);
-	return buffer;
-}
-
-char* SHA224_Data(const sha_byte* data, size_t len, char digest[SHA224_DIGEST_STRING_LENGTH]) {
-	SHA_CTX	context;
-
-	SHA224_Init(&context);
-	SHA224_Update(&context, data, len);
-	return SHA224_End(&context, digest);
-}
-
-
-/*** SHA-512: *********************************************************/
-void SHA512_Internal_Init(SHA_CTX* context, const sha_word64* ihv) {
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	MEMCPY_BCOPY(context->s512.state, ihv, sizeof(sha_word64) * 8);
-	MEMSET_BZERO(context->s512.buffer, 128);
-	context->s512.bitcount[0] = context->s512.bitcount[1] =  0;
-}
-
-void SHA512_Init(SHA_CTX* context) {
-	SHA512_Internal_Init(context, sha512_initial_hash_value);
-}
-
-#ifdef SHA2_UNROLL_TRANSFORM
-
-/* Unrolled SHA-512 round macros: */
-#if BYTE_ORDER == LITTLE_ENDIAN
-
-#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h)	\
-	REVERSE64(*data++, W512[j]); \
-	T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
-	     K512[j] + W512[j]; \
-	(d) += T1, \
-	(h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)), \
-	j++
-
-
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
-
-#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h)	\
-	T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
-	     K512[j] + (W512[j] = *data++); \
-	(d) += T1; \
-	(h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
-	j++
-
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-
-#define ROUND512(a,b,c,d,e,f,g,h)	\
-	s0 = W512[(j+1)&0x0f]; \
-	s0 = sigma0_512(s0); \
-	s1 = W512[(j+14)&0x0f]; \
-	s1 = sigma1_512(s1); \
-	T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + K512[j] + \
-	     (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); \
-	(d) += T1; \
-	(h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
-	j++
-
-void SHA512_Internal_Transform(SHA_CTX* context, const sha_word64* data) {
-	sha_word64	a, b, c, d, e, f, g, h, s0, s1;
-	sha_word64	T1, *W512 = (sha_word64*)context->s512.buffer;
-	int		j;
-
-	/* Initialize registers with the prev. intermediate value */
-	a = context->s512.state[0];
-	b = context->s512.state[1];
-	c = context->s512.state[2];
-	d = context->s512.state[3];
-	e = context->s512.state[4];
-	f = context->s512.state[5];
-	g = context->s512.state[6];
-	h = context->s512.state[7];
-
-	j = 0;
-	do {
-		ROUND512_0_TO_15(a,b,c,d,e,f,g,h);
-		ROUND512_0_TO_15(h,a,b,c,d,e,f,g);
-		ROUND512_0_TO_15(g,h,a,b,c,d,e,f);
-		ROUND512_0_TO_15(f,g,h,a,b,c,d,e);
-		ROUND512_0_TO_15(e,f,g,h,a,b,c,d);
-		ROUND512_0_TO_15(d,e,f,g,h,a,b,c);
-		ROUND512_0_TO_15(c,d,e,f,g,h,a,b);
-		ROUND512_0_TO_15(b,c,d,e,f,g,h,a);
-	} while (j < 16);
-
-	/* Now for the remaining rounds up to 79: */
-	do {
-		ROUND512(a,b,c,d,e,f,g,h);
-		ROUND512(h,a,b,c,d,e,f,g);
-		ROUND512(g,h,a,b,c,d,e,f);
-		ROUND512(f,g,h,a,b,c,d,e);
-		ROUND512(e,f,g,h,a,b,c,d);
-		ROUND512(d,e,f,g,h,a,b,c);
-		ROUND512(c,d,e,f,g,h,a,b);
-		ROUND512(b,c,d,e,f,g,h,a);
-	} while (j < 80);
-
-	/* Compute the current intermediate hash value */
-	context->s512.state[0] += a;
-	context->s512.state[1] += b;
-	context->s512.state[2] += c;
-	context->s512.state[3] += d;
-	context->s512.state[4] += e;
-	context->s512.state[5] += f;
-	context->s512.state[6] += g;
-	context->s512.state[7] += h;
-
-	/* Clean up */
-	a = b = c = d = e = f = g = h = T1 = 0;
-}
-
-#else /* SHA2_UNROLL_TRANSFORM */
-
-void SHA512_Internal_Transform(SHA_CTX* context, const sha_word64* data) {
-	sha_word64	a, b, c, d, e, f, g, h, s0, s1;
-	sha_word64	T1, T2, *W512 = (sha_word64*)context->s512.buffer;
-	int		j;
-
-	/* Initialize registers with the prev. intermediate value */
-	a = context->s512.state[0];
-	b = context->s512.state[1];
-	c = context->s512.state[2];
-	d = context->s512.state[3];
-	e = context->s512.state[4];
-	f = context->s512.state[5];
-	g = context->s512.state[6];
-	h = context->s512.state[7];
-
-	j = 0;
-	do {
-#if BYTE_ORDER == LITTLE_ENDIAN
-		/* Convert TO host byte order */
-		REVERSE64(*data++, W512[j]);
-		/* Apply the SHA-512 compression function to update a..h */
-		T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
-		/* Apply the SHA-512 compression function to update a..h with copy */
-		T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] = *data++);
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-		T2 = Sigma0_512(a) + Maj(a, b, c);
-		h = g;
-		g = f;
-		f = e;
-		e = d + T1;
-		d = c;
-		c = b;
-		b = a;
-		a = T1 + T2;
-
-		j++;
-	} while (j < 16);
-
-	do {
-		/* Part of the message block expansion: */
-		s0 = W512[(j+1)&0x0f];
-		s0 = sigma0_512(s0);
-		s1 = W512[(j+14)&0x0f];
-		s1 =  sigma1_512(s1);
-
-		/* Apply the SHA-512 compression function to update a..h */
-		T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] +
-		     (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0);
-		T2 = Sigma0_512(a) + Maj(a, b, c);
-		h = g;
-		g = f;
-		f = e;
-		e = d + T1;
-		d = c;
-		c = b;
-		b = a;
-		a = T1 + T2;
-
-		j++;
-	} while (j < 80);
-
-	/* Compute the current intermediate hash value */
-	context->s512.state[0] += a;
-	context->s512.state[1] += b;
-	context->s512.state[2] += c;
-	context->s512.state[3] += d;
-	context->s512.state[4] += e;
-	context->s512.state[5] += f;
-	context->s512.state[6] += g;
-	context->s512.state[7] += h;
-
-	/* Clean up */
-	a = b = c = d = e = f = g = h = T1 = T2 = 0;
-}
-
-#endif /* SHA2_UNROLL_TRANSFORM */
-
-void SHA512_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
-	unsigned int	freespace, usedspace;
-
-	if (len == 0) {
-		/* Calling with no data is valid - we do nothing */
-		return;
-	}
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0 && data != (sha_byte*)0);
-
-	usedspace = (unsigned int)((context->s512.bitcount[0] >> 3) % 128);
-	if (usedspace > 0) {
-		/* Calculate how much free space is available in the buffer */
-		freespace = 128 - usedspace;
-
-		if (len >= freespace) {
-			/* Fill the buffer completely and process it */
-			MEMCPY_BCOPY(&context->s512.buffer[usedspace], data, freespace);
-			ADDINC128(context->s512.bitcount, freespace << 3);
-			len -= freespace;
-			data += freespace;
-			SHA512_Internal_Transform(context, (const sha_word64*)context->s512.buffer);
-		} else {
-			/* The buffer is not yet full */
-			MEMCPY_BCOPY(&context->s512.buffer[usedspace], data, len);
-			ADDINC128(context->s512.bitcount, len << 3);
-			/* Clean up: */
-			usedspace = freespace = 0;
-			return;
-		}
-	}
-	while (len >= 128) {
-		/* Process as many complete blocks as we can */
-		SHA512_Internal_Transform(context, (const sha_word64*)data);
-		ADDINC128(context->s512.bitcount, 1024);
-		len -= 128;
-		data += 128;
-	}
-	if (len > 0) {
-		/* There's left-overs, so save 'em */
-		MEMCPY_BCOPY(context->s512.buffer, data, len);
-		ADDINC128(context->s512.bitcount, len << 3);
-	}
-	/* Clean up: */
-	usedspace = freespace = 0;
-}
-
-void SHA512_Internal_Last(SHA_CTX* context) {
-	unsigned int	usedspace;
-
-	usedspace = (unsigned int)((context->s512.bitcount[0] >> 3) % 128);
-#if BYTE_ORDER == LITTLE_ENDIAN
-	/* Convert FROM host byte order */
-	REVERSE64(context->s512.bitcount[0],context->s512.bitcount[0]);
-	REVERSE64(context->s512.bitcount[1],context->s512.bitcount[1]);
-#endif
-	if (usedspace > 0) {
-		/* Begin padding with a 1 bit: */
-		context->s512.buffer[usedspace++] = 0x80;
-
-		if (usedspace <= 112) {
-			/* Set-up for the last transform: */
-			MEMSET_BZERO(&context->s512.buffer[usedspace], 112 - usedspace);
-		} else {
-			if (usedspace < 128) {
-				MEMSET_BZERO(&context->s512.buffer[usedspace], 128 - usedspace);
-			}
-			/* Do second-to-last transform: */
-			SHA512_Internal_Transform(context, (const sha_word64*)context->s512.buffer);
-
-			/* And set-up for the last transform: */
-			MEMSET_BZERO(context->s512.buffer, 112);
-		}
-		/* Clean up: */
-		usedspace = 0;
-	} else {
-		/* Prepare for final transform: */
-		MEMSET_BZERO(context->s512.buffer, 112);
-
-		/* Begin padding with a 1 bit: */
-		*context->s512.buffer = 0x80;
-	}
-	/* Store the length of input data (in bits): */
-	MEMCPY_BCOPY(&context->s512.buffer[112], &context->s512.bitcount[1],
-		     sizeof(sha_word64));
-	MEMCPY_BCOPY(&context->s512.buffer[120], &context->s512.bitcount[0],
-		     sizeof(sha_word64));
-
-	/* Final transform: */
-	SHA512_Internal_Transform(context, (const sha_word64*)context->s512.buffer);
-}
-
-void SHA512_Final(sha_byte digest[], SHA_CTX* context) {
-	sha_word64	*d = (sha_word64*)digest;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	/* If no digest buffer is passed, we don't bother doing this: */
-	if (digest != (sha_byte*)0) {
-		SHA512_Internal_Last(context);
-
-		/* Save the hash data for output: */
-#if BYTE_ORDER == LITTLE_ENDIAN
-		{
-			/* Convert TO host byte order */
-			int	j;
-			for (j = 0; j < (SHA512_DIGEST_LENGTH >> 3); j++) {
-				REVERSE64(context->s512.state[j],context->s512.state[j]);
-				*d++ = context->s512.state[j];
-			}
-		}
-#else
-		MEMCPY_BCOPY(d, context->s512.state, SHA512_DIGEST_LENGTH);
-#endif
-	}
-
-	/* Zero out state data */
-	MEMSET_BZERO(context, sizeof(*context));
-}
-
-char *SHA512_End(SHA_CTX* context, char buffer[]) {
-	sha_byte	digest[SHA512_DIGEST_LENGTH], *d = digest;
-	int		i;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	if (buffer != (char*)0) {
-		SHA512_Final(digest, context);
-
-		for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
-			*buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
-			*buffer++ = sha_hex_digits[*d & 0x0f];
-			d++;
-		}
-		*buffer = (char)0;
-	} else {
-		MEMSET_BZERO(context, sizeof(*context));
-	}
-	MEMSET_BZERO(digest, SHA512_DIGEST_LENGTH);
-	return buffer;
-}
-
-char* SHA512_Data(const sha_byte* data, size_t len, char digest[SHA512_DIGEST_STRING_LENGTH]) {
-	SHA_CTX	context;
-
-	SHA512_Init(&context);
-	SHA512_Update(&context, data, len);
-	return SHA512_End(&context, digest);
-}
-
-
-/*** SHA-384: *********************************************************/
-void SHA384_Init(SHA_CTX* context) {
-	SHA512_Internal_Init(context, sha384_initial_hash_value);
-}
-
-void SHA384_Update(SHA_CTX* context, const sha_byte* data, size_t len) {
-	SHA512_Update(context, data, len);
-}
-
-void SHA384_Final(sha_byte digest[], SHA_CTX* context) {
-	sha_word64	*d = (sha_word64*)digest;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	/* If no digest buffer is passed, we don't bother doing this: */
-	if (digest != (sha_byte*)0) {
-		SHA512_Internal_Last(context);
-
-		/* Save the hash data for output: */
-#if BYTE_ORDER == LITTLE_ENDIAN
-		{
-			/* Convert TO host byte order */
-			int	j;
-			for (j = 0; j < (SHA384_DIGEST_LENGTH >> 3); j++) {
-				REVERSE64(context->s512.state[j],context->s512.state[j]);
-				*d++ = context->s512.state[j];
-			}
-		}
-#else
-		MEMCPY_BCOPY(d, context->s512.state, SHA384_DIGEST_LENGTH);
-#endif
-	}
-
-	/* Zero out state data */
-	MEMSET_BZERO(context, sizeof(*context));
-}
-
-char *SHA384_End(SHA_CTX* context, char buffer[]) {
-	sha_byte	digest[SHA384_DIGEST_LENGTH], *d = digest;
-	int		i;
-
-	/* Sanity check: */
-	assert(context != (SHA_CTX*)0);
-
-	if (buffer != (char*)0) {
-		SHA384_Final(digest, context);
-
-		for (i = 0; i < SHA384_DIGEST_LENGTH; i++) {
-			*buffer++ = sha_hex_digits[(*d & 0xf0) >> 4];
-			*buffer++ = sha_hex_digits[*d & 0x0f];
-			d++;
-		}
-		*buffer = (char)0;
-	} else {
-		MEMSET_BZERO(context, sizeof(*context));
-	}
-	MEMSET_BZERO(digest, SHA384_DIGEST_LENGTH);
-	return buffer;
-}
-
-char* SHA384_Data(const sha_byte* data, size_t len, char digest[SHA384_DIGEST_STRING_LENGTH]) {
-	SHA_CTX	context;
-
-	SHA384_Init(&context);
-	SHA384_Update(&context, data, len);
-	return SHA384_End(&context, digest);
-}
diff --git a/Source/cm_sha2.h b/Source/cm_sha2.h
deleted file mode 100644
index f151031..0000000
--- a/Source/cm_sha2.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * FILE:    sha2.h
- * AUTHOR:  Aaron D. Gifford
- *          http://www.aarongifford.com/computers/sha.html
- *
- * Copyright (c) 2000-2003, 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.
- *
- * $Id: sha2.h,v 1.4 2004/01/07 19:06:18 adg Exp $
- */
-
-#ifndef __SHA2_H__
-#define __SHA2_H__
-
-#include "cm_sha2_mangle.h"
-
-/* CMake modification: use integer types from KWIML.  */
-#include <cm_kwiml.h>
-typedef KWIML_INT_uint8_t cm_sha2_uint8_t;
-typedef KWIML_INT_uint32_t cm_sha2_uint32_t;
-typedef KWIML_INT_uint64_t cm_sha2_uint64_t;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*
- * Import u_intXX_t size_t type definitions from system headers.  You
- * may need to change this, or define these things yourself in this
- * file.
- */
-#include <sys/types.h>
-
-/*** SHA-224/256/384/512 Various Length Definitions *******************/
-
-/* Digest lengths for SHA-1/224/256/384/512 */
-#define   SHA1_DIGEST_LENGTH          20
-#define   SHA1_DIGEST_STRING_LENGTH  (SHA1_DIGEST_LENGTH   * 2 + 1)
-#define SHA224_DIGEST_LENGTH          28
-#define SHA224_DIGEST_STRING_LENGTH  (SHA224_DIGEST_LENGTH * 2 + 1)
-#define SHA256_DIGEST_LENGTH          32
-#define SHA256_DIGEST_STRING_LENGTH  (SHA256_DIGEST_LENGTH * 2 + 1)
-#define SHA384_DIGEST_LENGTH          48
-#define SHA384_DIGEST_STRING_LENGTH  (SHA384_DIGEST_LENGTH * 2 + 1)
-#define SHA512_DIGEST_LENGTH          64
-#define SHA512_DIGEST_STRING_LENGTH  (SHA512_DIGEST_LENGTH * 2 + 1)
-
-
-/*** SHA-224/256/384/512 Context Structures ***************************/
-
-typedef union _SHA_CTX {
-    /* SHA-1 uses this part of the union: */
-    struct {
-	cm_sha2_uint32_t state[5];
-	cm_sha2_uint64_t bitcount;
-	cm_sha2_uint8_t  buffer[64];
-    } s1;
-
-    /* SHA-224 and SHA-256 use this part of the union: */
-    struct {
-	cm_sha2_uint32_t state[8];
-	cm_sha2_uint64_t bitcount;
-	cm_sha2_uint8_t  buffer[64];
-    } s256;
-
-    /* SHA-384 and SHA-512 use this part of the union: */
-    struct {
-	cm_sha2_uint64_t state[8];
-	cm_sha2_uint64_t bitcount[2];
-	cm_sha2_uint8_t  buffer[128];
-    } s512;
-} SHA_CTX;
-
-/*** SHA-256/384/512 Function Prototypes ******************************/
-
-void SHA1_Init(SHA_CTX*);
-void SHA1_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
-void SHA1_Final(cm_sha2_uint8_t[SHA1_DIGEST_LENGTH], SHA_CTX*);
-char* SHA1_End(SHA_CTX*, char[SHA1_DIGEST_STRING_LENGTH]);
-char* SHA1_Data(const cm_sha2_uint8_t*, size_t,
-		char[SHA1_DIGEST_STRING_LENGTH]);
-
-void SHA224_Init(SHA_CTX*);
-void SHA224_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
-void SHA224_Final(cm_sha2_uint8_t[SHA224_DIGEST_LENGTH], SHA_CTX*);
-char* SHA224_End(SHA_CTX*, char[SHA224_DIGEST_STRING_LENGTH]);
-char* SHA224_Data(const cm_sha2_uint8_t*, size_t,
-		  char[SHA224_DIGEST_STRING_LENGTH]);
-
-void SHA256_Init(SHA_CTX*);
-void SHA256_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
-void SHA256_Final(cm_sha2_uint8_t[SHA256_DIGEST_LENGTH], SHA_CTX*);
-char* SHA256_End(SHA_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
-char* SHA256_Data(const cm_sha2_uint8_t*, size_t,
-		  char[SHA256_DIGEST_STRING_LENGTH]);
-
-void SHA384_Init(SHA_CTX*);
-void SHA384_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
-void SHA384_Final(cm_sha2_uint8_t[SHA384_DIGEST_LENGTH], SHA_CTX*);
-char* SHA384_End(SHA_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const cm_sha2_uint8_t*, size_t,
-		  char[SHA384_DIGEST_STRING_LENGTH]);
-
-void SHA512_Init(SHA_CTX*);
-void SHA512_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
-void SHA512_Final(cm_sha2_uint8_t[SHA512_DIGEST_LENGTH], SHA_CTX*);
-char* SHA512_End(SHA_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
-char* SHA512_Data(const cm_sha2_uint8_t*, size_t,
-		  char[SHA512_DIGEST_STRING_LENGTH]);
-
-#ifdef    __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __SHA2_H__ */
diff --git a/Source/cm_sha2_mangle.h b/Source/cm_sha2_mangle.h
deleted file mode 100644
index 3dce819..0000000
--- a/Source/cm_sha2_mangle.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cm_sha2_mangle_h
-#define cm_sha2_mangle_h
-
-/* Mangle sha2 symbol names to avoid possible conflict with
-   implementations in other libraries to which CMake links.  */
-#define SHA1_Data                  cmSHA1_Data
-#define SHA1_End                   cmSHA1_End
-#define SHA1_Final                 cmSHA1_Final
-#define SHA1_Init                  cmSHA1_Init
-#define SHA1_Internal_Transform    cmSHA1_Internal_Transform
-#define SHA1_Update                cmSHA1_Update
-#define SHA224_Data                cmSHA224_Data
-#define SHA224_End                 cmSHA224_End
-#define SHA224_Final               cmSHA224_Final
-#define SHA224_Init                cmSHA224_Init
-#define SHA224_Internal_Transform  cmSHA224_Internal_Transform
-#define SHA224_Update              cmSHA224_Update
-#define SHA256_Data                cmSHA256_Data
-#define SHA256_End                 cmSHA256_End
-#define SHA256_Final               cmSHA256_Final
-#define SHA256_Init                cmSHA256_Init
-#define SHA256_Internal_Init       cmSHA256_Internal_Init
-#define SHA256_Internal_Last       cmSHA256_Internal_Last
-#define SHA256_Internal_Transform  cmSHA256_Internal_Transform
-#define SHA256_Update              cmSHA256_Update
-#define SHA384_Data                cmSHA384_Data
-#define SHA384_End                 cmSHA384_End
-#define SHA384_Final               cmSHA384_Final
-#define SHA384_Init                cmSHA384_Init
-#define SHA384_Update              cmSHA384_Update
-#define SHA512_Data                cmSHA512_Data
-#define SHA512_End                 cmSHA512_End
-#define SHA512_Final               cmSHA512_Final
-#define SHA512_Init                cmSHA512_Init
-#define SHA512_Internal_Init       cmSHA512_Internal_Init
-#define SHA512_Internal_Last       cmSHA512_Internal_Last
-#define SHA512_Internal_Transform  cmSHA512_Internal_Transform
-#define SHA512_Update              cmSHA512_Update
-
-#endif
diff --git a/Utilities/Scripts/clang-format.bash b/Utilities/Scripts/clang-format.bash
index ad3b3a1..8e07c99 100755
--- a/Utilities/Scripts/clang-format.bash
+++ b/Utilities/Scripts/clang-format.bash
@@ -121,7 +121,7 @@ $git_ls -z -- '*.c' '*.cc' '*.cpp' '*.cxx' '*.h' '*.hh' '*.hpp' '*.hxx' |
   egrep -z -v '^Source/cmListFileLexer(\.in\.l|\.c)' |
 
   # Exclude third-party sources.
-  egrep -z -v '^Source/(cm_sha2|bindexplib)' |
+  egrep -z -v '^Source/bindexplib' |
   egrep -z -v '^Source/(kwsys|CursesDialog/form)/' |
   egrep -z -v '^Utilities/(KW|cm).*/' |
 

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5420278dc884c0382f271872b67c33978f3fe6b8
commit 5420278dc884c0382f271872b67c33978f3fe6b8
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 13:21:41 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:38 2016 -0500

    Port hash computation to cmCryptoHash
    
    Avoid using KWSys MD5 or `cm_sha2` and use the `cmCryptoHash`
    abstraction instead.

diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
index 4c8abd9..0c4f573 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -1060,8 +1060,8 @@ std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path)
 std::string cmCPackWIXGenerator::CreateHashedId(
   std::string const& path, std::string const& normalizedFilename)
 {
-  CM_AUTO_PTR<cmCryptoHash> sha1 = cmCryptoHash::New("SHA1");
-  std::string hash = sha1->HashString(path.c_str());
+  cmCryptoHash sha1(cmCryptoHash::AlgoSHA1);
+  std::string const hash = sha1.HashString(path);
 
   std::string identifier;
   identifier += hash.substr(0, 7) + "_";
diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx
index 224681a..f7a6e0b 100644
--- a/Source/CTest/cmCTestLaunch.cxx
+++ b/Source/CTest/cmCTestLaunch.cxx
@@ -4,6 +4,7 @@
 
 #include <cmConfigure.h>
 
+#include "cmCryptoHash.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGlobalGenerator.h"
 #include "cmMakefile.h"
@@ -14,7 +15,6 @@
 
 #include <cm_auto_ptr.hxx>
 #include <cmsys/FStream.hxx>
-#include <cmsys/MD5.h>
 #include <cmsys/Process.h>
 #include <cmsys/RegularExpression.hxx>
 #include <iostream>
@@ -167,17 +167,14 @@ void cmCTestLaunch::ComputeFileNames()
 
   // We hash the input command working dir and command line to obtain
   // a repeatable and (probably) unique name for log files.
-  char hash[32];
-  cmsysMD5* md5 = cmsysMD5_New();
-  cmsysMD5_Initialize(md5);
-  cmsysMD5_Append(md5, (unsigned char const*)(this->CWD.c_str()), -1);
+  cmCryptoHash md5(cmCryptoHash::AlgoMD5);
+  md5.Initialize();
+  md5.Append(this->CWD);
   for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
        ai != this->RealArgs.end(); ++ai) {
-    cmsysMD5_Append(md5, (unsigned char const*)ai->c_str(), -1);
+    md5.Append(*ai);
   }
-  cmsysMD5_FinalizeHex(md5, hash);
-  cmsysMD5_Delete(md5);
-  this->LogHash.assign(hash, 32);
+  this->LogHash = md5.FinalizeHex();
 
   // We store stdout and stderr in temporary log files.
   this->LogOut = this->LogDir;
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 1bade57..615bd23 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -2553,7 +2553,8 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
         this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5.");
         return false;
       }
-      hash = CM_AUTO_PTR<cmCryptoHash>(cmCryptoHash::New("MD5"));
+      hash =
+        CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(cmCryptoHash::AlgoMD5));
       hashMatchMSG = "MD5 sum";
       expectedHash = cmSystemTools::LowerCase(*i);
     } else if (*i == "SHOW_PROGRESS") {
diff --git a/Source/cmFilePathUuid.cxx b/Source/cmFilePathUuid.cxx
index ad434e3..03d2524 100644
--- a/Source/cmFilePathUuid.cxx
+++ b/Source/cmFilePathUuid.cxx
@@ -107,8 +107,8 @@ std::string cmFilePathUuid::GetChecksumString(
   {
     // Calculate the file ( seed + relative path + name ) checksum
     std::vector<unsigned char> hashBytes =
-      cmCryptoHash::New("SHA256")->ByteHashString(
-        sourceRelSeed + sourceRelPath + sourceFilename);
+      cmCryptoHash(cmCryptoHash::AlgoSHA256)
+        .ByteHashString(sourceRelSeed + sourceRelPath + sourceFilename);
 
     checksumBase32 =
       cmBase32Encoder().encodeString(&hashBytes[0], hashBytes.size(), false);
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index cf51c6a..42e9df1 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -44,9 +44,9 @@
 #include <string.h>
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
+#include "cmCryptoHash.h"
 #include <cm_jsoncpp_value.h>
 #include <cm_jsoncpp_writer.h>
-#include <cmsys/MD5.h>
 #endif
 
 class cmInstalledFile;
@@ -2616,14 +2616,9 @@ void cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
   // Compute a hash of the rule.
   RuleHash hash;
   {
-    unsigned char const* data =
-      reinterpret_cast<unsigned char const*>(content.c_str());
-    int length = static_cast<int>(content.length());
-    cmsysMD5* sum = cmsysMD5_New();
-    cmsysMD5_Initialize(sum);
-    cmsysMD5_Append(sum, data, length);
-    cmsysMD5_FinalizeHex(sum, hash.Data);
-    cmsysMD5_Delete(sum);
+    cmCryptoHash md5(cmCryptoHash::AlgoMD5);
+    std::string const md5_hex = md5.HashString(content);
+    memcpy(hash.Data, md5_hex.c_str(), 32);
   }
 
   // Shorten the output name (in expected use case).
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 4aecb1d..434cb10 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -26,7 +26,7 @@
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
 #define CM_LG_ENCODE_OBJECT_NAMES
-#include <cmsys/MD5.h>
+#include "cmCryptoHash.h"
 #endif
 
 #include <algorithm>
@@ -2001,17 +2001,6 @@ void cmLocalGenerator::GenerateTargetInstallRules(
 }
 
 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
-static std::string cmLocalGeneratorMD5(const char* input)
-{
-  char md5out[32];
-  cmsysMD5* md5 = cmsysMD5_New();
-  cmsysMD5_Initialize(md5);
-  cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
-  cmsysMD5_FinalizeHex(md5, md5out);
-  cmsysMD5_Delete(md5);
-  return std::string(md5out, 32);
-}
-
 static bool cmLocalGeneratorShortenObjectName(std::string& objName,
                                               std::string::size_type max_len)
 {
@@ -2020,7 +2009,8 @@ static bool cmLocalGeneratorShortenObjectName(std::string& objName,
   std::string::size_type pos =
     objName.find('/', objName.size() - max_len + 32);
   if (pos != objName.npos) {
-    std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
+    cmCryptoHash md5(cmCryptoHash::AlgoMD5);
+    std::string md5name = md5.HashString(objName.substr(0, pos));
     md5name += objName.substr(pos);
     objName = md5name;
 
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 27fecdf..7738ab6 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -847,8 +847,8 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
 bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
 {
 #if defined(CMAKE_BUILD_WITH_CMAKE)
-  CM_AUTO_PTR<cmCryptoHash> md5 = cmCryptoHash::New("MD5");
-  std::string str = md5->HashFile(source);
+  cmCryptoHash md5(cmCryptoHash::AlgoMD5);
+  std::string const str = md5.HashFile(source);
   strncpy(md5out, str.c_str(), 32);
   return !str.empty();
 #else
@@ -863,8 +863,8 @@ bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
 std::string cmSystemTools::ComputeStringMD5(const std::string& input)
 {
 #if defined(CMAKE_BUILD_WITH_CMAKE)
-  CM_AUTO_PTR<cmCryptoHash> md5 = cmCryptoHash::New("MD5");
-  return md5->HashString(input);
+  cmCryptoHash md5(cmCryptoHash::AlgoMD5);
+  return md5.HashString(input);
 #else
   (void)input;
   cmSystemTools::Message("md5sum not supported in bootstrapping mode",
diff --git a/Source/cmUuid.cxx b/Source/cmUuid.cxx
index 904bcbb..201e1cc 100644
--- a/Source/cmUuid.cxx
+++ b/Source/cmUuid.cxx
@@ -2,9 +2,8 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmUuid.h"
 
-#include "cm_sha2.h"
+#include "cmCryptoHash.h"
 
-#include <cmsys/MD5.h>
 #include <string.h>
 
 cmUuid::cmUuid()
@@ -22,16 +21,12 @@ std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace,
   std::vector<unsigned char> hashInput;
   this->CreateHashInput(uuidNamespace, name, hashInput);
 
-  cmsysMD5_s* md5 = cmsysMD5_New();
-  cmsysMD5_Initialize(md5);
-  cmsysMD5_Append(md5, &hashInput[0], int(hashInput.size()));
+  cmCryptoHash md5(cmCryptoHash::AlgoMD5);
+  md5.Initialize();
+  md5.Append(&hashInput[0], hashInput.size());
+  std::vector<unsigned char> digest = md5.Finalize();
 
-  unsigned char digest[16] = { 0 };
-  cmsysMD5_Finalize(md5, digest);
-
-  cmsysMD5_Delete(md5);
-
-  return this->FromDigest(digest, 3);
+  return this->FromDigest(&digest[0], 3);
 }
 
 std::string cmUuid::FromSha1(std::vector<unsigned char> const& uuidNamespace,
@@ -40,16 +35,12 @@ std::string cmUuid::FromSha1(std::vector<unsigned char> const& uuidNamespace,
   std::vector<unsigned char> hashInput;
   this->CreateHashInput(uuidNamespace, name, hashInput);
 
-  SHA_CTX* sha = new SHA_CTX;
-  SHA1_Init(sha);
-  SHA1_Update(sha, &hashInput[0], hashInput.size());
-
-  unsigned char digest[SHA1_DIGEST_LENGTH] = { 0 };
-  SHA1_Final(digest, sha);
-
-  delete sha;
+  cmCryptoHash sha1(cmCryptoHash::AlgoSHA1);
+  sha1.Initialize();
+  sha1.Append(&hashInput[0], hashInput.size());
+  std::vector<unsigned char> digest = sha1.Finalize();
 
-  return this->FromDigest(digest, 5);
+  return this->FromDigest(&digest[0], 5);
 }
 
 void cmUuid::CreateHashInput(std::vector<unsigned char> const& uuidNamespace,

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9a596b33bbfdb274ccf7f678c78cb8826c7c363b
commit 9a596b33bbfdb274ccf7f678c78cb8826c7c363b
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 11:33:43 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:37 2016 -0500

    cmCryptoHash: Re-implement in terms of librhash
    
    Offer direct construction with an enumeration of supported algorithms.
    Also expose the Initialize/Append/Finalize steps publicly and add a
    FinalizeHex method.

diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 9b3f84a..f440999 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -2,31 +2,62 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCryptoHash.h"
 
-#include "cm_sha2.h"
-
+#include <cm_kwiml.h>
+#include <cm_rhash.h>
 #include <cmsys/FStream.hxx>
-#include <cmsys/MD5.h>
 #include <string.h>
 
+static unsigned int const cmCryptoHashAlgoToId[] = {
+  /* clang-format needs this comment to break after the opening brace */
+  RHASH_MD5,    //
+  RHASH_SHA1,   //
+  RHASH_SHA224, //
+  RHASH_SHA256, //
+  RHASH_SHA384, //
+  RHASH_SHA512
+};
+
+static int cmCryptoHash_rhash_library_initialized;
+
+static rhash cmCryptoHash_rhash_init(unsigned int id)
+{
+  if (!cmCryptoHash_rhash_library_initialized) {
+    cmCryptoHash_rhash_library_initialized = 1;
+    rhash_library_init();
+  }
+  return rhash_init(id);
+}
+
+cmCryptoHash::cmCryptoHash(Algo algo)
+  : Id(cmCryptoHashAlgoToId[algo])
+  , CTX(cmCryptoHash_rhash_init(Id))
+{
+}
+
+cmCryptoHash::~cmCryptoHash()
+{
+  rhash_free(this->CTX);
+}
+
 CM_AUTO_PTR<cmCryptoHash> cmCryptoHash::New(const char* algo)
 {
   if (strcmp(algo, "MD5") == 0) {
-    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHashMD5);
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoMD5));
   }
   if (strcmp(algo, "SHA1") == 0) {
-    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHashSHA1);
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA1));
   }
   if (strcmp(algo, "SHA224") == 0) {
-    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHashSHA224);
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA224));
   }
   if (strcmp(algo, "SHA256") == 0) {
-    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHashSHA256);
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA256));
   }
   if (strcmp(algo, "SHA384") == 0) {
-    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHashSHA384);
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA384));
   }
   if (strcmp(algo, "SHA512") == 0) {
-    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHashSHA512);
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA512));
   }
   return CM_AUTO_PTR<cmCryptoHash>(CM_NULLPTR);
 }
@@ -80,7 +111,7 @@ std::vector<unsigned char> cmCryptoHash::ByteHashFile(const std::string& file)
     this->Initialize();
     {
       // Should be efficient enough on most system:
-      cm_sha2_uint64_t buffer[512];
+      KWIML_INT_uint64_t buffer[512];
       char* buffer_c = reinterpret_cast<char*>(buffer);
       unsigned char const* buffer_uc =
         reinterpret_cast<unsigned char const*>(buffer);
@@ -117,51 +148,29 @@ std::string cmCryptoHash::HashFile(const std::string& file)
   return ByteHashToString(this->ByteHashFile(file));
 }
 
-cmCryptoHashMD5::cmCryptoHashMD5()
-  : MD5(cmsysMD5_New())
+void cmCryptoHash::Initialize()
 {
+  rhash_reset(this->CTX);
 }
 
-cmCryptoHashMD5::~cmCryptoHashMD5()
+void cmCryptoHash::Append(void const* buf, size_t sz)
 {
-  cmsysMD5_Delete(this->MD5);
+  rhash_update(this->CTX, buf, sz);
 }
 
-void cmCryptoHashMD5::Initialize()
+void cmCryptoHash::Append(std::string const& str)
 {
-  cmsysMD5_Initialize(this->MD5);
+  this->Append(str.c_str(), str.size());
 }
 
-void cmCryptoHashMD5::Append(unsigned char const* buf, int sz)
+std::vector<unsigned char> cmCryptoHash::Finalize()
 {
-  cmsysMD5_Append(this->MD5, buf, sz);
+  std::vector<unsigned char> hash(rhash_get_digest_size(this->Id), 0);
+  rhash_final(this->CTX, &hash[0]);
+  return hash;
 }
 
-std::vector<unsigned char> cmCryptoHashMD5::Finalize()
+std::string cmCryptoHash::FinalizeHex()
 {
-  std::vector<unsigned char> hash(16, 0);
-  cmsysMD5_Finalize(this->MD5, &hash[0]);
-  return hash;
+  return cmCryptoHash::ByteHashToString(this->Finalize());
 }
-
-#define cmCryptoHash_SHA_CLASS_IMPL(SHA)                                      \
-  cmCryptoHash##SHA::cmCryptoHash##SHA()                                      \
-    : SHA(new SHA_CTX)                                                        \
-  {                                                                           \
-  }                                                                           \
-  cmCryptoHash##SHA::~cmCryptoHash##SHA() { delete this->SHA; }               \
-  void cmCryptoHash##SHA::Initialize() { SHA##_Init(this->SHA); }             \
-  void cmCryptoHash##SHA::Append(unsigned char const* buf, int sz)            \
-  {                                                                           \
-    SHA##_Update(this->SHA, buf, sz);                                         \
-  }                                                                           \
-  std::vector<unsigned char> cmCryptoHash##SHA::Finalize()                    \
-  {                                                                           \
-    std::vector<unsigned char> hash(SHA##_DIGEST_LENGTH, 0);                  \
-    SHA##_Final(&hash[0], this->SHA);                                         \
-    return hash;                                                              \
-  }
-
-cmCryptoHash_SHA_CLASS_IMPL(SHA1) cmCryptoHash_SHA_CLASS_IMPL(SHA224)
-  cmCryptoHash_SHA_CLASS_IMPL(SHA256) cmCryptoHash_SHA_CLASS_IMPL(SHA384)
-    cmCryptoHash_SHA_CLASS_IMPL(SHA512)
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 5c2d3ca..95080ac 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -15,7 +15,18 @@
 class cmCryptoHash
 {
 public:
-  virtual ~cmCryptoHash() {}
+  enum Algo
+  {
+    AlgoMD5,
+    AlgoSHA1,
+    AlgoSHA224,
+    AlgoSHA256,
+    AlgoSHA384,
+    AlgoSHA512
+  };
+
+  cmCryptoHash(Algo algo);
+  ~cmCryptoHash();
 
   /// @brief Returns a new hash generator of the requested type
   /// @arg algo Hash type name. Supported hash types are
@@ -53,47 +64,15 @@ public:
   ///         An empty string otherwise.
   std::string HashFile(const std::string& file);
 
-protected:
-  virtual void Initialize() = 0;
-  virtual void Append(unsigned char const*, int) = 0;
-  virtual std::vector<unsigned char> Finalize() = 0;
-};
-
-class cmCryptoHashMD5 : public cmCryptoHash
-{
-  struct cmsysMD5_s* MD5;
-
-public:
-  cmCryptoHashMD5();
-  ~cmCryptoHashMD5() CM_OVERRIDE;
+  void Initialize();
+  void Append(void const*, size_t);
+  void Append(std::string const& str);
+  std::vector<unsigned char> Finalize();
+  std::string FinalizeHex();
 
-protected:
-  void Initialize() CM_OVERRIDE;
-  void Append(unsigned char const* buf, int sz) CM_OVERRIDE;
-  std::vector<unsigned char> Finalize() CM_OVERRIDE;
+private:
+  unsigned int Id;
+  struct rhash_context* CTX;
 };
 
-#define cmCryptoHash_SHA_CLASS_DECL(SHA)                                      \
-  class cmCryptoHash##SHA : public cmCryptoHash                               \
-  {                                                                           \
-    union _SHA_CTX* SHA;                                                      \
-                                                                              \
-  public:                                                                     \
-    cmCryptoHash##SHA();                                                      \
-    ~cmCryptoHash##SHA();                                                     \
-                                                                              \
-  protected:                                                                  \
-    virtual void Initialize();                                                \
-    virtual void Append(unsigned char const* buf, int sz);                    \
-    virtual std::vector<unsigned char> Finalize();                            \
-  }
-
-cmCryptoHash_SHA_CLASS_DECL(SHA1);
-cmCryptoHash_SHA_CLASS_DECL(SHA224);
-cmCryptoHash_SHA_CLASS_DECL(SHA256);
-cmCryptoHash_SHA_CLASS_DECL(SHA384);
-cmCryptoHash_SHA_CLASS_DECL(SHA512);
-
-#undef cmCryptoHash_SHA_CLASS_DECL
-
 #endif

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=47f91a6183a6bb65a423d5acb1b75c4b39c17a87
commit 47f91a6183a6bb65a423d5acb1b75c4b39c17a87
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 11:30:09 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:37 2016 -0500

    cmCryptoHash: Avoid using subclasses at client sites
    
    Use only the main `cmCryptoHash` interface.

diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 0a3a1ab..27fecdf 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -847,8 +847,8 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
 bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
 {
 #if defined(CMAKE_BUILD_WITH_CMAKE)
-  cmCryptoHashMD5 md5;
-  std::string str = md5.HashFile(source);
+  CM_AUTO_PTR<cmCryptoHash> md5 = cmCryptoHash::New("MD5");
+  std::string str = md5->HashFile(source);
   strncpy(md5out, str.c_str(), 32);
   return !str.empty();
 #else
@@ -863,8 +863,8 @@ bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
 std::string cmSystemTools::ComputeStringMD5(const std::string& input)
 {
 #if defined(CMAKE_BUILD_WITH_CMAKE)
-  cmCryptoHashMD5 md5;
-  return md5.HashString(input);
+  CM_AUTO_PTR<cmCryptoHash> md5 = cmCryptoHash::New("MD5");
+  return md5->HashString(input);
 #else
   (void)input;
   cmSystemTools::Message("md5sum not supported in bootstrapping mode",

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d0ff3e701c63caab5a44c48ac70e3ab75af9ee88
commit d0ff3e701c63caab5a44c48ac70e3ab75af9ee88
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 14:04:59 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:37 2016 -0500

    librhash: Port to KWIML for ABI and integer type information

diff --git a/Utilities/cmlibrhash/librhash/byte_order.h b/Utilities/cmlibrhash/librhash/byte_order.h
index f8330e1..d34a020 100644
--- a/Utilities/cmlibrhash/librhash/byte_order.h
+++ b/Utilities/cmlibrhash/librhash/byte_order.h
@@ -4,10 +4,6 @@
 #include "ustd.h"
 #include <stdlib.h>
 
-#ifdef __GLIBC__
-# include <endian.h>
-#endif
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -32,22 +28,12 @@ extern "C" {
 
 
 /* detect CPU endianness */
-#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
-		__BYTE_ORDER == __LITTLE_ENDIAN) || \
-	defined(CPU_IA32) || defined(CPU_X64) || \
-	defined(__ia64) || defined(__ia64__) || defined(__alpha__) || defined(_M_ALPHA) || \
-	defined(vax) || defined(MIPSEL) || defined(_ARM_) || defined(__arm__)
+#include <cm_kwiml.h>
+#if KWIML_ABI_ENDIAN_ID == KWIML_ABI_ENDIAN_ID_LITTLE
 # define CPU_LITTLE_ENDIAN
 # define IS_BIG_ENDIAN 0
 # define IS_LITTLE_ENDIAN 1
-#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
-		__BYTE_ORDER == __BIG_ENDIAN) || \
-	defined(__sparc) || defined(__sparc__) || defined(sparc) || \
-	defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_POWER) || \
-	defined(__POWERPC__) || defined(POWERPC) || defined(__powerpc) || \
-	defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || \
-	defined(__hpux)  || defined(_MIPSEB) || defined(mc68000) || \
-	defined(__s390__) || defined(__s390x__) || defined(sel)
+#elif KWIML_ABI_ENDIAN_ID == KWIML_ABI_ENDIAN_ID_BIG
 # define CPU_BIG_ENDIAN
 # define IS_BIG_ENDIAN 1
 # define IS_LITTLE_ENDIAN 0
diff --git a/Utilities/cmlibrhash/librhash/ustd.h b/Utilities/cmlibrhash/librhash/ustd.h
index 5bd9aac..019b931 100644
--- a/Utilities/cmlibrhash/librhash/ustd.h
+++ b/Utilities/cmlibrhash/librhash/ustd.h
@@ -9,29 +9,31 @@
 # pragma warning(push,1)
 #endif
 
-#if _MSC_VER >= 1300
+#include <cm_kwiml.h>
 
-# define int64_t __int64
-# define int32_t __int32
-# define int16_t __int16
-# define int8_t  __int8
-# define uint64_t unsigned __int64
-# define uint32_t unsigned __int32
-# define uint16_t unsigned __int16
-# define uint8_t  unsigned __int8
-
-/* disable warnings: The POSIX name for this item is deprecated. Use the ISO C++ conformant name. */
-#pragma warning(disable : 4996)
-
-#else /* _MSC_VER >= 1300 */
-
-# include <stdint.h>
-# include <unistd.h>
-
-#endif /* _MSC_VER >= 1300 */
-
-#if _MSC_VER <= 1300
-# include <stdlib.h> /* size_t for vc6.0 */
-#endif /* _MSC_VER <= 1300 */
+#ifndef KWIML_INT_HAVE_INT64_T
+# define int64_t KWIML_INT_int64_t
+#endif
+#ifndef KWIML_INT_HAVE_INT32_T
+# define int32_t KWIML_INT_int32_t
+#endif
+#ifndef KWIML_INT_HAVE_INT16_T
+# define int16_t KWIML_INT_int16_t
+#endif
+#ifndef KWIML_INT_HAVE_INT8_T
+# define int8_t KWIML_INT_int8_t
+#endif
+#ifndef KWIML_INT_HAVE_UINT64_T
+# define uint64_t KWIML_INT_uint64_t
+#endif
+#ifndef KWIML_INT_HAVE_UINT32_T
+# define uint32_t KWIML_INT_uint32_t
+#endif
+#ifndef KWIML_INT_HAVE_UINT16_T
+# define uint16_t KWIML_INT_uint16_t
+#endif
+#ifndef KWIML_INT_HAVE_UINT8_T
+# define uint8_t KWIML_INT_uint8_t
+#endif
 
 #endif /* LIBRHASH_USTD_H */

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=465a85fb4615f4cfa20058c534bf3bfe71df1732
commit 465a85fb4615f4cfa20058c534bf3bfe71df1732
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Wed Nov 9 11:43:34 2016 -0500
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:36 2016 -0500

    librhash: Avoid signed left-shift overflow
    
    Fix `rhash_md5_final` to use unsigned integers for left shifting to
    avoid the possibility of undefined overflow behavior.

diff --git a/Utilities/cmlibrhash/librhash/md5.c b/Utilities/cmlibrhash/librhash/md5.c
index 0feb090..b20de45 100644
--- a/Utilities/cmlibrhash/librhash/md5.c
+++ b/Utilities/cmlibrhash/librhash/md5.c
@@ -213,8 +213,8 @@ void rhash_md5_final(md5_ctx *ctx, unsigned char* result)
 	/* pad message and run for last block */
 
 	/* append the byte 0x80 to the message */
-	ctx->message[index]   &= ~(0xFFFFFFFF << shift);
-	ctx->message[index++] ^= 0x80 << shift;
+	ctx->message[index]   &= ~(0xFFFFFFFFu << shift);
+	ctx->message[index++] ^= 0x80u << shift;
 
 	/* if no room left in the message to store 64-bit message length */
 	if (index > 14) {

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fc2cb74feedf2637e4b2cc153ede7b0726b9a7d3
commit fc2cb74feedf2637e4b2cc153ede7b0726b9a7d3
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Wed Nov 9 11:38:54 2016 -0500
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:36 2016 -0500

    librhash: Implement bswap_32 as a function even in strict C90 mode
    
    We cannot fall back to the macro implementation because some call sites
    may call it with an argument like `*ptr++` that has side effects.

diff --git a/Utilities/cmlibrhash/librhash/byte_order.h b/Utilities/cmlibrhash/librhash/byte_order.h
index 6ed8668..f8330e1 100644
--- a/Utilities/cmlibrhash/librhash/byte_order.h
+++ b/Utilities/cmlibrhash/librhash/byte_order.h
@@ -103,15 +103,12 @@ static inline uint32_t bswap_32(uint32_t x) {
 # define bswap_32(x) __builtin_bswap32(x)
 #elif (_MSC_VER > 1300) && (defined(CPU_IA32) || defined(CPU_X64)) /* MS VC */
 # define bswap_32(x) _byteswap_ulong((unsigned long)x)
-#elif !defined(__STRICT_ANSI__)
+#else
 /* general bswap_32 definition */
-static inline uint32_t bswap_32(uint32_t x) {
+static uint32_t bswap_32(uint32_t x) {
 	x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0x00FF00FF);
 	return (x >> 16) | (x << 16);
 }
-#else
-#define bswap_32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
-	(((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
 #endif /* bswap_32 */
 
 #if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0bd333bc2eb6590f939ccabb7caf102f13443600
commit 0bd333bc2eb6590f939ccabb7caf102f13443600
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Tue Nov 8 11:33:09 2016 -0500
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:29:36 2016 -0500

    librhash: Implement bswap_64 even in strict C90 mode

diff --git a/Utilities/cmlibrhash/librhash/byte_order.h b/Utilities/cmlibrhash/librhash/byte_order.h
index a43906c..6ed8668 100644
--- a/Utilities/cmlibrhash/librhash/byte_order.h
+++ b/Utilities/cmlibrhash/librhash/byte_order.h
@@ -120,8 +120,8 @@ static inline uint32_t bswap_32(uint32_t x) {
 # define bswap_64(x) __builtin_bswap64(x)
 #elif (_MSC_VER > 1300) && (defined(CPU_IA32) || defined(CPU_X64)) /* MS VC */
 # define bswap_64(x) _byteswap_uint64((__int64)x)
-#elif !defined(__STRICT_ANSI__)
-static inline uint64_t bswap_64(uint64_t x) {
+#else
+static uint64_t bswap_64(uint64_t x) {
 	union {
 		uint64_t ll;
 		uint32_t l[2];
@@ -131,8 +131,6 @@ static inline uint64_t bswap_64(uint64_t x) {
 	r.l[1] = bswap_32(w.l[0]);
 	return r.ll;
 }
-#else
-#error "bswap_64 unsupported"
 #endif
 
 #ifdef CPU_BIG_ENDIAN

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7189d62c32e6f53dab5637f928917e59055f5e41
commit 7189d62c32e6f53dab5637f928917e59055f5e41
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Tue Nov 8 11:32:02 2016 -0500
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:28:57 2016 -0500

    librhash: Use __builtin_bswap{32,64} on Clang

diff --git a/Utilities/cmlibrhash/librhash/byte_order.h b/Utilities/cmlibrhash/librhash/byte_order.h
index 59a6c23..a43906c 100644
--- a/Utilities/cmlibrhash/librhash/byte_order.h
+++ b/Utilities/cmlibrhash/librhash/byte_order.h
@@ -85,6 +85,10 @@ void rhash_swap_copy_str_to_u64(void* to, int index, const void* from, size_t le
 void rhash_swap_copy_u64_to_str(void* to, const void* from, size_t length);
 void rhash_u32_mem_swap(unsigned *p, int length_in_u32);
 
+#ifndef __has_builtin
+# define __has_builtin(x) 0
+#endif
+
 /* define bswap_32 */
 #if defined(__GNUC__) && defined(CPU_IA32) && !defined(__i386__)
 /* for intel x86 CPU */
@@ -95,6 +99,8 @@ static inline uint32_t bswap_32(uint32_t x) {
 #elif defined(__GNUC__)  && (__GNUC__ >= 4) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)
 /* for GCC >= 4.3 */
 # define bswap_32(x) __builtin_bswap32(x)
+#elif defined(__clang__) && __has_builtin(__builtin_bswap32)
+# define bswap_32(x) __builtin_bswap32(x)
 #elif (_MSC_VER > 1300) && (defined(CPU_IA32) || defined(CPU_X64)) /* MS VC */
 # define bswap_32(x) _byteswap_ulong((unsigned long)x)
 #elif !defined(__STRICT_ANSI__)
@@ -110,6 +116,8 @@ static inline uint32_t bswap_32(uint32_t x) {
 
 #if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)
 # define bswap_64(x) __builtin_bswap64(x)
+#elif defined(__clang__) && __has_builtin(__builtin_bswap64)
+# define bswap_64(x) __builtin_bswap64(x)
 #elif (_MSC_VER > 1300) && (defined(CPU_IA32) || defined(CPU_X64)) /* MS VC */
 # define bswap_64(x) _byteswap_uint64((__int64)x)
 #elif !defined(__STRICT_ANSI__)

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=af7ebf8ad3b2b773dfe636a189a82998b1dc63e1
commit af7ebf8ad3b2b773dfe636a189a82998b1dc63e1
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 11:26:24 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:26:55 2016 -0500

    librhash: Install COPYING file with CMake documentation
    
    When we install using the bundled librhash source, notify users of its
    license terms.

diff --git a/Utilities/cmlibrhash/CMakeLists.txt b/Utilities/cmlibrhash/CMakeLists.txt
index 968a792..340d946 100644
--- a/Utilities/cmlibrhash/CMakeLists.txt
+++ b/Utilities/cmlibrhash/CMakeLists.txt
@@ -34,3 +34,5 @@ include_directories(
   )
 
 add_library(cmlibrhash ${librhash_sources})
+
+install(FILES COPYING README DESTINATION ${CMAKE_DOC_DIR}/cmlibrhash)

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bb01f20e993bbd19b00e07ff0094b155aa0859de
commit bb01f20e993bbd19b00e07ff0094b155aa0859de
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 11:23:36 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:26:55 2016 -0500

    librhash: Disable warnings to avoid changing 3rd party code
    
    Add '-w' or equivalent flag on compilers supporting it.
    Tell MSVC to use its lowest warning level inside librhash sources.

diff --git a/Utilities/cmlibrhash/CMakeLists.txt b/Utilities/cmlibrhash/CMakeLists.txt
index 47d069a..968a792 100644
--- a/Utilities/cmlibrhash/CMakeLists.txt
+++ b/Utilities/cmlibrhash/CMakeLists.txt
@@ -1,5 +1,13 @@
 project(librhash C)
 
+# Disable warnings to avoid changing 3rd party code.
+if(CMAKE_C_COMPILER_ID MATCHES
+    "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
+elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
+endif()
+
 set(librhash_sources
   librhash/algorithms.c
   librhash/algorithms.h
diff --git a/Utilities/cmlibrhash/librhash/ustd.h b/Utilities/cmlibrhash/librhash/ustd.h
index 38c4e3e..5bd9aac 100644
--- a/Utilities/cmlibrhash/librhash/ustd.h
+++ b/Utilities/cmlibrhash/librhash/ustd.h
@@ -5,6 +5,10 @@
 /* Include KWSys Large File Support configuration. */
 #include <cmsys/Configure.h>
 
+#if defined(_MSC_VER)
+# pragma warning(push,1)
+#endif
+
 #if _MSC_VER >= 1300
 
 # define int64_t __int64

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=31bb727f3b239b541e1ff5679b3c461e9a05f227
commit 31bb727f3b239b541e1ff5679b3c461e9a05f227
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 11:18:37 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:26:54 2016 -0500

    librhash: Build the library within CMake
    
    Update `ustd.h` to include KWSys Large File Support configuration so
    that consistent stream libraries are used (on AIX with XL).
    
    Add a `cm_rhash.h` header to include the CMake-provided copy of the
    `rhash.h` header from CMake sources.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a5702e1..82a34d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -298,6 +298,10 @@ macro (CMAKE_BUILD_UTILITIES)
     add_subdirectory(Utilities/KWIML)
   endif()
 
+  set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
+  add_subdirectory(Utilities/cmlibrhash)
+  CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
+
   #---------------------------------------------------------------------
   # Build zlib library for Curl, CMake, and CTest.
   set(CMAKE_ZLIB_HEADER "cm_zlib.h")
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index cf9dbb8..879272c 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -788,6 +788,7 @@ target_link_libraries(CMakeLib cmsys
   ${CMAKE_CURL_LIBRARIES}
   ${CMAKE_JSONCPP_LIBRARIES}
   ${CMAKE_LIBUV_LIBRARIES}
+  ${CMAKE_LIBRHASH_LIBRARIES}
   ${CMake_KWIML_LIBRARIES}
   )
 
diff --git a/Utilities/cm_rhash.h b/Utilities/cm_rhash.h
new file mode 100644
index 0000000..23d5409
--- /dev/null
+++ b/Utilities/cm_rhash.h
@@ -0,0 +1,8 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#ifndef cm_rhash_h
+#define cm_rhash_h
+
+#include <cmlibrhash/librhash/rhash.h>
+
+#endif
diff --git a/Utilities/cmlibrhash/CMakeLists.txt b/Utilities/cmlibrhash/CMakeLists.txt
new file mode 100644
index 0000000..47d069a
--- /dev/null
+++ b/Utilities/cmlibrhash/CMakeLists.txt
@@ -0,0 +1,28 @@
+project(librhash C)
+
+set(librhash_sources
+  librhash/algorithms.c
+  librhash/algorithms.h
+  librhash/byte_order.c
+  librhash/byte_order.h
+  librhash/hex.c
+  librhash/hex.h
+  librhash/md5.c
+  librhash/md5.h
+  librhash/rhash.c
+  librhash/rhash.h
+  librhash/sha1.c
+  librhash/sha1.h
+  librhash/sha256.c
+  librhash/sha256.h
+  librhash/sha512.c
+  librhash/sha512.h
+  librhash/ustd.h
+  librhash/util.h
+  )
+
+include_directories(
+  ${KWSYS_HEADER_ROOT}
+  )
+
+add_library(cmlibrhash ${librhash_sources})
diff --git a/Utilities/cmlibrhash/librhash/ustd.h b/Utilities/cmlibrhash/librhash/ustd.h
index 94f1ae2..38c4e3e 100644
--- a/Utilities/cmlibrhash/librhash/ustd.h
+++ b/Utilities/cmlibrhash/librhash/ustd.h
@@ -2,6 +2,9 @@
 #ifndef LIBRHASH_USTD_H
 #define LIBRHASH_USTD_H
 
+/* Include KWSys Large File Support configuration. */
+#include <cmsys/Configure.h>
+
 #if _MSC_VER >= 1300
 
 # define int64_t __int64

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=53048afa8dc24327d82a1ff0f78801e1f344a4b6
commit 53048afa8dc24327d82a1ff0f78801e1f344a4b6
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Nov 3 11:15:19 2016 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Nov 10 08:26:54 2016 -0500

    librhash: Remove source fragments not needed for CMake
    
    We only need a subset of the hash algorithms supported by librhash.
    Add preprocessor conditionals to remove source fragments that we do
    not need.  Write an alternative algorithm enumeration that matches
    the indexing on our reduced array.
    
    Also remove a few fragments outright.

diff --git a/Utilities/cmlibrhash/README b/Utilities/cmlibrhash/README
index 1e51017..4ea492f 100644
--- a/Utilities/cmlibrhash/README
+++ b/Utilities/cmlibrhash/README
@@ -1,57 +1,3 @@
-                           === RHash program ===
-
-RHash is a console utility for calculation  and verification of magnet links
-and a wide range of hash sums like  CRC32,  MD4, MD5,  SHA1, SHA256, SHA512,
-SHA3,   AICH,  ED2K,  Tiger,  DC++ TTH,  BitTorrent BTIH,   GOST R 34.11-94,
-RIPEMD-160, HAS-160, EDON-R, Whirlpool and Snefru.
-
-Hash sums are used to  ensure and verify integrity  of large volumes of data
-for a long-term storing or transferring.
-
-Features:
- * Output in a predefined (SFV, BSD-like) or a user-defined format.
- * Can calculate Magnet links.
- * Updating hash files (adding hash sums of files missing in the hash file).
- * Calculates several hash sums in one pass
- * Ability to process directories recursively.
- * Portability: the program works the same on Linux, *BSD or Windows.
-
-
-                        === The LibRHash library ===
-
-LibRHash is a professional,  portable,  thread-safe  C library for computing
-a wide variety of hash sums, such as  CRC32, MD4, MD5, SHA1, SHA256, SHA512,
-SHA3,   AICH,  ED2K,  Tiger,  DC++ TTH,  BitTorrent BTIH,   GOST R 34.11-94,
-RIPEMD-160, HAS-160, EDON-R, Whirlpool and Snefru.
-Hash sums are used  to ensure and verify integrity of  large volumes of data
-for a long-term storing or transferring.
-
-Features:
- * Small and easy to learn interface.
- * Hi-level and Low-level API.
- * Allows calculating of several hash functions simultaneously.
- * Portability: the library works on Linux, *BSD and Windows.
-
-
-                               === Links ===
-
- * Project Home Page: http://rhash.sourceforge.net/
- * Official Releases: http://sf.net/projects/rhash/files/rhash/
-
- * RHash hash functions descriptions http://rhash.anz.ru/hashes.php
- * The table of the hash functions supported by RHash
-   http://sf.net/apps/mediawiki/rhash/index.php?title=Hash_sums
- * ECRYPT: The Hash Function Zoo
-   http://ehash.iaik.tugraz.at/wiki/The_Hash_Function_Zoo
-
-
-                     === Getting latest source code ===
-
-The latest source code can be obtained from Git repository by command:
-
-  git clone git://github.com/rhash/RHash.git
-
-
                        === Notes on RHash License ===
 
 The RHash program and LibRHash library are distributed under  RHash License,
diff --git a/Utilities/cmlibrhash/librhash/algorithms.c b/Utilities/cmlibrhash/librhash/algorithms.c
index 1f343a1..56d20b8 100644
--- a/Utilities/cmlibrhash/librhash/algorithms.c
+++ b/Utilities/cmlibrhash/librhash/algorithms.c
@@ -22,6 +22,7 @@
 #include "algorithms.h"
 
 /* header files of all supported hash sums */
+#if 0
 #include "aich.h"
 #include "crc32.h"
 #include "ed2k.h"
@@ -29,17 +30,21 @@
 #include "gost.h"
 #include "has160.h"
 #include "md4.h"
+#endif
 #include "md5.h"
+#if 0
 #include "ripemd-160.h"
 #include "snefru.h"
+#endif
 #include "sha1.h"
 #include "sha256.h"
 #include "sha512.h"
+#if 0
 #include "sha3.h"
 #include "tiger.h"
-#include "torrent.h"
 #include "tth.h"
 #include "whirlpool.h"
+#endif
 
 #ifdef USE_OPENSSL
 /* note: BTIH and AICH depends on the used SHA1 algorithm */
@@ -66,14 +71,19 @@ unsigned rhash_uninitialized_algorithms = RHASH_NEED_INIT_ALG;
 rhash_hash_info* rhash_info_table = rhash_hash_info_default;
 int rhash_info_size = RHASH_HASH_COUNT;
 
+#if 0
 static void rhash_crc32_init(uint32_t* crc32);
 static void rhash_crc32_update(uint32_t* crc32, const unsigned char* msg, size_t size);
 static void rhash_crc32_final(uint32_t* crc32, unsigned char* result);
+#endif
 
+#if 0
 rhash_info info_crc32 = { RHASH_CRC32, F_BE32, 4, "CRC32", "crc32" };
 rhash_info info_md4 = { RHASH_MD4, F_LE32, 16, "MD4", "md4" };
+#endif
 rhash_info info_md5 = { RHASH_MD5, F_LE32, 16, "MD5", "md5" };
 rhash_info info_sha1 = { RHASH_SHA1,      F_BE32, 20, "SHA1", "sha1" };
+#if 0
 rhash_info info_tiger = { RHASH_TIGER,    F_LE64, 24, "TIGER", "tiger" };
 rhash_info info_tth  = { RHASH_TTH,       F_BS32, 24, "TTH", "tree:tiger" };
 rhash_info info_btih = { RHASH_BTIH,      0, 20, "BTIH", "btih" };
@@ -86,16 +96,19 @@ rhash_info info_gostpro = { RHASH_GOST_CRYPTOPRO, F_LE32, 32, "GOST-CRYPTOPRO",
 rhash_info info_has160 = { RHASH_HAS160,     F_LE32, 20, "HAS-160", "has160" };
 rhash_info info_snf128 = { RHASH_SNEFRU128,  F_BE32, 16, "SNEFRU-128", "snefru128" };
 rhash_info info_snf256 = { RHASH_SNEFRU256,  F_BE32, 32, "SNEFRU-256", "snefru256" };
+#endif
 rhash_info info_sha224 = { RHASH_SHA224,     F_BE32, 28, "SHA-224", "sha224" };
 rhash_info info_sha256 = { RHASH_SHA256,     F_BE32, 32, "SHA-256", "sha256" };
 rhash_info info_sha384 = { RHASH_SHA384,     F_BE64, 48, "SHA-384", "sha384" };
 rhash_info info_sha512 = { RHASH_SHA512,     F_BE64, 64, "SHA-512", "sha512" };
+#if 0
 rhash_info info_edr256 = { RHASH_EDONR256,   F_LE32, 32, "EDON-R256", "edon-r256" };
 rhash_info info_edr512 = { RHASH_EDONR512,   F_LE64, 64, "EDON-R512", "edon-r512" };
 rhash_info info_sha3_224 = { RHASH_SHA3_224, F_LE64, 28, "SHA3-224", "sha3-224" };
 rhash_info info_sha3_256 = { RHASH_SHA3_256, F_LE64, 32, "SHA3-256", "sha3-256" };
 rhash_info info_sha3_384 = { RHASH_SHA3_384, F_LE64, 48, "SHA3-384", "sha3-384" };
 rhash_info info_sha3_512 = { RHASH_SHA3_512, F_LE64, 64, "SHA3-512", "sha3-512" };
+#endif
 
 /* some helper macros */
 #define dgshft(name) (((char*)&((name##_ctx*)0)->hash) - (char*)0)
@@ -109,13 +122,15 @@ rhash_info info_sha3_512 = { RHASH_SHA3_512, F_LE64, 64, "SHA3-512", "sha3-512"
 /* information about all hashes */
 rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT] =
 {
+#if 0
 	{ &info_crc32, sizeof(uint32_t), 0, iuf(rhash_crc32), 0 }, /* 32 bit */
 	{ &info_md4, sizeof(md4_ctx), dgshft(md4), iuf(rhash_md4), 0 }, /* 128 bit */
+#endif
 	{ &info_md5, sizeof(md5_ctx), dgshft(md5), iuf(rhash_md5), 0 }, /* 128 bit */
 	{ &info_sha1, sizeof(sha1_ctx), dgshft(sha1), iuf(rhash_sha1), 0 }, /* 160 bit */
+#if 0
 	{ &info_tiger, sizeof(tiger_ctx), dgshft(tiger), iuf(rhash_tiger), 0 }, /* 192 bit */
 	{ &info_tth, sizeof(tth_ctx), dgshft2(tth, tiger.hash), iuf(rhash_tth), 0 }, /* 192 bit */
-	{ &info_btih, sizeof(torrent_ctx), dgshft2(torrent, btih), iuf(bt), (pcleanup_t)bt_cleanup }, /* 160 bit */
 	{ &info_ed2k, sizeof(ed2k_ctx), dgshft2(ed2k, md4_context_inner.hash), iuf(rhash_ed2k), 0 }, /* 128 bit */
 	{ &info_aich, sizeof(aich_ctx), dgshft2(aich, sha1_context.hash), iuf(rhash_aich), (pcleanup_t)rhash_aich_cleanup }, /* 160 bit */
 	{ &info_whirlpool, sizeof(whirlpool_ctx), dgshft(whirlpool), iuf(rhash_whirlpool), 0 }, /* 512 bit */
@@ -125,16 +140,19 @@ rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT] =
 	{ &info_has160, sizeof(has160_ctx), dgshft(has160), iuf(rhash_has160), 0 }, /* 160 bit */
 	{ &info_snf128, sizeof(snefru_ctx), dgshft(snefru), ini(rhash_snefru128), upd(rhash_snefru), fin(rhash_snefru), 0 }, /* 128 bit */
 	{ &info_snf256, sizeof(snefru_ctx), dgshft(snefru), ini(rhash_snefru256), upd(rhash_snefru), fin(rhash_snefru), 0 }, /* 256 bit */
+#endif
 	{ &info_sha224, sizeof(sha256_ctx), dgshft(sha256), ini(rhash_sha224), upd(rhash_sha256), fin(rhash_sha256), 0 }, /* 224 bit */
 	{ &info_sha256, sizeof(sha256_ctx), dgshft(sha256), iuf(rhash_sha256), 0 },  /* 256 bit */
 	{ &info_sha384, sizeof(sha512_ctx), dgshft(sha512), ini(rhash_sha384), upd(rhash_sha512), fin(rhash_sha512), 0 }, /* 384 bit */
 	{ &info_sha512, sizeof(sha512_ctx), dgshft(sha512), iuf(rhash_sha512), 0 },  /* 512 bit */
+#if 0
 	{ &info_edr256, sizeof(edonr_ctx), dgshft2(edonr, u.data256.hash) + 32, iuf(rhash_edonr256), 0 },  /* 256 bit */
 	{ &info_edr512, sizeof(edonr_ctx), dgshft2(edonr, u.data512.hash) + 64, iuf(rhash_edonr512), 0 },  /* 512 bit */
 	{ &info_sha3_224, sizeof(sha3_ctx), dgshft(sha3), ini(rhash_sha3_224), upd(rhash_sha3), fin(rhash_sha3), 0 }, /* 224 bit */
 	{ &info_sha3_256, sizeof(sha3_ctx), dgshft(sha3), ini(rhash_sha3_256), upd(rhash_sha3), fin(rhash_sha3), 0 }, /* 256 bit */
 	{ &info_sha3_384, sizeof(sha3_ctx), dgshft(sha3), ini(rhash_sha3_384), upd(rhash_sha3), fin(rhash_sha3), 0 }, /* 384 bit */
 	{ &info_sha3_512, sizeof(sha3_ctx), dgshft(sha3), ini(rhash_sha3_512), upd(rhash_sha3), fin(rhash_sha3), 0 }, /* 512 bit */
+#endif
 };
 
 /**
@@ -156,6 +174,7 @@ void rhash_init_algorithms(unsigned mask)
 	rhash_uninitialized_algorithms = 0;
 }
 
+#if 0
 /* CRC32 helper functions */
 
 /**
@@ -198,3 +217,4 @@ static void rhash_crc32_final(uint32_t* crc32, unsigned char* result)
 	result[2] = (unsigned char)(*crc32 >> 8), result[3] = (unsigned char)(*crc32);
 #endif
 }
+#endif
diff --git a/Utilities/cmlibrhash/librhash/byte_order.h b/Utilities/cmlibrhash/librhash/byte_order.h
index 77b8bb9..59a6c23 100644
--- a/Utilities/cmlibrhash/librhash/byte_order.h
+++ b/Utilities/cmlibrhash/librhash/byte_order.h
@@ -4,10 +4,6 @@
 #include "ustd.h"
 #include <stdlib.h>
 
-#ifdef IN_RHASH
-#include "config.h"
-#endif
-
 #ifdef __GLIBC__
 # include <endian.h>
 #endif
diff --git a/Utilities/cmlibrhash/librhash/rhash.c b/Utilities/cmlibrhash/librhash/rhash.c
index 98cf97e..ad6249b 100644
--- a/Utilities/cmlibrhash/librhash/rhash.c
+++ b/Utilities/cmlibrhash/librhash/rhash.c
@@ -32,8 +32,6 @@
 
 #include "byte_order.h"
 #include "algorithms.h"
-#include "torrent.h"
-#include "plug_openssl.h"
 #include "util.h"
 #include "hex.h"
 #include "rhash.h" /* RHash library interface */
@@ -155,8 +153,10 @@ RHASH_API rhash rhash_init(unsigned hash_id)
 			rctx->vector[i].hash_info = info;
 			rctx->vector[i].context = phash_ctx;
 
+#if 0
 			/* BTIH initialization is complex, save pointer for later */
 			if ((id & RHASH_BTIH) != 0) rctx->bt_ctx = phash_ctx;
+#endif
 			phash_ctx += (info->context_size + 7) & ~7;
 
 			/* initialize the i-th hash context */
@@ -508,6 +508,7 @@ const rhash_info* rhash_info_by_id(unsigned hash_id)
 	return rhash_info_table[rhash_ctz(hash_id)].info;
 }
 
+#if 0
 /**
  * Detect default digest output format for given hash algorithm.
  *
@@ -519,6 +520,7 @@ RHASH_API int rhash_is_base32(unsigned hash_id)
 	/* fast method is just to test a bit-mask */
 	return ((hash_id & (RHASH_TTH | RHASH_AICH)) != 0);
 }
+#endif
 
 /**
  * Returns size of binary digest for given hash algorithm.
@@ -572,6 +574,7 @@ RHASH_API const char* rhash_get_magnet_name(unsigned hash_id)
 	return (info ? info->magnet_name : 0);
 }
 
+#if 0
 static size_t rhash_get_magnet_url_size(const char* filepath,
 	rhash context, unsigned hash_mask, int flags)
 {
@@ -809,47 +812,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID reserved)
 }
 #endif
 
-/**
- * Process a BitTorrent-related rhash message.
- *
- * @param msg_id message identifier
- * @param bt BitTorrent context
- * @param ldata data depending on message
- * @param rdata data depending on message
- * @return message-specific data
- */
-static rhash_uptr_t process_bt_msg(unsigned msg_id, torrent_ctx* bt, rhash_uptr_t ldata, rhash_uptr_t rdata)
-{
-	if (bt == NULL) return RHASH_ERROR;
-
-	switch (msg_id) {
-	case RMSG_BT_ADD_FILE:
-		bt_add_file(bt, (const char*)ldata, *(unsigned long long*)rdata);
-		break;
-	case RMSG_BT_SET_OPTIONS:
-		bt_set_options(bt, (unsigned)ldata);
-		break;
-	case RMSG_BT_SET_ANNOUNCE:
-		bt_add_announce(bt, (const char*)ldata);
-		break;
-	case RMSG_BT_SET_PIECE_LENGTH:
-		bt_set_piece_length(bt, (size_t)ldata);
-		break;
-	case RMSG_BT_SET_BATCH_SIZE:
-		bt_set_piece_length(bt,
-			bt_default_piece_length(*(unsigned long long*)ldata));
-		break;
-	case RMSG_BT_SET_PROGRAM_NAME:
-		bt_set_program_name(bt, (const char*)ldata);
-		break;
-	case RMSG_BT_GET_TEXT:
-		return (rhash_uptr_t)bt_get_text(bt, (char**)ldata);
-	default:
-		return RHASH_ERROR; /* unknown message */
-	}
-	return 0;
-}
-
 #define PVOID2UPTR(p) ((rhash_uptr_t)((char*)p - 0))
 
 /**
@@ -902,18 +864,9 @@ RHASH_API rhash_uptr_t rhash_transmit(unsigned msg_id, void* dst, rhash_uptr_t l
 		return rhash_openssl_hash_mask;
 #endif
 
-	/* BitTorrent related messages */
-	case RMSG_BT_ADD_FILE:
-	case RMSG_BT_SET_OPTIONS:
-	case RMSG_BT_SET_ANNOUNCE:
-	case RMSG_BT_SET_PIECE_LENGTH:
-	case RMSG_BT_SET_PROGRAM_NAME:
-	case RMSG_BT_GET_TEXT:
-	case RMSG_BT_SET_BATCH_SIZE:
-		return process_bt_msg(msg_id, (torrent_ctx*)(((rhash_context_ext*)dst)->bt_ctx), ldata, rdata);
-
 	default:
 		return RHASH_ERROR; /* unknown message */
 	}
 	return 0;
 }
+#endif
diff --git a/Utilities/cmlibrhash/librhash/rhash.h b/Utilities/cmlibrhash/librhash/rhash.h
index 73ee537..6d18c18 100644
--- a/Utilities/cmlibrhash/librhash/rhash.h
+++ b/Utilities/cmlibrhash/librhash/rhash.h
@@ -20,6 +20,7 @@ extern "C" {
  */
 enum rhash_ids
 {
+#if 0
 	RHASH_CRC32 = 0x01,
 	RHASH_MD4   = 0x02,
 	RHASH_MD5   = 0x04,
@@ -58,6 +59,22 @@ enum rhash_ids
 
 	/** The number of supported hash functions */
 	RHASH_HASH_COUNT = 26
+#else
+	RHASH_MD5        = 0x01,
+	RHASH_SHA1       = 0x02,
+	RHASH_SHA224     = 0x04,
+	RHASH_SHA256     = 0x08,
+	RHASH_SHA384     = 0x10,
+	RHASH_SHA512     = 0x20,
+	RHASH_ALL_HASHES =
+		RHASH_MD5 |
+		RHASH_SHA1 |
+		RHASH_SHA224 |
+		RHASH_SHA256 |
+		RHASH_SHA384 |
+		RHASH_SHA512,
+	RHASH_HASH_COUNT = 6
+#endif
 };
 
 /**
@@ -136,6 +153,7 @@ RHASH_API const char* rhash_get_magnet_name(unsigned hash_id); /* get name part
 /* note, that rhash_info_by_id() is not exported to a shared library or DLL */
 const rhash_info* rhash_info_by_id(unsigned hash_id); /* get hash sum info by hash id */
 
+#if 0
 /**
  * Flags for printing a hash sum
  */
@@ -168,6 +186,7 @@ enum rhash_print_sum_flags
 	/** print file size in rhash_print_magnet */
 	RHPR_FILESIZE  = 0x40,
 };
+#endif
 
 /* output hash into the given buffer */
 RHASH_API size_t rhash_print_bytes(char* output,
@@ -213,18 +232,6 @@ RHASH_API rhash_uptr_t rhash_transmit(
 #define RMSG_SET_OPENSSL_MASK 10
 #define RMSG_GET_OPENSSL_MASK 11
 
-#define RMSG_BT_ADD_FILE 32
-#define RMSG_BT_SET_OPTIONS 33
-#define RMSG_BT_SET_ANNOUNCE 34
-#define RMSG_BT_SET_PIECE_LENGTH 35
-#define RMSG_BT_SET_PROGRAM_NAME 36
-#define RMSG_BT_GET_TEXT 37
-#define RMSG_BT_SET_BATCH_SIZE 38
-
-/* possible BitTorrent options for the RMSG_BT_SET_OPTIONS message */
-#define RHASH_BT_OPT_PRIVATE 1
-#define RHASH_BT_OPT_INFOHASH_ONLY 2
-
 /* helper macros */
 
 /** Get a pointer to context of the specified hash function */

-----------------------------------------------------------------------

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list