From b6fbb0ca6ae311fe4dde9a0445adc16a806570f1 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 19 Jun 2014 20:04:48 -0700 Subject: [PATCH] + poly1305 streaming interface --- .../poly1305/donna/auth_poly1305_donna.c | 34 ++++++++++++++++++- .../sodium/crypto_onetimeauth_poly1305.h | 30 +++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) 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 d1d29e18..acd04c00 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c @@ -58,6 +58,35 @@ crypto_onetimeauth_poly1305_donna(unsigned char *out, const unsigned char *m, return 0; } +int +crypto_onetimeauth_poly1305_donna_init(crypto_onetimeauth_poly1305_state *state, + const unsigned char *key) +{ + poly1305_init((poly1305_context *) state, key); + + return 0; +} + +int +crypto_onetimeauth_poly1305_donna_update(crypto_onetimeauth_poly1305_state *state, + const unsigned char *in, + unsigned long long inlen) +{ + poly1305_update((poly1305_context *) state, in, inlen); + + return 0; +} + +int +crypto_onetimeauth_poly1305_donna_final(crypto_onetimeauth_poly1305_state *state, + unsigned char *out) +{ + poly1305_finish((poly1305_context *) state, out); + + return 0; +} + + const char * crypto_onetimeauth_poly1305_donna_implementation_name(void) { @@ -68,5 +97,8 @@ 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_verify =) crypto_onetimeauth_poly1305_donna_verify, + _SODIUM_C99(.onetimeauth_init =) crypto_onetimeauth_poly1305_donna_init, + _SODIUM_C99(.onetimeauth_update =) crypto_onetimeauth_poly1305_donna_update, + _SODIUM_C99(.onetimeauth_final =) crypto_onetimeauth_poly1305_donna_final }; diff --git a/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h b/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h index 8fa66963..54f4a735 100644 --- a/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +++ b/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h @@ -16,6 +16,11 @@ extern "C" { #include #include +typedef struct crypto_onetimeauth_poly1305_state { + unsigned long long aligner; + unsigned char opaque[136]; +} crypto_onetimeauth_poly1305_state; + typedef struct crypto_onetimeauth_poly1305_implementation { const char *(*implementation_name)(void); int (*onetimeauth)(unsigned char *out, @@ -26,13 +31,15 @@ typedef struct crypto_onetimeauth_poly1305_implementation { 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; -typedef struct crypto_onetimeauth_poly1305_state { - unsigned long long aligner; - unsigned char opaque[136]; -} crypto_onetimeauth_poly1305_state; - #define crypto_onetimeauth_poly1305_BYTES 16U SODIUM_EXPORT size_t crypto_onetimeauth_poly1305_bytes(void); @@ -63,6 +70,19 @@ int crypto_onetimeauth_poly1305_verify(const unsigned char *h, unsigned long long inlen, const unsigned char *k); +SODIUM_EXPORT +int crypto_onetimeauth_poly1305_init(crypto_onetimeauth_poly1305_state *state, + const unsigned char *key); + +SODIUM_EXPORT +int crypto_onetimeauth_poly1305_update(crypto_onetimeauth_poly1305_state *state, + const unsigned char *in, + unsigned long long inlen); + +SODIUM_EXPORT +int crypto_onetimeauth_poly1305_final(crypto_onetimeauth_poly1305_state *state, + unsigned char *out); + #ifdef __cplusplus } #endif