+version 0.30.???
+================
+
+ - added support for using libnss instead of beecrypt for
+ vhashify's hash calculation. libnss has bad SHA1 performance on
+ i386, but is a) maintained and b) gives better performance with
+ all other hashes and on x86_64.
+
+
version 0.30.214
================
- patches for yum-3.2.
AC_PROG_INSTALL
AC_PROG_LN_S
AM_PROG_CC_C_O
+PKG_PROG_PKG_CONFIG
ENSC_CXXCOMPILER
ENSC_C99COMPILER
dnl ########################
dnl
+dnl {crypto stuff
+dnl
+AC_MSG_CHECKING([for used crypto API])
+AC_ARG_WITH(crypto-api,
+ AC_HELP_STRING([--with-crypto-api=API],
+ [select crypto api to be used; possible values are `none', `nss', `beecrypt', `auto' (default:auto)]),
+ [case $withval in
+ (none|nss|beecrypt|auto) ensc_crypto_api=$withval;;
+ (*) AC_MSG_ERROR([invalid initscripts value, only gentoo and sysv are supported]);;
+ esac],[ensc_crypto_api=auto])
+AC_MSG_RESULT($ensc_crypto_api)
+
+
+dnl Now, check for matching crypto api. When selected 'auto', the
+dnl first matching one wins
+
+dnl ########################
+dnl
dnl {check for beecrypt
dnl
+case $ensc_crypto_api in
+(auto|beecrypt)
if test x"$ensc_cv_c99_c99compiler" = xyes; then
ensc_have_beecrypt=yes
AC_CHECK_LIB(beecrypt, hashFunctionContextInit, [ : ],
[ ensc_have_beecrypt=no ])
fi
-
- if test x"$ensc_have_beecrypt" != xyes; then
- AC_MSG_WARN([
-****
-**** 'beecrypt' could not be found;
-**** this will disable the build of 'vhashify'
-****])
- fi
else
ensc_have_beecrypt=no
-fi
+fi;;
+esac
+
+case $ensc_crypto_api in
+(auto) if test x"$ensc_have_beecrypt" = xyes; then
+ AC_MSG_NOTICE([using beecrypt as crypto api])
+ ensc_crypto_api=beecrypt
+ fi;;
+(beecrypt) if test x"$ensc_have_beecrypt" != xyes; then
+ AC_MSG_ERROR([beecrypt crypto api not found])
+ fi;;
+esac
AM_CONDITIONAL(ENSC_HAVE_BEECRYPT, test x"$ensc_have_beecrypt" = xyes)
AM_CONDITIONAL(ENSC_CAN_BEECRYPT_WITH_DIETLIBC, false)
dnl ########################
+dnl ########################
+dnl
+dnl {check for nss
+dnl
+
+case $ensc_crypto_api in
+(nss) PKG_CHECK_MODULES(NSS, nss);;
+(auto) PKG_CHECK_MODULES(NSS, nss, [
+ AC_MSG_NOTICE([using NSS as crypto api])
+ ensc_crypto_api=nss],
+ AC_MSG_RESULT(no));;
+esac
+
+dnl
+dnl nss stuff ends here}
+dnl
+dnl ########################
+
+case $ensc_crypto_api in
+(beecrypt)
+ ENSC_HAVE_CRYPTO=true
+ ENSC_CRYPTO_API=ENSC_CRYPTO_API_BEECRYPT
+ ENSC_CRYPTO_CFLAGS=
+ ENSC_CRYPTO_LIB=-lbeecrypt
+ ENSC_CAN_CRYPTO_WITH_DIETLIBC=false
+ ;;
+
+(nss)
+ ENSC_HAVE_CRYPTO=true
+ ENSC_CRYPTO_API=ENSC_CRYPTO_API_NSS
+ ENSC_CRYPTO_CFLAGS=$NSS_CFLAGS
+ ENSC_CRYPTO_LIB=$NSS_LIBS
+ ENSC_CAN_CRYPTO_WITH_DIETLIBC=false
+ ;;
+
+(none)
+ ENSC_HAVE_CRYPTO=false
+ ENSC_CRYPTO_API=ENSC_CRYPTO_API_NONE
+ ENSC_CRYPTO_CFLAGS=
+ ENSC_CRYPTO_LIB=
+ ENSC_CAN_CRYPTO_WITH_DIETLIBC=false
+
+ AC_MSG_WARN([No crypto api found/select. This will disable the build of `vhashify'])
+ ;;
+
+(*) AC_MSG_ERROR([internal error])
+esac
+
+AM_CONDITIONAL(ENSC_HAVE_CRYPTO, $ENSC_HAVE_CRYPTO)
+AM_CONDITIONAL(ENSC_CAN_CRYPTO_WITH_DIETLIBC, $ENSC_CAN_CRYPTO_WITH_DIETLIBC)
+AC_SUBST(ENSC_CRYPTO_CFLAGS, $ENSC_CRYPTO_CFLAGS)
+AC_SUBST(ENSC_CRYPTO_LIB, $ENSC_CRYPTO_LIB)
+AC_DEFINE_UNQUOTED(ENSC_CRYPTO_API, $ENSC_CRYPTO_API, [Used crypto API])
+
+dnl
+dnl crypto stuff ends here}
+dnl
+dnl ########################
+
+
dnl Check what distro this is, use Gentoo initscripts if appropriate
AC_MSG_CHECKING([for host initscripts])
AC_ARG_WITH(initscripts, AC_HELP_STRING([--with-initscripts=TYPE], [force host initscripts; valid values are 'gentoo' and 'sysv' (default: guess)]), [
ext2fs Source: $ensc_cv_test_ext2fs_header
syscall(2) invocation: $with_syscall
vserver(2) syscall#: $ensc_cv_value_syscall_vserver
+ crypto api: $ensc_crypto_api
Paths:
prefix: $prefix
noinst_HEADERS += \
lib_internal/coreassert.h \
+ lib_internal/crypto-wrapper.h \
+ lib_internal/crypto-wrapper-nss.h \
+ lib_internal/crypto-wrapper-beecrypt.h \
lib_internal/errinfo.h \
lib_internal/jail.h \
lib_internal/matchlist.h \
--- /dev/null
+/* --*- c -*--
+ * Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 and/or 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_BEECRYPT_H
+#define H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_BEECRYPT_H
+
+#include <beecrypt/beecrypt.h>
+#include <ctype.h>
+
+typedef hashFunction ensc_hash_method;
+typedef hashFunctionContext ensc_hash_context;
+
+inline static void
+ensc_crypto_init(void)
+{
+}
+
+inline static ensc_hash_method const *
+ensc_crypto_hash_get_default(void)
+{
+ return hashFunctionDefault();
+}
+
+inline static ensc_hash_method const *
+ensc_crypto_hash_find(char const *id_c)
+{
+ char *id = strdupa(id_c);
+ char *ptr = id;
+ char const *name;
+
+ while (*ptr) {
+ *ptr = tolower(*ptr);
+ ++ptr;
+ }
+
+ ptr = id;
+ while ((ptr=strchr(ptr, '-'))!=NULL)
+ memmove(ptr, ptr+1, strlen(ptr));
+
+ if (strcmp(id, "md2")==0)
+ name = "MD2";
+ else if (strcmp(id, "md5")==0)
+ name = "MD5";
+ else if (strcmp(id, "sha1")==0)
+ name = "SHA-1";
+ else if (strcasecmp(id, "sha256")==0)
+ name = "SHA-256";
+#if 0
+ /* sha-384 in beecrypt seems to be broken; digestsize is reported as
+ * 64 there although 48 is the correct value */
+ else if (strcasecmp(id, "sha384")==0)
+ name = "SHA-384";
+#endif
+ else if (strcasecmp(id, "sha512")==0)
+ name = "SHA-512";
+ else
+ name = NULL;
+
+ return hashFunctionFind(name);
+}
+
+inline static char const *
+ensc_crypto_hash_get_name(ensc_hash_method const *m)
+{
+ return m->name;
+}
+
+inline static size_t
+ensc_crypto_hash_get_digestsize(ensc_hash_method const *m)
+{
+ return m->digestsize;
+}
+
+
+
+inline static size_t
+ensc_crypto_hashctx_get_digestsize(ensc_hash_context const *ctx)
+{
+ return ensc_crypto_hash_get_digestsize(ctx->algo);
+}
+
+inline static int
+ensc_crypto_hashctx_get_digest(ensc_hash_context *ctx, void *result,
+ size_t *res_len, size_t UNUSED max_res_len)
+{
+ int rc = hashFunctionContextDigest(ctx, result);
+ if (res_len)
+ *res_len = ctx->algo->digestsize;
+
+ return rc;
+}
+
+inline static int
+ensc_crypto_hashctx_update(ensc_hash_context *ctx, void const *src, size_t len)
+{
+ return hashFunctionContextUpdate(ctx, src, len);
+}
+
+inline static int
+ensc_crypto_hashctx_init(ensc_hash_context *ctx, ensc_hash_method const *m)
+{
+ return hashFunctionContextInit(ctx, m);
+}
+
+inline static int
+ensc_crypto_hashctx_reset(ensc_hash_context *ctx)
+{
+ return hashFunctionContextReset(ctx);
+}
+
+inline static void
+ensc_crypto_hashctx_free(ensc_hash_context *ctx)
+{
+ hashFunctionContextFree(ctx);
+}
+
+#endif /* H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_BEECRYPT_H */
--- /dev/null
+/* --*- c -*--
+ * Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_NSS_H
+#define H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_NSS_H
+
+#include <sechash.h>
+#include <secoid.h>
+#include <nss.h>
+
+#include "util-cast.h"
+
+typedef struct SECHashObjectStr ensc_hash_method;
+typedef struct HASHContextStr *ensc_hash_context;
+
+inline static int
+ensc_crypto_init(void)
+{
+ NSS_NoDB_Init(NULL);
+ return 0;
+}
+
+inline static ensc_hash_method const *
+ensc_crypto_hash_get_default(void)
+{
+ return HASH_GetHashObject(SEC_OID_SHA1);
+}
+
+inline static ensc_hash_method const *
+ensc_crypto_hash_find(char const *id_c)
+{
+ SECOidTag oid;
+
+#if 1
+ char *id = strdupa(id_c);
+ char *ptr = id;
+
+ while (*ptr) {
+ *ptr = tolower(*ptr);
+ ++ptr;
+ }
+
+ ptr = id;
+ while ((ptr=strchr(ptr, '-'))!=NULL)
+ memmove(ptr, ptr+1, strlen(ptr));
+
+ if (strcmp(id, "md2")==0)
+ oid = SEC_OID_MD2;
+ else if (strcmp(id, "md5")==0)
+ oid = SEC_OID_MD5;
+ else if (strcmp(id, "sha1")==0)
+ oid = SEC_OID_SHA1;
+ else if (strcasecmp(id, "sha256")==0)
+ oid = SEC_OID_SHA256;
+ else if (strcasecmp(id, "sha384")==0)
+ oid = SEC_OID_SHA384;
+ else if (strcasecmp(id, "sha512")==0)
+ oid = SEC_OID_SHA512;
+ else
+ oid = SEC_OID_UNKNOWN;
+
+#else
+ struct SECItemStr const item = {
+ .type = ???,
+ .data = const_cast(unsigned char *)(static_cast(unsigned char const *)(id)),
+ .len = strlen(id)
+ };
+ SECOidTag oid;
+
+ oid = SECOID_FindOIDTag(&item);
+#endif
+
+ return HASH_GetHashObjectByOidTag(oid);
+}
+
+inline static char const *
+ensc_crypto_hash_get_name(ensc_hash_method const *m)
+{
+ char const * const NAMES[] = {
+ [HASH_AlgNULL] = "null",
+ [HASH_AlgMD2] = "md2",
+ [HASH_AlgMD5] = "md5",
+ [HASH_AlgSHA1] = "sha1",
+ [HASH_AlgSHA256] = "sha256",
+ [HASH_AlgSHA384] = "sha384",
+ [HASH_AlgSHA512] = "sha512",
+ };
+ size_t idx = static_cast(size_t)(m->type);
+
+ if (idx >= sizeof(NAMES)/sizeof(NAMES[0]))
+ return NULL;
+
+ return NAMES[idx];
+ /* TODO: use SECOID_FindOIDTagDescription()? */
+}
+
+inline static size_t
+ensc_crypto_hash_get_digestsize(ensc_hash_method const *m)
+{
+ size_t const SIZES[] = {
+ [HASH_AlgMD2] = MD2_LENGTH,
+ [HASH_AlgMD5] = MD5_LENGTH,
+ [HASH_AlgSHA1] = SHA1_LENGTH,
+ [HASH_AlgSHA256] = SHA256_LENGTH,
+ [HASH_AlgSHA384] = SHA384_LENGTH,
+ [HASH_AlgSHA512] = SHA512_LENGTH,
+ };
+ size_t idx = static_cast(size_t)(m->type);
+
+ if (idx >= sizeof(SIZES)/sizeof(SIZES[0]))
+ return 0;
+
+ return SIZES[idx];
+}
+
+inline static size_t
+ensc_crypto_hashctx_get_digestsize(ensc_hash_context const *ctx)
+{
+ return ensc_crypto_hash_get_digestsize((*ctx)->hashobj);
+}
+
+inline static int
+ensc_crypto_hashctx_get_digest(ensc_hash_context *ctx, void *result,
+ size_t UNUSED *res_len_a, size_t UNUSED max_res_len)
+{
+ unsigned int res_len;
+
+ HASH_End(*ctx, result, &res_len, max_res_len);
+ if (res_len_a)
+ *res_len_a = res_len;
+
+ return 0;
+}
+
+inline static int
+ensc_crypto_hashctx_init(ensc_hash_context *ctx, ensc_hash_method const *m)
+{
+ *ctx = HASH_Create(m->type);
+ return *ctx==NULL ? -1 : 0;
+}
+
+inline static int
+ensc_crypto_hashctx_update(ensc_hash_context *ctx, void const *src, size_t len)
+{
+ HASH_Update(*ctx, src, len);
+ return 0;
+}
+
+inline static int
+ensc_crypto_hashctx_reset(ensc_hash_context *ctx)
+{
+ HASH_Begin(*ctx);
+ return 0;
+}
+
+inline static void
+ensc_crypto_hashctx_free(ensc_hash_context *ctx)
+{
+ HASH_Destroy(*ctx);
+ *ctx = NULL;
+}
+
+#endif /* H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_NSS_H */
--- /dev/null
+/* --*- c -*--
+ * Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 and/or 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_H
+#define H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_H
+
+#define ENSC_CRYPTO_API_NSS 1
+#define ENSC_CRYPTO_API_BEECRYPT 2
+
+#if ENSC_CRYPTO_API == ENSC_CRYPTO_API_BEECRYPT
+#include "crypto-wrapper-beecrypt.h"
+#elif ENSC_CRYPTO_API == ENSC_CRYPTO_API_NSS
+#include "crypto-wrapper-nss.h"
+#else
+#error undefined crypto API
+#endif
+
+#endif /* H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_H */
lib_internal/testsuite/matchlist-gnu
endif
+if ENSC_HAVE_CRYPTO
+check_PROGRAMS += lib_internal/testsuite/crypto \
+ lib_internal/testsuite/crypto-speed
+TESTS += lib_internal/testsuite/crypto
+endif
+
DIETPROGS += lib_internal/testsuite/isnumber \
lib_internal/testsuite/sigbus \
lib_internal/testsuite/matchlist
+if ENSC_CAN_CRYPTO_WITH_DIETLIBC
+DIETPROGS += lib_internal/testsuite/crypto \
+ lib_internal/testsuite/crypto-speed
+endif
+
EXTRA_DIST += lib_internal/testsuite/copy-check
TESTS_ENVIRONMENT += libinternaltestsuitedir=$(top_builddir)/lib_internal/testsuite
lib_internal_testsuite_matchlist_gnu_SOURCES = lib_internal/testsuite/matchlist.c
lib_internal_testsuite_matchlist_gnu_LDADD = $(LIBINTERNAL_GLIBC)
lib_internal_testsuite_matchlist_gnu_CPPFLAGS = $(AM_CPPFLAGS) # see note above
+
+if ENSC_HAVE_CRYPTO
+lib_internal_testsuite_crypto_speed_SOURCES = lib_internal/testsuite/crypto-speed.c
+lib_internal_testsuite_crypto_speed_CFLAGS = $(AM_CFLAGS) $(ENSC_CRYPTO_CFLAGS)
+lib_internal_testsuite_crypto_speed_LDADD = $(ENSC_CRYPTO_LIB) -lrt
+
+lib_internal_testsuite_crypto_SOURCES = lib_internal/testsuite/crypto.c
+lib_internal_testsuite_crypto_CFLAGS = $(AM_CFLAGS) $(ENSC_CRYPTO_CFLAGS)
+lib_internal_testsuite_crypto_LDADD = $(ENSC_CRYPTO_LIB)
+
+if !ENSC_CAN_CRYPTO_WITH_DIETLIBC
+lib_internal_testsuite_crypto_speed_LDFLAGS = -Wl,--as-needed
+lib_internal_testsuite_crypto_LDFLAGS = -Wl,--as-needed
+endif
+endif
--- /dev/null
+System:
+T61, Core2Duo 2.2Ghz, 4GiB RAM, Fedora 8, 64 bit
+
+
+64 bit
+======== --with-crypto-api=nss ============
+ md5: 1 x 0 -> 0.000010612s, 0 bytes/s
+ md5: 1048576 x 0 -> 0.240403614s, 0 bytes/s
+ md5: 1 x 16 -> 0.000001792s, 8.928.571 bytes/s
+ md5: 1048576 x 16 -> 0.290466264s, 57.759.602 bytes/s
+ md5: 16 x 1024 -> 0.000071528s, 229.057.152 bytes/s
+ md5: 16384 x 1024 -> 0.050839303s, 330.004.838 bytes/s
+ md5: 16 x 1048576 -> 0.047048043s, 356.597.531 bytes/s
+ md5: 100 x 1048576 -> 0.293919980s, 356.755.604 bytes/s
+ md5: 1000 x 1048576 -> 2.947685749s, 355.728.557 bytes/s
+ sha1: 1 x 0 -> 0.000004680s, 0 bytes/s
+ sha1: 1048576 x 0 -> 0.234542043s, 0 bytes/s
+ sha1: 1 x 16 -> 0.000002353s, 6.799.830 bytes/s
+ sha1: 1048576 x 16 -> 0.346382108s, 48.435.573 bytes/s
+ sha1: 16 x 1024 -> 0.000083828s, 195.447.821 bytes/s
+ sha1: 16384 x 1024 -> 0.080529647s, 208.335.893 bytes/s
+ sha1: 16 x 1048576 -> 0.077226951s, 217.245.608 bytes/s
+ sha1: 100 x 1048576 -> 0.482363856s, 217.382.788 bytes/s
+ sha1: 1000 x 1048576 -> 4.860877286s, 215.717.439 bytes/s
+sha256: 1 x 0 -> 0.000005987s, 0 bytes/s
+sha256: 1048576 x 0 -> 0.234423065s, 0 bytes/s
+sha256: 1 x 16 -> 0.000002859s, 5.596.362 bytes/s
+sha256: 1048576 x 16 -> 0.388906658s, 43.139.441 bytes/s
+sha256: 16 x 1024 -> 0.000158419s, 103.421.938 bytes/s
+sha256: 16384 x 1024 -> 0.150738207s, 111.300.355 bytes/s
+sha256: 16 x 1048576 -> 0.147762674s, 113.541.637 bytes/s
+sha256: 100 x 1048576 -> 0.920904318s, 113.863.729 bytes/s
+sha256: 1000 x 1048576 -> 9.222825976s, 113.693.568 bytes/s
+sha512: 1 x 0 -> 0.000012629s, 0 bytes/s
+sha512: 1048576 x 0 -> 0.232183717s, 0 bytes/s
+sha512: 1 x 16 -> 0.000003574s, 4.476.776 bytes/s
+sha512: 1048576 x 16 -> 0.340624988s, 49.254.213 bytes/s
+sha512: 16 x 1024 -> 0.000106430s, 153.941.557 bytes/s
+sha512: 16384 x 1024 -> 0.101951761s, 164.560.335 bytes/s
+sha512: 16 x 1048576 -> 0.098160536s, 170.916.100 bytes/s
+sha512: 100 x 1048576 -> 0.611599635s, 171.448.107 bytes/s
+sha512: 1000 x 1048576 -> 6.109529732s, 171.629.576 bytes/s
+
+
+======== --with-crypto-api=beecrypt ======
+ md5: 1 x 0 -> 0.000019913s, 0 bytes/s
+ md5: 1048576 x 0 -> 0.043844247s, 0 bytes/s
+ md5: 1 x 16 -> 0.000003545s, 4.513.399 bytes/s
+ md5: 1048576 x 16 -> 0.088413571s, 189.758.379 bytes/s
+ md5: 16 x 1024 -> 0.000047876s, 342.217.394 bytes/s
+ md5: 16384 x 1024 -> 0.044752750s, 374.886.817 bytes/s
+ md5: 16 x 1048576 -> 0.044899921s, 373.658.029 bytes/s
+ md5: 100 x 1048576 -> 0.280756545s, 373.482.299 bytes/s
+ md5: 1000 x 1048576 -> 2.802876816s, 374.107.058 bytes/s
+ sha1: 1 x 0 -> 0.000005236s, 0 bytes/s
+ sha1: 1048576 x 0 -> 0.036770880s, 0 bytes/s
+ sha1: 1 x 16 -> 0.000001467s, 10.906.612 bytes/s
+ sha1: 1048576 x 16 -> 0.127525089s, 131.560.119 bytes/s
+ sha1: 16 x 1024 -> 0.000088543s, 185.040.037 bytes/s
+ sha1: 16384 x 1024 -> 0.084912873s, 197.581.537 bytes/s
+ sha1: 16 x 1048576 -> 0.084310211s, 198.993.879 bytes/s
+ sha1: 100 x 1048576 -> 0.528023625s, 198.585.053 bytes/s
+ sha1: 1000 x 1048576 -> 5.284808204s, 198.413.255 bytes/s
+sha256: 1 x 0 -> 0.000005436s, 0 bytes/s
+sha256: 1048576 x 0 -> 0.036945402s, 0 bytes/s
+sha256: 1 x 16 -> 0.000002002s, 7.992.007 bytes/s
+sha256: 1048576 x 16 -> 0.195753663s, 85.705.757 bytes/s
+sha256: 16 x 1024 -> 0.000158651s, 103.270.701 bytes/s
+sha256: 16384 x 1024 -> 0.152873039s, 109.746.074 bytes/s
+sha256: 16 x 1048576 -> 0.151477419s, 110.757.207 bytes/s
+sha256: 100 x 1048576 -> 0.947547671s, 110.662.084 bytes/s
+sha256: 1000 x 1048576 -> 9.478980465s, 110.621.179 bytes/s
+sha512: 1 x 0 -> 0.000013080s, 0 bytes/s
+sha512: 1048576 x 0 -> 0.046340109s, 0 bytes/s
+sha512: 1 x 16 -> 0.000002583s, 6.194.347 bytes/s
+sha512: 1048576 x 16 -> 0.154927531s, 108.290.733 bytes/s
+sha512: 16 x 1024 -> 0.000114033s, 143.677.707 bytes/s
+sha512: 16384 x 1024 -> 0.102781822s, 163.231.354 bytes/s
+sha512: 16 x 1048576 -> 0.102118303s, 164.291.958 bytes/s
+sha512: 100 x 1048576 -> 0.639161103s, 164.055.039 bytes/s
+sha512: 1000 x 1048576 -> 6.402716295s, 163.770.492 bytes/s
+
+
+
+
+
+32 bit
+======== --with-crypto-api=nss ============
+ md5: 1 x 0 -> 0.000012284s, 0 bytes/s
+ md5: 1048576 x 0 -> 0.351524846s, 0 bytes/s
+ md5: 1 x 16 -> 0.000002187s, 7.315.957 bytes/s
+ md5: 1048576 x 16 -> 0.427717323s, 39.225.009 bytes/s
+ md5: 16 x 1024 -> 0.000070463s, 232.519.194 bytes/s
+ md5: 16384 x 1024 -> 0.067484999s, 248.606.597 bytes/s
+ md5: 16 x 1048576 -> 0.062185788s, 269.791.805 bytes/s
+ md5: 100 x 1048576 -> 0.388526572s, 269.885.273 bytes/s
+ md5: 1000 x 1048576 -> 3.899700600s, 268.886.283 bytes/s
+ sha1: 1 x 0 -> 0.000005877s, 0 bytes/s
+ sha1: 1048576 x 0 -> 0.340648155s, 0 bytes/s
+ sha1: 1 x 16 -> 0.000008329s, 1.920.998 bytes/s
+ sha1: 1048576 x 16 -> 0.509808543s, 32.908.856 bytes/s
+ sha1: 16 x 1024 -> 0.000159847s, 102.498.013 bytes/s
+ sha1: 16384 x 1024 -> 0.165871684s, 101.145.750 bytes/s
+ sha1: 16 x 1048576 -> 0.146010257s, 114.904.365 bytes/s
+ sha1: 100 x 1048576 -> 0.911497730s, 115.038.794 bytes/s
+ sha1: 1000 x 1048576 -> 9.126493727s, 114.893.630 bytes/s
+sha256: 1 x 0 -> 0.000010657s, 0 bytes/s
+sha256: 1048576 x 0 -> 0.340843492s, 0 bytes/s
+sha256: 1 x 16 -> 0.000004360s, 3.669.724 bytes/s
+sha256: 1048576 x 16 -> 0.613874241s, 27.330.053 bytes/s
+sha256: 16 x 1024 -> 0.000259229s, 63.202.805 bytes/s
+sha256: 16384 x 1024 -> 0.250969198s, 66.849.701 bytes/s
+sha256: 16 x 1048576 -> 0.247802951s, 67.703.858 bytes/s
+sha256: 100 x 1048576 -> 1.553324694s, 67.505.268 bytes/s
+sha256: 1000 x 1048576 -> 15.557616964s, 67.399.525 bytes/s
+sha512: 1 x 0 -> 0.000012079s, 0 bytes/s
+sha512: 1048576 x 0 -> 0.345451653s, 0 bytes/s
+sha512: 1 x 16 -> 0.000007218s, 2.216.680 bytes/s
+sha512: 1048576 x 16 -> 0.975005743s, 17.207.299 bytes/s
+sha512: 16 x 1024 -> 0.000661291s, 24.775.779 bytes/s
+sha512: 16384 x 1024 -> 0.612676930s, 27.383.462 bytes/s
+sha512: 16 x 1048576 -> 0.606441419s, 27.665.023 bytes/s
+sha512: 100 x 1048576 -> 3.789441963s, 27.670.987 bytes/s
+sha512: 1000 x 1048576 -> 37.944704131s, 27.634.317 bytes/s
+
+
+======= --with-crypto-api=beecrypt =========
+ md5: 1 x 0 -> 0.000023938s, 0 bytes/s
+ md5: 1048576 x 0 -> 0.058107490s, 0 bytes/s
+ md5: 1 x 16 -> 0.000003805s, 4.204.993 bytes/s
+ md5: 1048576 x 16 -> 0.123594359s, 135.744.188 bytes/s
+ md5: 16 x 1024 -> 0.000053382s, 306.919.935 bytes/s
+ md5: 16384 x 1024 -> 0.050902371s, 329.595.963 bytes/s
+ md5: 16 x 1048576 -> 0.049934429s, 335.984.937 bytes/s
+ md5: 100 x 1048576 -> 0.322439450s, 325.200.902 bytes/s
+ md5: 1000 x 1048576 -> 3.119201490s, 336.168.087 bytes/s
+ sha1: 1 x 0 -> 0.000004520s, 0 bytes/s
+ sha1: 1048576 x 0 -> 0.054753513s, 0 bytes/s
+ sha1: 1 x 16 -> 0.000001847s, 8.662.696 bytes/s
+ sha1: 1048576 x 16 -> 0.179519878s, 93.456.034 bytes/s
+ sha1: 16 x 1024 -> 0.000110003s, 148.941.392 bytes/s
+ sha1: 16384 x 1024 -> 0.115976962s, 144.659.902 bytes/s
+ sha1: 16 x 1048576 -> 0.105239505s, 159.419.373 bytes/s
+ sha1: 100 x 1048576 -> 0.656445997s, 159.735.302 bytes/s
+ sha1: 1000 x 1048576 -> 6.719054793s, 156.060.045 bytes/s
+sha256: 1 x 0 -> 0.000011564s, 0 bytes/s
+sha256: 1048576 x 0 -> 0.068358959s, 0 bytes/s
+sha256: 1 x 16 -> 0.000003228s, 4.956.629 bytes/s
+sha256: 1048576 x 16 -> 0.354763055s, 47.291.328 bytes/s
+sha256: 16 x 1024 -> 0.000263999s, 62.060.841 bytes/s
+sha256: 16384 x 1024 -> 0.259517650s, 64.647.687 bytes/s
+sha256: 16 x 1048576 -> 0.257160705s, 65.240.200 bytes/s
+sha256: 100 x 1048576 -> 1.604815811s, 65.339.336 bytes/s
+sha256: 1000 x 1048576 -> 16.418434570s, 63.865.772 bytes/s
+sha512: 1 x 0 -> 0.000040958s, 0 bytes/s
+sha512: 1048576 x 0 -> 0.080563994s, 0 bytes/s
+sha512: 1 x 16 -> 0.000007829s, 2.043.683 bytes/s
+sha512: 1048576 x 16 -> 0.875192486s, 19.169.744 bytes/s
+sha512: 16 x 1024 -> 0.000784418s, 20.886.823 bytes/s
+sha512: 16384 x 1024 -> 0.774741496s, 21.655.243 bytes/s
+sha512: 16 x 1048576 -> 0.772724538s, 21.711.768 bytes/s
+sha512: 100 x 1048576 -> 4.879952557s, 21.487.422 bytes/s
+sha512: 1000 x 1048576 -> 48.663248611s, 21.547.595 bytes/s
+
+
+
+============================
+
+VIA C7, 1.2GHz, 1GiB RAM, Fedora 8 i386
+
+======== --with-crypto-api=nss ============
+ md5: 1 x 0 -> 0.000000001s, 0 bytes/s
+ md5: 1048576 x 0 -> 1.300000000s, 0 bytes/s
+ md5: 1 x 16 -> 0.000000001s, 16.000.000.000 bytes/s
+ md5: 1048576 x 16 -> 1.480000000s, 11.335.956 bytes/s
+ md5: 16 x 1024 -> 0.000000001s, 16.384.000.000.000 bytes/s
+ md5: 16384 x 1024 -> 0.260000000s, 64.527.753 bytes/s
+ md5: 16 x 1048576 -> 0.260000000s, 64.527.753 bytes/s
+ md5: 100 x 1048576 -> 1.600000000s, 65.536.000 bytes/s
+ md5: 1000 x 1048576 -> 15.980000000s, 65.618.022 bytes/s
+ sha1: 1 x 0 -> 0.000000001s, 0 bytes/s
+ sha1: 1048576 x 0 -> 1.120000000s, 0 bytes/s
+ sha1: 1 x 16 -> 0.000000001s, 16.000.000.000 bytes/s
+ sha1: 1048576 x 16 -> 1.820000000s, 9.218.250 bytes/s
+ sha1: 16 x 1024 -> 0.000000001s, 16.384.000.000.000 bytes/s
+ sha1: 16384 x 1024 -> 0.600000000s, 27.962.026 bytes/s
+ sha1: 16 x 1048576 -> 0.610000000s, 27.503.632 bytes/s
+ sha1: 100 x 1048576 -> 3.780000000s, 27.740.105 bytes/s
+ sha1: 1000 x 1048576 -> 37.760000000s, 27.769.491 bytes/s
+sha256: 1 x 0 -> 0.000000001s, 0 bytes/s
+sha256: 1048576 x 0 -> 1.120000000s, 0 bytes/s
+sha256: 1 x 16 -> 0.000000001s, 16.000.000.000 bytes/s
+sha256: 1048576 x 16 -> 2.220000000s, 7.557.304 bytes/s
+sha256: 16 x 1024 -> 0.010000000s, 1.638.400 bytes/s
+sha256: 16384 x 1024 -> 1.000000000s, 16.777.216 bytes/s
+sha256: 16 x 1048576 -> 1.000000000s, 16.777.216 bytes/s
+sha256: 100 x 1048576 -> 6.280000000s, 16.697.070 bytes/s
+sha256: 1000 x 1048576 -> 62.890000000s, 16.673.175 bytes/s
+sha512: 1 x 0 -> 0.000000001s, 0 bytes/s
+sha512: 1048576 x 0 -> 1.120000000s, 0 bytes/s
+sha512: 1 x 16 -> 0.000000001s, 16.000.000.000 bytes/s
+sha512: 1048576 x 16 -> 3.550000000s, 4.725.976 bytes/s
+sha512: 16 x 1024 -> 0.010000000s, 1.638.400 bytes/s
+sha512: 16384 x 1024 -> 2.350000000s, 7.139.240 bytes/s
+sha512: 16 x 1048576 -> 2.380000000s, 7.049.250 bytes/s
+sha512: 100 x 1048576 -> 14.770000000s, 7.099.363 bytes/s
+sha512: 1000 x 1048576 -> 147.610000000s, 7.103.692 bytes/s
+
+
+======== --with-crypto-api=beecrypt ======
+ md5: 1 x 0 -> 0.000000001s, 0 bytes/s
+ md5: 1048576 x 0 -> 0.390000000s, 0 bytes/s
+ md5: 1 x 16 -> 0.000000001s, 3.115.098.112 bytes/s
+ md5: 1048576 x 16 -> 0.510000000s, 32.896.501 bytes/s
+ md5: 16 x 1024 -> 0.000000001s, 2.994.733.056 bytes/s
+ md5: 16384 x 1024 -> 0.230000000s, 72.944.417 bytes/s
+ md5: 16 x 1048576 -> 0.240000000s, 69.905.066 bytes/s
+ md5: 100 x 1048576 -> 1.520000000s, 68.985.263 bytes/s
+ md5: 1000 x 1048576 -> 15.220000000s, 68.894.612 bytes/s
+ sha1: 1 x 0 -> 0.000000001s, 0 bytes/s
+ sha1: 1048576 x 0 -> 0.190000000s, 0 bytes/s
+ sha1: 1 x 16 -> 0.000000001s, 3.115.098.112 bytes/s
+ sha1: 1048576 x 16 -> 0.700000000s, 23.967.451 bytes/s
+ sha1: 16 x 1024 -> 0.000000001s, 2.994.733.056 bytes/s
+ sha1: 16384 x 1024 -> 0.430000000s, 39.016.781 bytes/s
+ sha1: 16 x 1048576 -> 0.440000000s, 38.130.036 bytes/s
+ sha1: 100 x 1048576 -> 2.730000000s, 38.409.377 bytes/s
+ sha1: 1000 x 1048576 -> 27.230000000s, 38.508.116 bytes/s
+sha256: 1 x 0 -> 0.000000001s, 0 bytes/s
+sha256: 1048576 x 0 -> 0.200000000s, 0 bytes/s
+sha256: 1 x 16 -> 0.000000001s, 3.115.098.112 bytes/s
+sha256: 1048576 x 16 -> 1.360000000s, 12.336.188 bytes/s
+sha256: 16 x 1024 -> 0.000000001s, 2.994.733.056 bytes/s
+sha256: 16384 x 1024 -> 1.100000000s, 15.252.014 bytes/s
+sha256: 16 x 1048576 -> 1.110000000s, 15.114.609 bytes/s
+sha256: 100 x 1048576 -> 6.920000000s, 15.152.832 bytes/s
+sha256: 1000 x 1048576 -> 69.290000000s, 15.133.150 bytes/s
+sha512: 1 x 0 -> 0.000000001s, 0 bytes/s
+sha512: 1048576 x 0 -> 0.260000000s, 0 bytes/s
+sha512: 1 x 16 -> 0.000000001s, 3.115.098.112 bytes/s
+sha512: 1048576 x 16 -> 2.950000000s, 5.687.191 bytes/s
+sha512: 16 x 1024 -> 0.000000001s, 2.994.733.056 bytes/s
+sha512: 16384 x 1024 -> 2.600000000s, 6.452.775 bytes/s
+sha512: 16 x 1048576 -> 2.630000000s, 6.379.169 bytes/s
+sha512: 100 x 1048576 -> 16.400000000s, 6.393.756 bytes/s
+sha512: 1000 x 1048576 -> 164.250000000s, 6.384.024 bytes/s
--- /dev/null
+/* --*- c -*--
+ * Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 and/or 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define ENSC_TESTSUITE
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <lib_internal/crypto-wrapper.h>
+#include <lib_internal/coreassert.h>
+#include <time.h>
+#include <locale.h>
+
+
+static void
+do_benchmark(char const *meth_name)
+{
+ struct {
+ size_t block_size;
+ size_t blocks;
+ } const DATA_SIZES[] = {
+ { 0, 1 },
+ { 0, 1024*1024 },
+ { 16, 1 },
+ { 16, 1024*1024 },
+ { 1024, 16 },
+ { 1024, 16*1024 },
+ { 1024*1024, 16 },
+ { 1024*1024, 100 },
+ { 1024*1024, 1000 }
+ };
+
+ ensc_hash_method const *m = ensc_crypto_hash_find(meth_name);
+ ensc_hash_context ctx;
+ size_t d_len = m ? ensc_crypto_hash_get_digestsize(m) : 0;
+ char digest[d_len];
+ char * buf;
+ size_t i;
+
+ assert(m);
+ assert(ensc_crypto_hashctx_init(&ctx, m)==0);
+
+ for (i=0; i<sizeof(DATA_SIZES)/sizeof(DATA_SIZES[0]); ++i) {
+ size_t cnt = DATA_SIZES[i].blocks;
+ size_t const bs = DATA_SIZES[i].block_size;
+ struct timespec tm_start, tm_end, delta;
+ uint64_t bps;
+
+ buf = malloc(bs+1); /* avoid malloc-0 confusions */
+ assert(buf);
+
+ memset(buf, 0x11, bs);
+
+ ensc_crypto_hashctx_reset(&ctx);
+
+ /* benchmarked code starts here... */
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tm_start);
+ while (cnt--)
+ ensc_crypto_hashctx_update(&ctx, buf, bs);
+
+ ensc_crypto_hashctx_get_digest(&ctx, digest, NULL, d_len);
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tm_end);
+ /* ... and ends here */
+
+ delta.tv_sec = tm_end.tv_sec - tm_start.tv_sec;
+ if (tm_end.tv_nsec < tm_start.tv_nsec) {
+ --delta.tv_sec;
+ tm_end.tv_nsec += 1000000000l;
+ }
+ delta.tv_nsec = tm_end.tv_nsec - tm_start.tv_nsec;
+
+ if (delta.tv_nsec==0 && delta.tv_sec==0)
+ delta.tv_nsec = 1;
+
+ bps = (uint64_t)(DATA_SIZES[i].blocks) * bs * 1000000000;
+ bps /= (uint64_t)(delta.tv_sec) * 1000000000 + delta.tv_nsec;
+
+ printf("%6s: %7zu x %-7zu -> %2lu.%09lus, %'15llu bytes/s\n",
+ meth_name, DATA_SIZES[i].blocks, bs,
+ delta.tv_sec, delta.tv_nsec, (unsigned long long)(bps));
+ }
+
+ ensc_crypto_hashctx_free(&ctx);
+}
+
+int main()
+{
+ char const * const METHS[] = {
+ "md5", "sha1", "sha256", "sha512", NULL
+ };
+ char const * const * meth;
+
+ ensc_crypto_init();
+ setlocale(LC_NUMERIC, ""); /* needed for the thousands grouping */
+
+ for (meth=METHS+0; *meth; ++meth)
+ do_benchmark(*meth);
+}
--- /dev/null
+/* --*- c -*--
+ * Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 and/or 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define ENSC_TESTSUITE
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <lib_internal/crypto-wrapper.h>
+#include <lib_internal/coreassert.h>
+
+static unsigned int
+hex2digit(char c)
+{
+ if (c>='0' && c<='9')
+ return c-'0';
+ c &= ~0x20;
+ if (c>='A' && c<='F')
+ return c-'A' + 10;
+
+ assert(0);
+ return 0;
+}
+
+static void
+convert_digest_ascii2bin(void *dst_v, char const *digest, size_t d_len)
+{
+ unsigned char *dst = dst_v;
+
+ while (d_len>0) {
+ *dst = hex2digit(*digest++)<<4;
+ *dst |= hex2digit(*digest++);
+
+ ++dst;
+ --d_len;
+ }
+}
+
+static void
+test_digest(char const *name, size_t d_len,
+ void const *buf, size_t buf_len,
+ char const *digest)
+{
+ ensc_hash_method const *m = ensc_crypto_hash_find(name);
+ ensc_hash_context ctx;
+ unsigned char *exp_digest[d_len/8];
+ unsigned char *bin_digest[d_len/8];
+ size_t bin_digest_len;
+ size_t i;
+
+ d_len /= 8;
+ convert_digest_ascii2bin(exp_digest, digest, d_len);
+
+ assert(m);
+ assert(ensc_crypto_hash_get_digestsize(m)==d_len);
+
+ {
+ char const *tmp_name = ensc_crypto_hash_get_name(m);
+ ensc_hash_method const *tmp_meth = tmp_name ? ensc_crypto_hash_find(tmp_name) : NULL;
+
+ assert(tmp_name!=NULL);
+ assert(tmp_meth!=NULL);
+ assert(ensc_crypto_hash_get_digestsize(tmp_meth)==d_len);
+ }
+
+ ensc_crypto_hashctx_init(&ctx, m);
+ assert(ensc_crypto_hashctx_get_digestsize(&ctx)==d_len);
+
+ /* run it multiple times to test for correct reset/init behavior */
+ for (i=0; i<3; ++i) {
+ assert(ensc_crypto_hashctx_reset(&ctx)==0);
+ assert(ensc_crypto_hashctx_update(&ctx, buf, buf_len)==0);
+
+ switch (i) {
+ case 0:
+ case 2:
+ break;
+
+ case 1:
+ assert(ensc_crypto_hashctx_update(&ctx, "gremlin", 7)==0);
+ break;
+ }
+
+ assert(ensc_crypto_hashctx_get_digest(&ctx, bin_digest, &bin_digest_len, d_len)==0);
+ assert(bin_digest_len==d_len);
+
+
+ switch (i) {
+ case 0:
+ case 2:
+ assert(memcmp(exp_digest, bin_digest, d_len)==0);
+ break;
+
+ case 1:
+ assert(memcmp(exp_digest, bin_digest, d_len)!=0);
+ break;
+ }
+ }
+
+ ensc_crypto_hashctx_free(&ctx);
+}
+
+int main()
+{
+ ensc_crypto_init();
+ assert(ensc_crypto_hash_get_default()!=NULL);
+
+ /* MD-5 */
+
+ test_digest("md5", 128, "", 0, "d41d8cd98f00b204e9800998ecf8427e");
+ test_digest("md-5", 128, "", 0, "d41d8cd98f00b204e9800998ecf8427e");
+ test_digest("MD5", 128, "", 0, "d41d8cd98f00b204e9800998ecf8427e");
+ test_digest("MD-5", 128, "", 0, "d41d8cd98f00b204e9800998ecf8427e");
+
+ test_digest("md5", 128, "foo", 3, "acbd18db4cc2f85cedef654fccc4a4d8");
+
+ /* SHA-1 */
+ test_digest("sha1", 160, "", 0, "da39a3ee5e6b4b0d3255bfef95601890afd80709");
+ test_digest("sha-1", 160, "", 0, "da39a3ee5e6b4b0d3255bfef95601890afd80709");
+ test_digest("SHA1", 160, "", 0, "da39a3ee5e6b4b0d3255bfef95601890afd80709");
+ test_digest("SHA-1", 160, "", 0, "da39a3ee5e6b4b0d3255bfef95601890afd80709");
+
+ test_digest("sha1", 160, "foo", 3, "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33");
+
+ /* SHA-256 */
+ test_digest("sha256", 256, "", 0, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+ test_digest("sha-256", 256, "", 0, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+ test_digest("SHA256", 256, "", 0, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+ test_digest("SHA-256", 256, "", 0, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+
+ test_digest("sha256", 256, "foo", 3, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae");
+
+#if ENSC_CRYPTO_API != ENSC_CRYPTO_API_BEECRYPT /* see comments in crypto-wrapper-beecrypt.h */
+ /* SHA-384 */
+ test_digest("sha384", 384, "", 0, "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
+ test_digest("sha-384", 384, "", 0, "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
+ test_digest("SHA384", 384, "", 0, "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
+ test_digest("SHA-384", 384, "", 0, "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
+
+ test_digest("sha384", 384, "foo", 3, "98c11ffdfdd540676b1a137cb1a22b2a70350c9a44171d6b1180c6be5cbb2ee3f79d532c8a1dd9ef2e8e08e752a3babb");
+#endif
+
+ /* SHA-512 */
+ test_digest("sha512", 512, "", 0, "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
+ test_digest("sha-512", 512, "", 0, "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
+ test_digest("SHA512", 512, "", 0, "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
+ test_digest("SHA-512", 512, "", 0, "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
+
+ test_digest("sha512", 512, "foo", 3, "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7");
+}
src/vspace \
src/vmemctrl
-if ENSC_CAN_BEECRYPT_WITH_DIETLIBC
+if ENSC_CAN_CRYPTO_WITH_DIETLIBC
DIETPROGS += src/vhashify
endif
$(src_pkglib_CXX_X_PROGS)
if ENSC_HAVE_C99_COMPILER
-if ENSC_HAVE_BEECRYPT
+if ENSC_HAVE_CRYPTO
pkglib_PROGRAMS += src/vhashify
-endif ENSC_HAVE_BEECRYPT
+endif ENSC_HAVE_CRYPTO
endif ENSC_HAVE_C99_COMPILER
legacy_PROGRAMS += src/ifspec \
src_vunify_LDFLAGS = $(VSERVER_LDFLGS)
src_vhashify_SOURCES = src/vhashify.c
-if ENSC_CAN_BEECRYPT_WITH_DIETLIBC
-src_vhashify_LDADD = $(LIBINTERNAL) $(LIBENSCVECTOR) -lbeecrypt $(VSERVER_LDADDS)
+src_vhashify_CFLAGS = $(AM_CFLAGS) $(ENSC_CRYPTO_CFLAGS)
+if ENSC_CAN_CRYPTO_WITH_DIETLIBC
+src_vhashify_LDADD = $(LIBINTERNAL) $(LIBENSCVECTOR) $(ENSC_CRYPTO_LIB) $(VSERVER_LDADDS)
src_vhashify_LDFLAGS = $(VSERVER_LDFLGS)
else
-src_vhashify_LDADD = $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) -lbeecrypt
-src_vhashify_LDFLAGS =
+src_vhashify_LDADD = $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) $(ENSC_CRYPTO_LIB)
+src_vhashify_LDFLAGS = -Wl,--as-needed
endif
src_vuname_SOURCES = src/vuname.c
src_testsuite_check_passive_PRGS = src/testsuite/rpm-fake-test
if ENSC_HAVE_C99_COMPILER
-if ENSC_HAVE_BEECRYPT
+if ENSC_HAVE_CRYPTO
src_testsuite_check_passive_PRGS += src/testsuite/hashcalc \
src/testsuite/hashcalc-plain
endif
if ENSC_HAVE_C99_COMPILER
src_testsuite_check_src_C99_SCRPTS = src/testsuite/vunify-test.sh
-if ENSC_HAVE_BEECRYPT
+if ENSC_HAVE_CRYPTO
src_testsuite_check_src_C99_SCRPTS += src/testsuite/hashcalc-plain.sh \
src/testsuite/hashcalc.sh
endif
src_testsuite_hashcalc_SOURCES = src/testsuite/hashcalc.c
src_testsuite_hashcalc_plain_SOURCES = src/testsuite/hashcalc-plain.c
-if ENSC_CAN_BEECRYPT_WITH_DIETLIBC
-src_testsuite_hashcalc_LDADD = $(LIBINTERNAL) $(LIBENSCVECTOR) -lbeecrypt $(VSERVER_LDADDS)
+src_testsuite_hashcalc_CFLAGS = $(AM_CFLAGS) $(ENSC_CRYPTO_CFLAGS)
+src_testsuite_hashcalc_plain_CFLAGS = $(AM_CFLAGS) $(ENSC_CRYPTO_CFLAGS)
+
+if ENSC_CAN_CRYPTO_WITH_DIETLIBC
+src_testsuite_hashcalc_LDADD = $(LIBINTERNAL) $(LIBENSCVECTOR) $(ENSC_CRYPTO_LIB) $(VSERVER_LDADDS)
src_testsuite_hashcalc_LDFLAGS = $(VSERVER_LDFLGS)
-src_testsuite_hashcalc_plain_LDADD = $(LIBINTERNAL) $(LIBENSCVECTOR) -lbeecrypt $(VSERVER_LDADDS)
+src_testsuite_hashcalc_plain_LDADD = $(LIBINTERNAL) $(LIBENSCVECTOR) $(ENSC_CRYPTO_LIB) $(VSERVER_LDADDS)
src_testsuite_hashcalc_plain_LDFLAGS = $(VSERVER_LDFLGS)
else
-src_testsuite_hashcalc_LDADD = $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) -lbeecrypt
-src_testsuite_hashcalc_LDFLAGS =
+src_testsuite_hashcalc_LDADD = $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) $(ENSC_CRYPTO_LIB)
+src_testsuite_hashcalc_LDFLAGS = -Wl,--as-needed
-src_testsuite_hashcalc_plain_LDADD = $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) -lbeecrypt
-src_testsuite_hashcalc_plain_LDFLAGS =
+src_testsuite_hashcalc_plain_LDADD = $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) $(ENSC_CRYPTO_LIB)
+src_testsuite_hashcalc_plain_LDFLAGS = -Wl,--as-needed
endif
src_testsuite_CPPFLAGS = -I $(top_srcdir)/src -D ENSC_TESTSUITE
# include <config.h>
#endif
-#include <beecrypt/beecrypt.h>
+#include <lib_internal/crypto-wrapper.h>
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#define HASH_BLOCKSIZE 0x10000000u
static bool
-convertDigest(char res[], hashFunctionContext * h_ctx)
+convertDigest(char res[], ensc_hash_context * h_ctx)
{
static char const HEX_DIGIT[] = "0123456789abcdef";
- size_t d_size = h_ctx->algo->digestsize;
+ size_t d_size = ensc_crypto_hashctx_get_digestsize(h_ctx);
unsigned char digest[d_size];
size_t out = 0;
- if (hashFunctionContextDigest(h_ctx, digest)==-1)
+ if (ensc_crypto_hashctx_get_digest(h_ctx, digest, NULL, d_size)==-1)
return false;
for (size_t in=0; in<d_size; ++in) {
int main(int UNUSED argc, char *argv[])
{
- int fd = open(argv[1], O_NOFOLLOW|O_NONBLOCK|O_RDONLY|O_NOCTTY);
- hashFunctionContext hash_context;
- hashFunction const *method;
- struct stat st;
- off_t size;
- loff_t offset = 0;
- char digest[1024];
+ int fd = open(argv[1], O_NOFOLLOW|O_NONBLOCK|O_RDONLY|O_NOCTTY);
+ ensc_hash_context hash_context;
+ ensc_hash_method const *method;
+ struct stat st;
+ off_t size;
+ loff_t offset = 0;
+ char digest[2048];
- assert((method = hashFunctionFind(argv[2]))!=0);
- assert(hashFunctionContextInit(&hash_context, method)!=-1);
+ ensc_crypto_init();
+ assert((method = ensc_crypto_hash_find(argv[2]))!=0);
+ assert(ensc_crypto_hashctx_init(&hash_context, method)!=-1);
assert(fstat(fd, &st)!=-1);
- assert(hashFunctionContextReset(&hash_context)!=-1);
+ assert(ensc_crypto_hashctx_reset(&hash_context)!=-1);
size = st.st_size;
assert((buf=mmap(0, buf_size, PROT_READ, MAP_SHARED, fd, offset))!=0);
offset += buf_size;
- assert(hashFunctionContextUpdate(&hash_context, buf, buf_size)!=-1);
+ assert(ensc_crypto_hashctx_update(&hash_context, buf, buf_size)!=-1);
munmap((void *)(buf), buf_size);
}
Vwrite(1, digest, strlen(digest));
Vwrite(1, "\n", 1);
- hashFunctionContextFree(&hash_context);
+ ensc_crypto_hashctx_free(&hash_context);
return 0;
}
volatile unsigned int canary2;
volatile unsigned int canary3;
} __attribute__((__packed__)) d_path;
-
+
d_path.canary0 = 0x12345678;
d_path.canary1 = 0x21436587;
d_path.canary2 = 0x89abcdef;
d_path.canary3 = 0x98badcfe;
memset(d_path.d, 0x66, sizeof d_path.d);
- global_info.hash_conf.method = hashFunctionFind(argv[2]);
+ ensc_crypto_init();
+ global_info.hash_conf.method = ensc_crypto_hash_find(argv[2]);
- assert(hashFunctionContextInit(&global_info.hash_context,
- global_info.hash_conf.method)!=-1);
+ assert(ensc_crypto_hashctx_init(&global_info.hash_context,
+ global_info.hash_conf.method)!=-1);
assert(fstat(fd, &st)!=-1);
Vwrite(1, d_path.d, strlen(d_path.d));
Vwrite(1, "\n", 1);
- hashFunctionContextFree(&global_info.hash_context);
+ ensc_crypto_hashctx_free(&global_info.hash_context);
return 0;
}
} &>/dev/null
for i in $tmpdir/rand-*; do
- sha1_0=$($hashcalc "$i" SHA-1 | tr -d / )
- sha1_1=$(sha1sum "$i" | awk '{ print $1}' )
+ for m in md5 sha1 sha256 sha512; do
+ sum_0=$($hashcalc "$i" "$m" | tr -d / )
+ sum_1=$(${m}sum "$i" | awk '{ print $1}' )
- test x"$sha1_0" = x"$sha1_1" || {
- echo "SHA-1 mismatch at $(basename $i)"
- exit 1
- }
-
- md5_0=$($hashcalc "$i" MD5 | tr -d / )
- md5_1=$(md5sum "$i" | awk '{ print $1}' )
-
- test x"$md5_0" = x"$md5_1" || {
- echo "MD5 mismatch at $(basename $i)"
- exit 1
- }
+ # compare only the first 80 chars as vhashify will cut digest to MAXPATHLEN
+ test x"${sum_0::80}" = x"${sum_1::80}" || {
+ echo "$m mismatch at $(basename $i): '$sum_0' vs. '$sum_1'"
+ exit 1
+ }
+ done
done
true
{
int fd = open(filename, O_RDONLY);
if (fd==-1 && conf->method==0)
- conf->method = hashFunctionDefault();
+ conf->method = ensc_crypto_hash_get_default();
if (fd==-1) {
+ char const *hash_name;
assert(conf->method!=0);
if (conf->method==0) return false;
if (global_args->dry_run) return true; // do not create the file
-
+
fd = Eopen(filename, O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW, 0644);
- TEMP_FAILURE_RETRY(write(fd, conf->method->name, strlen(conf->method->name)));
+
+ hash_name = ensc_crypto_hash_get_name(conf->method);
+ TEMP_FAILURE_RETRY(write(fd, hash_name, strlen(hash_name)));
TEMP_FAILURE_RETRY(write(fd, "\n", 1));
}
else {
--s;
buf[s] = '\0';
- conf->method = hashFunctionFind(buf);
+ conf->method = ensc_crypto_hash_find(buf);
if (conf->method==0) {
WRITE_MSG(2, "Can not find hash-function '");
WRITE_STR(2, buf);
WRITE_MSG(2, "Can not read configuration file for hash-method\n");
}
- if (conf->method!=0 && conf->method->digestsize*8>HASH_MAXBITS) {
+ if (conf->method!=0 && ensc_crypto_hash_get_digestsize(conf->method)*8>HASH_MAXBITS) {
WRITE_MSG(2, "Wow... what an huge hash-function. I can not handle so much bits; giving up...\n");
conf->method=0;
}
#include "lib_internal/unify.h"
#include "ensc_vector/vector.h"
-#include <beecrypt/beecrypt.h>
+#include "lib_internal/crypto-wrapper.h"
#include <setjmp.h>
#include <unistd.h>
struct HashDirConfiguration
{
- hashFunction const *method;
+ ensc_hash_method const *method;
enum { hshALL=0, hshSTART = 1, hshMIDDLE=2,
hshEND = 4, hshINVALID = -1 } blocks;
size_t blocksize;
HashDirCollection hash_dirs;
size_t hash_dirs_max_size;
- hashFunctionContext hash_context;
+ ensc_hash_context hash_context;
};
int wrapper_exit_code = 1;
convertDigest(HashPath d_path)
{
static char const HEX_DIGIT[] = "0123456789abcdef";
- hashFunctionContext * const h_ctx = &global_info.hash_context;
- size_t d_size = h_ctx->algo->digestsize;
-
+ ensc_hash_context * const h_ctx = &global_info.hash_context;
+ size_t d_size = ensc_crypto_hashctx_get_digestsize(h_ctx);
+
unsigned char digest[d_size];
size_t out = 0;
- if (hashFunctionContextDigest(h_ctx, digest)==-1)
+ if (ensc_crypto_hashctx_get_digest(h_ctx, digest, NULL, d_size)==-1)
return false;
for (size_t in=0;
#ifndef ENSC_TESTSUITE
static bool
-addStatHash(hashFunctionContext *h_ctx, struct stat const * const st)
+addStatHash(ensc_hash_context *h_ctx, struct stat const * const st)
{
#define DECL_ATTR(X) __typeof__(st->st_##X) X
#define SET_ATTR(X) .X = st->st_##X
#undef DECL_ATTR
- return hashFunctionContextUpdate(h_ctx, (void *)&tmp, sizeof tmp)!=-1;
+ return ensc_crypto_hashctx_update(h_ctx, (void *)&tmp, sizeof tmp)!=-1;
}
#else
static bool
-addStatHash(hashFunctionContext UNUSED *h_ctx, struct stat const UNUSED * const st)
+addStatHash(ensc_hash_context UNUSED *h_ctx, struct stat const UNUSED * const st)
{
return true;
}
static bool
calculateHashFromFD(int fd, HashPath d_path, struct stat const * const st)
{
- hashFunctionContext * const h_ctx = &global_info.hash_context;
+ ensc_hash_context * const h_ctx = &global_info.hash_context;
void const * volatile buf = 0;
loff_t volatile buf_size = 0;
bool volatile res = false;
- if (hashFunctionContextReset(h_ctx)==-1 ||
+ if (ensc_crypto_hashctx_reset(h_ctx)==-1 ||
!addStatHash(h_ctx, st))
return false;
offset += buf_size;
madvise(const_cast(void *)(buf), buf_size, MADV_SEQUENTIAL); // ignore error...
- if (hashFunctionContextUpdate(h_ctx, buf, buf_size)==-1) goto out;
+ if (ensc_crypto_hashctx_update(h_ctx, buf, buf_size)==-1) goto out;
munmap(const_cast(void *)(buf), buf_size);
buf = 0;
return EXIT_FAILURE;
}
+ ensc_crypto_init();
switch (args.mode) {
case mdMANUALLY : initModeManually(&args, argc-optind, argv+optind); break;
case mdVSERVER : initModeVserver (&args, argc-optind, argv+optind); break;
default : assert(false); return EXIT_FAILURE;
};
- if (hashFunctionContextInit(&global_info.hash_context,
- global_info.hash_conf.method)==-1) {
+ if (ensc_crypto_hashctx_init(&global_info.hash_context,
+ global_info.hash_conf.method)==-1) {
WRITE_MSG(2, "Failed to initialize hash-context\n");
return EXIT_FAILURE;
}
#ifndef NDEBUG
MatchList_destroy(&global_info.dst_list);
freeHashList(&global_info.hash_dirs);
- hashFunctionContextFree(&global_info.hash_context);
+ ensc_crypto_hashctx_free(&global_info.hash_context);
#endif
return EXIT_SUCCESS;