From 9f1fd2a71dd37b124e027656b201782fe6078ab6 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 18 Apr 2013 13:44:35 +0200 Subject: [PATCH] Turn implementation definitions to globals. --- .../poly1305/onetimeauth_poly1305.c | 15 +++++------- .../poly1305/ref/auth_poly1305.c | 13 ++++------ .../sodium/crypto_onetimeauth_poly1305_ref.h | 4 ++-- .../sodium/randombytes_salsa20_random.h | 3 +-- .../include/sodium/randombytes_sysrandom.h | 3 +-- src/libsodium/randombytes/randombytes.c | 24 +++++++------------ .../salsa20/randombytes_salsa20_random.c | 20 +++++++--------- .../sysrandom/randombytes_sysrandom.c | 20 +++++++--------- 8 files changed, 40 insertions(+), 62 deletions(-) diff --git a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c index 8bc0523b..5ac91916 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c @@ -8,16 +8,13 @@ #include "crypto_onetimeauth_poly1305.h" #include "crypto_onetimeauth_poly1305_ref.h" -static crypto_onetimeauth_poly1305_implementation implementation = { - .implementation_name = crypto_onetimeauth_poly1305_ref_implementation_name, - .onetimeauth = crypto_onetimeauth_poly1305_ref, - .onetimeauth_verify = crypto_onetimeauth_poly1305_ref_verify -}; +static const crypto_onetimeauth_poly1305_implementation *implementation = + &crypto_onetimeauth_poly1305_ref_implementation; int crypto_onetimeauth_poly1305_set_implementation(crypto_onetimeauth_poly1305_implementation *impl) { - implementation = *impl; + implementation = impl; return 0; } @@ -25,19 +22,19 @@ crypto_onetimeauth_poly1305_set_implementation(crypto_onetimeauth_poly1305_imple const char * crypto_onetimeauth_poly1305_implementation_name(void) { - return implementation.implementation_name(); + return implementation->implementation_name(); } int crypto_onetimeauth_poly1305(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) { - return implementation.onetimeauth(out, in, inlen, k); + return implementation->onetimeauth(out, in, inlen, k); } int crypto_onetimeauth_poly1305_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) { - return implementation.onetimeauth_verify(h, in, inlen, k); + return implementation->onetimeauth_verify(h, in, inlen, k); } diff --git a/src/libsodium/crypto_onetimeauth/poly1305/ref/auth_poly1305.c b/src/libsodium/crypto_onetimeauth/poly1305/ref/auth_poly1305.c index fa5fc4c7..3a21baab 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/ref/auth_poly1305.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/ref/auth_poly1305.c @@ -111,11 +111,8 @@ crypto_onetimeauth_poly1305_implementation_name(void) } struct crypto_onetimeauth_poly1305_implementation -crypto_onetimeauth_poly1305_ref_implementation(void) -{ - return (crypto_onetimeauth_poly1305_implementation) { - .implementation_name = crypto_onetimeauth_poly1305_implementation_name, - .onetimeauth = crypto_onetimeauth, - .onetimeauth_verify = crypto_onetimeauth_verify - }; -} +crypto_onetimeauth_poly1305_ref_implementation = { + .implementation_name = crypto_onetimeauth_poly1305_implementation_name, + .onetimeauth = crypto_onetimeauth, + .onetimeauth_verify = crypto_onetimeauth_verify +}; diff --git a/src/libsodium/include/sodium/crypto_onetimeauth_poly1305_ref.h b/src/libsodium/include/sodium/crypto_onetimeauth_poly1305_ref.h index cc0dc84a..e8936376 100644 --- a/src/libsodium/include/sodium/crypto_onetimeauth_poly1305_ref.h +++ b/src/libsodium/include/sodium/crypto_onetimeauth_poly1305_ref.h @@ -7,8 +7,8 @@ extern "C" { #endif -struct crypto_onetimeauth_poly1305_implementation - crypto_onetimeauth_poly1305_ref_implementation(void); +extern struct crypto_onetimeauth_poly1305_implementation + crypto_onetimeauth_poly1305_ref_implementation; const char *crypto_onetimeauth_poly1305_ref_implementation_name(void); diff --git a/src/libsodium/include/sodium/randombytes_salsa20_random.h b/src/libsodium/include/sodium/randombytes_salsa20_random.h index 09c6ca0c..9e2dadce 100644 --- a/src/libsodium/include/sodium/randombytes_salsa20_random.h +++ b/src/libsodium/include/sodium/randombytes_salsa20_random.h @@ -9,8 +9,7 @@ extern "C" { #endif -struct randombytes_implementation - randombytes_salsa20_implementation(void); +extern struct randombytes_implementation randombytes_salsa20_implementation; const char *randombytes_salsa20_implementation_name(void); diff --git a/src/libsodium/include/sodium/randombytes_sysrandom.h b/src/libsodium/include/sodium/randombytes_sysrandom.h index 99100f0b..b0e23703 100644 --- a/src/libsodium/include/sodium/randombytes_sysrandom.h +++ b/src/libsodium/include/sodium/randombytes_sysrandom.h @@ -9,8 +9,7 @@ extern "C" { #endif -struct randombytes_implementation - randombytes_sysrandom_implementation(void); +extern struct randombytes_implementation randombytes_sysrandom_implementation; const char *randombytes_sysrandom_implementation_name(void); diff --git a/src/libsodium/randombytes/randombytes.c b/src/libsodium/randombytes/randombytes.c index f12ca0f7..46322fdc 100644 --- a/src/libsodium/randombytes/randombytes.c +++ b/src/libsodium/randombytes/randombytes.c @@ -8,19 +8,13 @@ #include "randombytes.h" #include "randombytes_sysrandom.h" -static randombytes_implementation implementation = { - .implementation_name = randombytes_sysrandom_implementation_name, - .random = randombytes_sysrandom, - .stir = randombytes_sysrandom_stir, - .uniform = randombytes_sysrandom_uniform, - .buf = randombytes_sysrandom_buf, - .close = randombytes_sysrandom_close -}; +static const randombytes_implementation *implementation = + &randombytes_sysrandom_implementation; int randombytes_set_implementation(randombytes_implementation *impl) { - implementation = *impl; + implementation = impl; return 0; } @@ -28,37 +22,37 @@ randombytes_set_implementation(randombytes_implementation *impl) const char * randombytes_implementation_name(void) { - return implementation.implementation_name(); + return implementation->implementation_name(); } uint32_t randombytes_random(void) { - return implementation.random(); + return implementation->random(); } void randombytes_stir(void) { - return implementation.stir(); + return implementation->stir(); } uint32_t randombytes_uniform(const uint32_t upper_bound) { - return implementation.uniform(upper_bound); + return implementation->uniform(upper_bound); } void randombytes_buf(void * const buf, const size_t size) { - return implementation.buf(buf, size); + return implementation->buf(buf, size); } int randombytes_close(void) { - return implementation.close(); + return implementation->close(); } void diff --git a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c index 609bf1ef..ff467a2f 100644 --- a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +++ b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c @@ -299,15 +299,11 @@ randombytes_salsa20_implementation_name(void) return "salsa20"; } -struct randombytes_implementation -randombytes_salsa20_implementation(void) -{ - return (randombytes_implementation) { - .implementation_name = randombytes_salsa20_implementation_name, - .random = randombytes_salsa20_random, - .stir = randombytes_salsa20_random_stir, - .uniform = randombytes_salsa20_random_uniform, - .buf = randombytes_salsa20_random_buf, - .close = randombytes_salsa20_random_close - }; -} +struct randombytes_implementation randombytes_salsa20_implementation = { + .implementation_name = randombytes_salsa20_implementation_name, + .random = randombytes_salsa20_random, + .stir = randombytes_salsa20_random_stir, + .uniform = randombytes_salsa20_random_uniform, + .buf = randombytes_salsa20_random_buf, + .close = randombytes_salsa20_random_close +}; diff --git a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c index 55925262..728c9294 100644 --- a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +++ b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c @@ -201,15 +201,11 @@ randombytes_sysrandom_implementation_name(void) return "sysrandom"; } -struct randombytes_implementation -randombytes_sysrandom_implementation(void) -{ - return (randombytes_implementation) { - .implementation_name = randombytes_sysrandom_implementation_name, - .random = randombytes_sysrandom, - .stir = randombytes_sysrandom_stir, - .uniform = randombytes_sysrandom_uniform, - .buf = randombytes_sysrandom_buf, - .close = randombytes_sysrandom_close - }; -} +struct randombytes_implementation randombytes_sysrandom_implementation = { + .implementation_name = randombytes_sysrandom_implementation_name, + .random = randombytes_sysrandom, + .stir = randombytes_sysrandom_stir, + .uniform = randombytes_sysrandom_uniform, + .buf = randombytes_sysrandom_buf, + .close = randombytes_sysrandom_close +};