Pick the best working poly1305 implementation at runtime.

This commit is contained in:
Frank Denis
2013-04-21 17:32:05 -07:00
parent aa6488dbe9
commit 3b57f77262
5 changed files with 21 additions and 7 deletions
+1
View File
@@ -53,6 +53,7 @@ libsodium_la_SOURCES = \
crypto_stream/xsalsa20/ref/stream_xsalsa20.c \
crypto_stream/xsalsa20/ref/xor_xsalsa20.c \
crypto_onetimeauth/poly1305/onetimeauth_poly1305.c \
crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c \
crypto_onetimeauth/poly1305/53/auth_poly1305_53.c \
crypto_onetimeauth/poly1305/53/crypto_onetimeauth.h \
crypto_onetimeauth/poly1305/53/verify_poly1305_53.c \
@@ -25,9 +25,12 @@ typedef struct crypto_onetimeauth_poly1305_implementation {
} crypto_onetimeauth_poly1305_implementation;
const char *crypto_onetimeauth_poly1305_ref_implementation_name(void);
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(unsigned char *out,
const unsigned char *in,
unsigned long long inlen,
+3 -2
View File
@@ -8,9 +8,10 @@
extern "C" {
#endif
void sodium_memzero(void * const pnt, const size_t size);
void sodium_memzero(void * const pnt, const size_t len);
void *_sodium_alignedcalloc(void ** const unaligned_p, const size_t len);
void *_sodium_alignedcalloc(unsigned char ** const unaligned_p,
const size_t len);
#ifdef __cplusplus
}
+9
View File
@@ -1,9 +1,18 @@
#include "core.h"
#include "crypto_onetimeauth.h"
static char initialized;
int
sodium_init(void)
{
if (__sync_lock_test_and_set(&initialized, 1) != 0) {
return 1;
}
if (crypto_onetimeauth_pick_best_implementation() == NULL) {
return -1;
}
return 0;
}
+4 -4
View File
@@ -13,22 +13,22 @@
#endif
void
sodium_memzero(void * const pnt, const size_t size)
sodium_memzero(void * const pnt, const size_t len)
{
#ifdef HAVE_SECUREZEROMEMORY
SecureZeroMemory(pnt, size);
SecureZeroMemory(pnt, len);
#else
volatile unsigned char *pnt_ = (volatile unsigned char *) pnt;
size_t i = (size_t) 0U;
while (i < size) {
while (i < len) {
pnt_[i++] = 0U;
}
#endif
}
void *
_sodium_alignedcalloc(void ** const unaligned_p, const size_t len)
_sodium_alignedcalloc(unsigned char ** const unaligned_p, const size_t len)
{
unsigned char *aligned;
unsigned char *unaligned;