mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-19 18:15:18 -07:00
Make the crypto_onetimeauth_poly1305() implementation switchable at runtime
This commit is contained in:
parent
96db80f17f
commit
f3e0d9a140
@ -52,6 +52,7 @@ libsodium_la_SOURCES = \
|
||||
crypto_stream/xsalsa20/ref/crypto_stream.h \
|
||||
crypto_stream/xsalsa20/ref/stream_xsalsa20.c \
|
||||
crypto_stream/xsalsa20/ref/xor_xsalsa20.c \
|
||||
crypto_onetimeauth/poly1305/onetimeauth_poly1305.c \
|
||||
crypto_onetimeauth/poly1305/ref/auth_poly1305.c \
|
||||
crypto_onetimeauth/poly1305/ref/crypto_onetimeauth.h \
|
||||
crypto_onetimeauth/poly1305/ref/verify_poly1305.c \
|
||||
|
@ -3,12 +3,7 @@
|
||||
|
||||
#include "crypto_onetimeauth_poly1305.h"
|
||||
|
||||
#define crypto_onetimeauth crypto_onetimeauth_poly1305
|
||||
#define crypto_onetimeauth_verify crypto_onetimeauth_poly1305_verify
|
||||
#define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES
|
||||
#define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES
|
||||
#define crypto_onetimeauth_PRIMITIVE "poly1305"
|
||||
#define crypto_onetimeauth_IMPLEMENTATION crypto_onetimeauth_poly1305_IMPLEMENTATION
|
||||
#define crypto_onetimeauth_VERSION crypto_onetimeauth_poly1305_VERSION
|
||||
#define crypto_onetimeauth crypto_onetimeauth_poly1305_53
|
||||
#define crypto_onetimeauth_verify crypto_onetimeauth_poly1305_53_verify
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,43 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
#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
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
@ -102,3 +102,9 @@ int crypto_onetimeauth(unsigned char *out,const unsigned char *in,unsigned long
|
||||
for (j = 0;j < 16;++j) out[j] = h[j];
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
crypto_onetimeauth_poly1305_ref_implementation_name(void)
|
||||
{
|
||||
return "ref";
|
||||
}
|
||||
|
@ -3,12 +3,7 @@
|
||||
|
||||
#include "crypto_onetimeauth_poly1305.h"
|
||||
|
||||
#define crypto_onetimeauth crypto_onetimeauth_poly1305
|
||||
#define crypto_onetimeauth_verify crypto_onetimeauth_poly1305_verify
|
||||
#define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES
|
||||
#define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES
|
||||
#define crypto_onetimeauth_PRIMITIVE "poly1305"
|
||||
#define crypto_onetimeauth_IMPLEMENTATION crypto_onetimeauth_poly1305_IMPLEMENTATION
|
||||
#define crypto_onetimeauth_VERSION crypto_onetimeauth_poly1305_VERSION
|
||||
#define crypto_onetimeauth crypto_onetimeauth_poly1305_ref
|
||||
#define crypto_onetimeauth_verify crypto_onetimeauth_poly1305_ref_verify
|
||||
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@ SODIUM_EXPORT = \
|
||||
sodium/crypto_hashblocks_sha512.h \
|
||||
sodium/crypto_onetimeauth.h \
|
||||
sodium/crypto_onetimeauth_poly1305.h \
|
||||
sodium/crypto_onetimeauth_poly1305_ref.h \
|
||||
sodium/crypto_scalarmult_curve25519.h \
|
||||
sodium/crypto_secretbox.h \
|
||||
sodium/crypto_secretbox_xsalsa20poly1305.h \
|
||||
|
@ -6,16 +6,40 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern int crypto_onetimeauth_poly1305_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
|
||||
extern int crypto_onetimeauth_poly1305_ref_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
|
||||
|
||||
extern int crypto_onetimeauth_poly1305_53(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
|
||||
extern int crypto_onetimeauth_poly1305_53_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
} crypto_onetimeauth_poly1305_implementation;
|
||||
|
||||
const char *crypto_onetimeauth_poly1305_ref_implementation_name(void);
|
||||
|
||||
int crypto_onetimeauth_poly1305_set_implementation(crypto_onetimeauth_poly1305_implementation *impl);
|
||||
|
||||
int crypto_onetimeauth_poly1305(unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k);
|
||||
|
||||
int crypto_onetimeauth_poly1305_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define crypto_onetimeauth_poly1305 crypto_onetimeauth_poly1305_ref
|
||||
#define crypto_onetimeauth_poly1305_verify crypto_onetimeauth_poly1305_ref_verify
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,24 @@
|
||||
#ifndef crypto_onetimeauth_poly1305_ref_H
|
||||
#define crypto_onetimeauth_poly1305_ref_H
|
||||
|
||||
#include "crypto_onetimeauth_poly1305.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int crypto_onetimeauth_poly1305_ref(unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k);
|
||||
|
||||
int crypto_onetimeauth_poly1305_ref_verify(const unsigned char *h,
|
||||
const unsigned char *in,
|
||||
unsigned long long inlen,
|
||||
const unsigned char *k);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user