From 2742547a274f05b626805c5623ccc5f5b6c00b4e Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 14 Nov 2015 14:34:34 +0100 Subject: [PATCH] Link poly1305_sse2 Breakage is expected as partial blocks are not handled yet --- src/libsodium/Makefile.am | 4 +++- .../poly1305/onetimeauth_poly1305.c | 11 ++++++++- .../poly1305/sse2/poly1305_sse2.c | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index d251937c..670f29d2 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -299,7 +299,9 @@ libsse2_la_LDFLAGS = $(libsodium_la_LDFLAGS) libsse2_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \ @CFLAGS_SSE2@ libsse2_la_SOURCES = \ - crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c + crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c \ + crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c \ + crypto_onetimeauth/poly1305/sse2/poly1305_sse2.h libssse3_la_LDFLAGS = $(libsodium_la_LDFLAGS) libssse3_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \ diff --git a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c index f5f1de5b..11673e76 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c @@ -1,7 +1,11 @@ #include "crypto_onetimeauth_poly1305.h" -#include "donna/poly1305_donna.h" #include "onetimeauth_poly1305.h" +#include "runtime.h" +#include "donna/poly1305_donna.h" +#if defined(HAVE_TI_MODE) && defined(HAVE_AMD64_ASM) && defined(HAVE_EMMINTRIN_H) +# include "sse2/poly1305_sse2.h" +#endif static const crypto_onetimeauth_poly1305_implementation *implementation = &crypto_onetimeauth_poly1305_donna_implementation; @@ -58,5 +62,10 @@ int _crypto_onetimeauth_poly1305_pick_best_implementation(void) { implementation = &crypto_onetimeauth_poly1305_donna_implementation; +#if defined(HAVE_TI_MODE) && defined(HAVE_AMD64_ASM) && defined(HAVE_EMMINTRIN_H) + if (sodium_runtime_has_sse2()) { + implementation = &crypto_onetimeauth_poly1305_sse2_implementation; + } +#endif return 0; } diff --git a/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c b/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c index ce08da71..a9d68775 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c @@ -2,6 +2,7 @@ #include #include +#include "crypto_verify_16.h" #include "utils.h" #include "poly1305_sse2.h" #include "../onetimeauth_poly1305.h" @@ -603,4 +604,26 @@ crypto_onetimeauth_poly1305_sse2(unsigned char *out, const unsigned char *m, return 0; } +static int +crypto_onetimeauth_poly1305_sse2_verify(const unsigned char *h, + const unsigned char *in, + unsigned long long inlen, + const unsigned char *k) +{ + unsigned char correct[16]; + + crypto_onetimeauth_poly1305_sse2(correct,in,inlen,k); + + return crypto_verify_16(h,correct); +} + +struct crypto_onetimeauth_poly1305_implementation +crypto_onetimeauth_poly1305_sse2_implementation = { + SODIUM_C99(.onetimeauth =) crypto_onetimeauth_poly1305_sse2, + SODIUM_C99(.onetimeauth_verify =) crypto_onetimeauth_poly1305_sse2_verify, + SODIUM_C99(.onetimeauth_init =) crypto_onetimeauth_poly1305_sse2_init, + SODIUM_C99(.onetimeauth_update =) crypto_onetimeauth_poly1305_sse2_update, + SODIUM_C99(.onetimeauth_final =) crypto_onetimeauth_poly1305_sse2_final +}; + #endif