From b5ed4cc34b4f5ab466de53428e25ee3a5eb9220c Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 29 Dec 2015 21:48:08 +0100 Subject: [PATCH] Add high-level crypto_pwhash() API --- src/libsodium/Makefile.am | 1 + src/libsodium/crypto_pwhash/crypto_pwhash.c | 83 +++++++++++++++++++ src/libsodium/include/sodium.h | 1 + src/libsodium/include/sodium/crypto_pwhash.h | 76 +++++++++++++++++ .../include/sodium/crypto_pwhash_argon2i.h | 1 - 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 src/libsodium/crypto_pwhash/crypto_pwhash.c create mode 100644 src/libsodium/include/sodium/crypto_pwhash.h diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index 7ad9f780..a37c2a96 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -51,6 +51,7 @@ libsodium_la_SOURCES = \ crypto_onetimeauth/poly1305/donna/poly1305_donna32.h \ crypto_onetimeauth/poly1305/donna/poly1305_donna64.h \ crypto_onetimeauth/poly1305/donna/poly1305_donna.c \ + crypto_pwhash/crypto_pwhash.c \ crypto_pwhash/argon2/argon2-core.c \ crypto_pwhash/argon2/argon2-core.h \ crypto_pwhash/argon2/argon2-encoding.c \ diff --git a/src/libsodium/crypto_pwhash/crypto_pwhash.c b/src/libsodium/crypto_pwhash/crypto_pwhash.c new file mode 100644 index 00000000..761fa9e5 --- /dev/null +++ b/src/libsodium/crypto_pwhash/crypto_pwhash.c @@ -0,0 +1,83 @@ + +#include "crypto_pwhash.h" + +size_t +crypto_pwhash_saltbytes(void) +{ + return crypto_pwhash_SALTBYTES; +} + +size_t +crypto_pwhash_strbytes(void) +{ + return crypto_pwhash_STRBYTES; +} + +const char * +crypto_pwhash_strprefix(void) +{ + return crypto_pwhash_STRPREFIX; +} + +size_t +crypto_pwhash_opslimit_interactive(void) +{ + return crypto_pwhash_OPSLIMIT_INTERACTIVE; +} + +size_t +crypto_pwhash_memlimit_interactive(void) +{ + return crypto_pwhash_MEMLIMIT_INTERACTIVE; +} + +size_t +crypto_pwhash_opslimit_moderate(void) +{ + return crypto_pwhash_OPSLIMIT_MODERATE; +} + +size_t +crypto_pwhash_memlimit_moderate(void) +{ + return crypto_pwhash_MEMLIMIT_MODERATE; +} + +size_t +crypto_pwhash_opslimit_sensitive(void) +{ + return crypto_pwhash_OPSLIMIT_SENSITIVE; +} + +size_t +crypto_pwhash_memlimit_sensitive(void) +{ + return crypto_pwhash_MEMLIMIT_SENSITIVE; +} + +int +crypto_pwhash(unsigned char * const out, unsigned long long outlen, + const char * const passwd, unsigned long long passwdlen, + const unsigned char * const salt, + unsigned long long opslimit, size_t memlimit) +{ + return crypto_pwhash_argon2i(out, outlen, passwd, passwdlen, salt, + opslimit, memlimit); +} + +int +crypto_pwhash_str(char out[crypto_pwhash_STRBYTES], + const char * const passwd, unsigned long long passwdlen, + unsigned long long opslimit, size_t memlimit) +{ + return crypto_pwhash_argon2i_str(out, passwd, passwdlen, + opslimit, memlimit); +} + +int +crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES], + const char * const passwd, + unsigned long long passwdlen) +{ + return crypto_pwhash_argon2i_str_verify(str, passwd, passwdlen); +} diff --git a/src/libsodium/include/sodium.h b/src/libsodium/include/sodium.h index 9d2b9d6b..b944861d 100644 --- a/src/libsodium/include/sodium.h +++ b/src/libsodium/include/sodium.h @@ -22,6 +22,7 @@ #include "sodium/crypto_hash_sha512.h" #include "sodium/crypto_onetimeauth.h" #include "sodium/crypto_onetimeauth_poly1305.h" +#include "sodium/crypto_pwhash.h" #include "sodium/crypto_pwhash_argon2i.h" #include "sodium/crypto_pwhash_scryptsalsa208sha256.h" #include "sodium/crypto_scalarmult.h" diff --git a/src/libsodium/include/sodium/crypto_pwhash.h b/src/libsodium/include/sodium/crypto_pwhash.h new file mode 100644 index 00000000..ac6b76f7 --- /dev/null +++ b/src/libsodium/include/sodium/crypto_pwhash.h @@ -0,0 +1,76 @@ +#ifndef crypto_pwhash_H +#define crypto_pwhash_H + +#include + +#include "crypto_pwhash_argon2i.h" +#include "export.h" + +#ifdef __cplusplus +# if __GNUC__ +# pragma GCC diagnostic ignored "-Wlong-long" +# endif +extern "C" { +#endif + +#define crypto_pwhash_SALTBYTES crypto_pwhash_argon2i_SALTBYTES +SODIUM_EXPORT +size_t crypto_pwhash_saltbytes(void); + +#define crypto_pwhash_STRBYTES crypto_pwhash_argon2i_STRBYTES +SODIUM_EXPORT +size_t crypto_pwhash_strbytes(void); + +#define crypto_pwhash_STRPREFIX crypto_pwhash_argon2i_STRPREFIX +SODIUM_EXPORT +const char *crypto_pwhash_strprefix(void); + +#define crypto_pwhash_OPSLIMIT_INTERACTIVE crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE +SODIUM_EXPORT +size_t crypto_pwhash_opslimit_interactive(void); + +#define crypto_pwhash_MEMLIMIT_INTERACTIVE crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE +SODIUM_EXPORT +size_t crypto_pwhash_memlimit_interactive(void); + +#define crypto_pwhash_OPSLIMIT_MODERATE crypto_pwhash_argon2i_OPSLIMIT_MODERATE +SODIUM_EXPORT +size_t crypto_pwhash_opslimit_moderate(void); + +#define crypto_pwhash_MEMLIMIT_MODERATE crypto_pwhash_argon2i_MEMLIMIT_MODERATE +SODIUM_EXPORT +size_t crypto_pwhash_memlimit_moderate(void); + +#define crypto_pwhash_OPSLIMIT_SENSITIVE crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE +SODIUM_EXPORT +size_t crypto_pwhash_opslimit_sensitive(void); + +#define crypto_pwhash_MEMLIMIT_SENSITIVE crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE +SODIUM_EXPORT +size_t crypto_pwhash_memlimit_sensitive(void); + +SODIUM_EXPORT +int crypto_pwhash(unsigned char * const out, unsigned long long outlen, + const char * const passwd, unsigned long long passwdlen, + const unsigned char * const salt, + unsigned long long opslimit, size_t memlimit) + __attribute__ ((warn_unused_result)); + +SODIUM_EXPORT +int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES], + const char * const passwd, unsigned long long passwdlen, + unsigned long long opslimit, size_t memlimit) + __attribute__ ((warn_unused_result)); + +SODIUM_EXPORT +int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES], + const char * const passwd, + unsigned long long passwdlen) + __attribute__ ((warn_unused_result)); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/libsodium/include/sodium/crypto_pwhash_argon2i.h b/src/libsodium/include/sodium/crypto_pwhash_argon2i.h index 204b78f9..043b7de5 100644 --- a/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +++ b/src/libsodium/include/sodium/crypto_pwhash_argon2i.h @@ -2,7 +2,6 @@ #define crypto_pwhash_argon2i_H #include -#include #include "export.h"