diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index 13aee214..e5bb8138 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -51,8 +51,7 @@ libsodium_la_SOURCES = \ crypto_hash/sha512/cp/hash_sha512.c \ crypto_onetimeauth/crypto_onetimeauth.c \ crypto_onetimeauth/poly1305/onetimeauth_poly1305.c \ - crypto_onetimeauth/poly1305/onetimeauth_poly1305_api.c \ - crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c \ + crypto_onetimeauth/poly1305/onetimeauth_poly1305.h \ crypto_onetimeauth/poly1305/donna/poly1305_donna.h \ crypto_onetimeauth/poly1305/donna/poly1305_donna32.h \ crypto_onetimeauth/poly1305/donna/poly1305_donna64.h \ diff --git a/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c b/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c index 42e21e33..cb23c90b 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c @@ -6,6 +6,7 @@ #else # include "poly1305_donna32.h" #endif +#include "../onetimeauth_poly1305.h" static void poly1305_update(poly1305_context *ctx, const unsigned char *m, @@ -45,7 +46,7 @@ poly1305_update(poly1305_context *ctx, const unsigned char *m, } } -int +static int crypto_onetimeauth_poly1305_donna(unsigned char *out, const unsigned char *m, unsigned long long inlen, const unsigned char *key) @@ -58,7 +59,7 @@ crypto_onetimeauth_poly1305_donna(unsigned char *out, const unsigned char *m, return 0; } -int +static int crypto_onetimeauth_poly1305_donna_init(crypto_onetimeauth_poly1305_state *state, const unsigned char *key) { @@ -67,7 +68,7 @@ crypto_onetimeauth_poly1305_donna_init(crypto_onetimeauth_poly1305_state *state, return 0; } -int +static int crypto_onetimeauth_poly1305_donna_update(crypto_onetimeauth_poly1305_state *state, const unsigned char *in, unsigned long long inlen) @@ -77,7 +78,7 @@ crypto_onetimeauth_poly1305_donna_update(crypto_onetimeauth_poly1305_state *stat return 0; } -int +static int crypto_onetimeauth_poly1305_donna_final(crypto_onetimeauth_poly1305_state *state, unsigned char *out) { @@ -86,17 +87,8 @@ crypto_onetimeauth_poly1305_donna_final(crypto_onetimeauth_poly1305_state *state return 0; } -/* LCOV_EXCL_START */ -const char * -crypto_onetimeauth_poly1305_donna_implementation_name(void) -{ - return POLY1305_IMPLEMENTATION_NAME; -} -/* LCOV_EXCL_STOP */ - struct crypto_onetimeauth_poly1305_implementation crypto_onetimeauth_poly1305_donna_implementation = { - SODIUM_C99(.implementation_name =) crypto_onetimeauth_poly1305_donna_implementation_name, SODIUM_C99(.onetimeauth =) crypto_onetimeauth_poly1305_donna, SODIUM_C99(.onetimeauth_verify =) crypto_onetimeauth_poly1305_donna_verify, SODIUM_C99(.onetimeauth_init =) crypto_onetimeauth_poly1305_donna_init, diff --git a/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h b/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h index 3c58158e..20f945c7 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h +++ b/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h @@ -10,26 +10,26 @@ typedef crypto_onetimeauth_poly1305_state poly1305_context; extern struct crypto_onetimeauth_poly1305_implementation crypto_onetimeauth_poly1305_donna_implementation; -const char *crypto_onetimeauth_poly1305_donna_implementation_name(void); +static const char *crypto_onetimeauth_poly1305_donna_implementation_name(void); -int crypto_onetimeauth_poly1305_donna(unsigned char *out, - const unsigned char *in, - unsigned long long inlen, - const unsigned char *k); - -int crypto_onetimeauth_poly1305_donna_verify(const unsigned char *h, +static int crypto_onetimeauth_poly1305_donna(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k); -int crypto_onetimeauth_poly1305_donna_init(crypto_onetimeauth_poly1305_state *state, - const unsigned char *key); +static int crypto_onetimeauth_poly1305_donna_verify(const unsigned char *h, + const unsigned char *in, + unsigned long long inlen, + const unsigned char *k); -int crypto_onetimeauth_poly1305_donna_update(crypto_onetimeauth_poly1305_state *state, - const unsigned char *in, - unsigned long long inlen); +static int crypto_onetimeauth_poly1305_donna_init(crypto_onetimeauth_poly1305_state *state, + const unsigned char *key); -int crypto_onetimeauth_poly1305_donna_final(crypto_onetimeauth_poly1305_state *state, - unsigned char *out); +static int crypto_onetimeauth_poly1305_donna_update(crypto_onetimeauth_poly1305_state *state, + const unsigned char *in, + unsigned long long inlen); + +static int crypto_onetimeauth_poly1305_donna_final(crypto_onetimeauth_poly1305_state *state, + unsigned char *out); #endif /* __POLY1305_DONNA_H__ */ diff --git a/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h b/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h index a4696632..a8756753 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +++ b/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h @@ -2,8 +2,6 @@ poly1305 implementation using 32 bit * 32 bit = 64 bit multiplication and 64 bit addition */ -#define POLY1305_IMPLEMENTATION_NAME "donna32" - #if defined(_MSC_VER) # define POLY1305_NOINLINE __declspec(noinline) #elif defined(__GNUC__) diff --git a/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h b/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h index 8b5c764b..dda02670 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +++ b/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h @@ -2,8 +2,6 @@ poly1305 implementation using 64 bit * 64 bit = 128 bit multiplication and 128 bit addition */ -#define POLY1305_IMPLEMENTATION_NAME "donna64" - #if defined(__SIZEOF_INT128__) typedef unsigned __int128 uint128_t; #else diff --git a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c index 14253b7b..f5f1de5b 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c @@ -1,26 +1,11 @@ #include "crypto_onetimeauth_poly1305.h" #include "donna/poly1305_donna.h" +#include "onetimeauth_poly1305.h" -/* LCOV_EXCL_START */ static const crypto_onetimeauth_poly1305_implementation *implementation = &crypto_onetimeauth_poly1305_donna_implementation; -int -crypto_onetimeauth_poly1305_set_implementation(crypto_onetimeauth_poly1305_implementation *impl) -{ - implementation = impl; - - return 0; -} - -const char * -crypto_onetimeauth_poly1305_implementation_name(void) -{ - return implementation->implementation_name(); -} -/* LCOV_EXCL_STOP */ - int crypto_onetimeauth_poly1305(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) @@ -58,3 +43,20 @@ crypto_onetimeauth_poly1305_final(crypto_onetimeauth_poly1305_state *state, { return implementation->onetimeauth_final(state, out); } + +size_t +crypto_onetimeauth_poly1305_bytes(void) { + return crypto_onetimeauth_poly1305_BYTES; +} + +size_t +crypto_onetimeauth_poly1305_keybytes(void) { + return crypto_onetimeauth_poly1305_KEYBYTES; +} + +int +_crypto_onetimeauth_poly1305_pick_best_implementation(void) +{ + implementation = &crypto_onetimeauth_poly1305_donna_implementation; + return 0; +} diff --git a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_api.c b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_api.c deleted file mode 100644 index b8878d5d..00000000 --- a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_api.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "crypto_onetimeauth_poly1305.h" - -size_t -crypto_onetimeauth_poly1305_bytes(void) { - return crypto_onetimeauth_poly1305_BYTES; -} - -size_t -crypto_onetimeauth_poly1305_keybytes(void) { - return crypto_onetimeauth_poly1305_KEYBYTES; -} diff --git a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c deleted file mode 100644 index 10084e5b..00000000 --- a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c +++ /dev/null @@ -1,13 +0,0 @@ - -#include -#include -#include "crypto_onetimeauth.h" -#include "crypto_onetimeauth_poly1305.h" -#include "utils.h" -#include "donna/poly1305_donna.h" - -crypto_onetimeauth_poly1305_implementation * -crypto_onetimeauth_pick_best_implementation(void) -{ - return &crypto_onetimeauth_poly1305_donna_implementation; -} diff --git a/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h b/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h index dacd79ef..835e631b 100644 --- a/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +++ b/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h @@ -54,32 +54,9 @@ SODIUM_EXPORT int crypto_onetimeauth_poly1305_final(crypto_onetimeauth_poly1305_state *state, unsigned char *out); -const char *crypto_onetimeauth_poly1305_implementation_name(void); - /* ------------------------------------------------------------------------- */ -typedef struct crypto_onetimeauth_poly1305_implementation { - const char *(*implementation_name)(void); - int (*onetimeauth)(unsigned char *out, - const unsigned char *in, - unsigned long long inlen, - const unsigned char *k); - int (*onetimeauth_verify)(const unsigned char *h, - const unsigned char *in, - unsigned long long inlen, - const unsigned char *k); - int (*onetimeauth_init)(crypto_onetimeauth_poly1305_state *state, - const unsigned char *key); - int (*onetimeauth_update)(crypto_onetimeauth_poly1305_state *state, - const unsigned char *in, - unsigned long long inlen); - int (*onetimeauth_final)(crypto_onetimeauth_poly1305_state *state, - unsigned char *out); -} crypto_onetimeauth_poly1305_implementation; - -int crypto_onetimeauth_poly1305_set_implementation(crypto_onetimeauth_poly1305_implementation *impl); - -crypto_onetimeauth_poly1305_implementation *crypto_onetimeauth_pick_best_implementation(void); +int _crypto_onetimeauth_poly1305_pick_best_implementation(void); #ifdef __cplusplus } diff --git a/src/libsodium/sodium/core.c b/src/libsodium/sodium/core.c index 45960cec..81bf1d7a 100644 --- a/src/libsodium/sodium/core.c +++ b/src/libsodium/sodium/core.c @@ -1,5 +1,6 @@ #include "core.h" +#include "crypto_generichash.h" #include "crypto_onetimeauth.h" #include "randombytes.h" #include "runtime.h" @@ -17,9 +18,7 @@ sodium_init(void) randombytes_stir(); _sodium_alloc_init(); _crypto_generichash_blake2b_pick_best_implementation(); - if (crypto_onetimeauth_pick_best_implementation() == NULL) { - return -1; /* LCOV_EXCL_LINE */ - } + _crypto_onetimeauth_poly1305_pick_best_implementation(); initialized = 1; return 0;