From b3a1d6b96749d697e93efc4e4d649e829c006788 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 21 Apr 2013 15:00:18 +0200 Subject: [PATCH] Add function wrappers around macros, for crypto_auth and crypto_box --- src/libsodium/crypto_auth/crypto_auth.c | 18 ++++++++ src/libsodium/crypto_box/crypto_box.c | 48 ++++++++++++++++++++++ src/libsodium/include/sodium/crypto_auth.h | 16 ++++++-- src/libsodium/include/sodium/crypto_box.h | 25 +++++++++++ 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/libsodium/crypto_auth/crypto_auth.c b/src/libsodium/crypto_auth/crypto_auth.c index cd07db54..e76b1494 100644 --- a/src/libsodium/crypto_auth/crypto_auth.c +++ b/src/libsodium/crypto_auth/crypto_auth.c @@ -1,6 +1,24 @@ #include "crypto_auth.h" +size_t +crypto_auth_bytes(void) +{ + return crypto_auth_BYTES; +} + +size_t +crypto_auth_keybytes(void) +{ + return crypto_auth_KEYBYTES; +} + +const char * +crypto_auth_primitive(void) +{ + return crypto_auth_PRIMITIVE; +} + int crypto_auth(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) diff --git a/src/libsodium/crypto_box/crypto_box.c b/src/libsodium/crypto_box/crypto_box.c index 651bd4e2..4edb893c 100644 --- a/src/libsodium/crypto_box/crypto_box.c +++ b/src/libsodium/crypto_box/crypto_box.c @@ -1,6 +1,54 @@ #include "crypto_box.h" +size_t +crypto_box_publickeybytes(void) +{ + return crypto_box_PUBLICKEYBYTES; +} + +size_t +crypto_box_secretkeybytes(void) +{ + return crypto_box_SECRETKEYBYTES; +} + +size_t +crypto_box_beforenmbytes(void) +{ + return crypto_box_BEFORENMBYTES; +} + +size_t +crypto_box_noncebytes(void) +{ + return crypto_box_NONCEBYTES; +} + +size_t +crypto_box_zerobytes(void) +{ + return crypto_box_ZEROBYTES; +} + +size_t +crypto_box_boxzerobytes(void) +{ + return crypto_box_BOXZEROBYTES; +} + +size_t +crypto_box_macbytes(void) +{ + return crypto_box_MACBYTES; +} + +const char * +crypto_box_primitive(void) +{ + return crypto_box_PRIMITIVE; +} + int crypto_box_keypair(unsigned char *pk, unsigned char *sk) { diff --git a/src/libsodium/include/sodium/crypto_auth.h b/src/libsodium/include/sodium/crypto_auth.h index 1d6e7963..df6abd1a 100644 --- a/src/libsodium/include/sodium/crypto_auth.h +++ b/src/libsodium/include/sodium/crypto_auth.h @@ -1,15 +1,23 @@ #ifndef crypto_auth_H #define crypto_auth_H -#include "crypto_auth_hmacsha512256.h" +#include -#define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES -#define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES -#define crypto_auth_PRIMITIVE "hmacsha512256" +#include "crypto_auth_hmacsha512256.h" #ifdef __cplusplus extern "C" { #endif + +#define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES +size_t crypto_auth_bytes(void); + +#define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES +size_t crypto_auth_keybytes(void); + +#define crypto_auth_PRIMITIVE "hmacsha512256" +const char *crypto_auth_primitive(void); + int crypto_auth(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k); diff --git a/src/libsodium/include/sodium/crypto_box.h b/src/libsodium/include/sodium/crypto_box.h index e132f5bf..f17cd472 100644 --- a/src/libsodium/include/sodium/crypto_box.h +++ b/src/libsodium/include/sodium/crypto_box.h @@ -1,16 +1,37 @@ #ifndef crypto_box_H #define crypto_box_H +#include + #include "crypto_box_curve25519xsalsa20poly1305.h" +#ifdef __cplusplus +extern "C" { +#endif + #define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES +size_t crypto_box_publickeybytes(void); + #define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES +size_t crypto_box_secretkeybytes(void); + #define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES +size_t crypto_box_beforenmbytes(void); + #define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES +size_t crypto_box_noncebytes(void); + #define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES +size_t crypto_box_zerobytes(void); + #define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES +size_t crypto_box_boxzerobytes(void); + #define crypto_box_MACBYTES crypto_box_curve25519xsalsa20poly1305_MACBYTES +size_t crypto_box_macbytes(void); + #define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305" +const char *crypto_box_primitive(void); int crypto_box_keypair(unsigned char *pk, unsigned char *sk); @@ -33,4 +54,8 @@ int crypto_box_open(unsigned char *m, const unsigned char *c, unsigned long long clen, const unsigned char *n, const unsigned char *pk, const unsigned char *sk); +#ifdef __cplusplus +} +#endif + #endif