Add high-level crypto_pwhash() API

This commit is contained in:
Frank Denis 2015-12-29 21:48:08 +01:00
parent c7b9178d5a
commit b5ed4cc34b
5 changed files with 161 additions and 1 deletions

View File

@ -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 \

View File

@ -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);
}

View File

@ -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"

View File

@ -0,0 +1,76 @@
#ifndef crypto_pwhash_H
#define crypto_pwhash_H
#include <stddef.h>
#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

View File

@ -2,7 +2,6 @@
#define crypto_pwhash_argon2i_H
#include <stddef.h>
#include <stdint.h>
#include "export.h"