Turn implementation definitions to globals.
This commit is contained in:
parent
7aa057dcd8
commit
9f1fd2a71d
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user