From 0ffa9e2385588b7b15aac9d0322187d5a31ec336 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 8 Apr 2015 12:21:59 +0100 Subject: [PATCH] Rework siphash internal API. --- src/libcryptobox/CMakeLists.txt | 3 +++ src/libcryptobox/siphash/ref.c | 9 +++++---- src/libcryptobox/siphash/siphash.c | 27 ++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/libcryptobox/CMakeLists.txt b/src/libcryptobox/CMakeLists.txt index 491d7f9b5..ecd729d6a 100644 --- a/src/libcryptobox/CMakeLists.txt +++ b/src/libcryptobox/CMakeLists.txt @@ -54,6 +54,9 @@ IF(HAVE_SSE2) SET(CHACHASRC ${CHACHASRC} ${CMAKE_CURRENT_SOURCE_DIR}/chacha20/sse2.S) SET(POLYSRC ${POLYSRC} ${CMAKE_CURRENT_SOURCE_DIR}/poly1305/sse2.S) ENDIF(HAVE_SSE2) +IF(HAVE_SSE41) + SET(SIPHASHSRC ${SIPHASHSRC} ${CMAKE_CURRENT_SOURCE_DIR}/siphash/sse41.S) +ENDIF(HAVE_SSE41) CONFIGURE_FILE(platform_config.h.in platform_config.h) INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}") diff --git a/src/libcryptobox/siphash/ref.c b/src/libcryptobox/siphash/ref.c index 2b20ae34d..1a09f2066 100644 --- a/src/libcryptobox/siphash/ref.c +++ b/src/libcryptobox/siphash/ref.c @@ -62,8 +62,8 @@ } while(0) -void -siphash_ref (uint8_t *out, const uint8_t *in, uint64_t inlen, const uint8_t *k) +uint64_t +siphash_ref (const unsigned char k[16], const unsigned char *in, const uint64_t inlen) { /* "somepseudorandomlygeneratedbytes" */ uint64_t v0 = 0x736f6d6570736575ULL; @@ -137,7 +137,7 @@ siphash_ref (uint8_t *out, const uint8_t *in, uint64_t inlen, const uint8_t *k) ; b = v0 ^ v1 ^ v2 ^ v3; - U64TO8_LE(out, b); + return b; #ifdef DOUBLE v1 ^= 0xdd; @@ -146,6 +146,7 @@ siphash_ref (uint8_t *out, const uint8_t *in, uint64_t inlen, const uint8_t *k) for( i=0; idesc); } void siphash24 (unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) { - siphash_opt->siphash (out, in, inlen, k); + uint64_t r; + + r = siphash_opt->siphash (k, in, inlen); + memcpy (out, &r, sizeof (r)); } size_t -siphash24_test (void) { +siphash24_test (bool generic) +{ static const unsigned char vectors[64][8] = { { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, }, { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, }, @@ -159,7 +171,12 @@ siphash24_test (void) { for (i = 0; i < sizeof in; ++i) { in[i] = i; - siphash24 (r.c, in, i, k); + if (generic) { + r.m = siphash_list[0].siphash (k, in, i); + } + else { + r.m = siphash_opt->siphash (k, in, i); + } if (memcmp (r.c, vectors[i], sizeof (r)) != 0) { return 0; } -- 2.39.5