Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full backend for scrypt with tests #31

Merged
merged 5 commits into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
/test-crypt-md5
/test-crypt-nthash
/test-crypt-pbkdf1-sha1
/test-crypt-scrypt
/test-crypt-sha256
/test-crypt-sha512
/test-crypt-sunmd5
Expand Down
3 changes: 3 additions & 0 deletions LICENSING
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ source tree. For specific licensing terms consult the files themselves.
alg-yescrypt.h, alg-yescrypt-opt.c, alg-yescrypt-sha256.c,
alg-yescrypt-sha256.h, alg-yescrypt-sysendian.h

* Copyright Alexander Peslyak, Björn Esser; 0-clause BSD:
crypt-scrypt.c

* Copyright Michael Bretterklieber, Björn Esser et al.; 2-clause BSD:
crypt-nthash.c

Expand Down
12 changes: 6 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ libcrypt_la_SOURCES = \
alg-yescrypt-sha256.c alg-yescrypt-common.c \
crypt.c crypt-bcrypt.c crypt-des.c crypt-gensalt-static.c \
crypt-gensalt.c crypt-md5.c crypt-nthash.c crypt-pbkdf1-sha1.c \
crypt-sha256.c crypt-sha512.c crypt-static.c crypt-sunmd5.c \
crypt-yescrypt.c randombytes.c

crypt-scrypt.c crypt-sha256.c crypt-sha512.c crypt-static.c \
crypt-sunmd5.c crypt-yescrypt.c randombytes.c

EXTRA_DIST += yescrypt-platform.c

Expand Down Expand Up @@ -157,8 +156,8 @@ check_PROGRAMS = \
test-alg-sha1 test-alg-sha256 test-alg-sha512 \
test-crypt-bcrypt test-crypt-des \
test-crypt-md5 test-crypt-nthash \
test-crypt-pbkdf1-sha1 test-crypt-sha256 test-crypt-sha512 \
test-crypt-sunmd5 test-crypt-yescrypt \
test-crypt-pbkdf1-sha1 test-crypt-scrypt test-crypt-sha256 \
test-crypt-sha512 test-crypt-sunmd5 test-crypt-yescrypt \
test-byteorder test-badsalt test-badsetting test-gensalt \
test-crypt-badargs test-short-outbuf \
test-getrandom-interface test-getrandom-fallbacks
Expand Down Expand Up @@ -192,15 +191,16 @@ LOG_COMPILER = m4/skip-if-exec-format-error
endif
EXTRA_DIST += m4/skip-if-exec-format-error

test_crypt_yescrypt_LDADD = libcrypt.la
test_crypt_bcrypt_LDADD = libcrypt.la
test_crypt_des_LDADD = libcrypt.la
test_crypt_md5_LDADD = libcrypt.la
test_crypt_nthash_LDADD = libcrypt.la
test_crypt_pbkdf1_sha1_LDADD = libcrypt.la
test_crypt_scrypt_LDADD = libcrypt.la
test_crypt_sha256_LDADD = libcrypt.la
test_crypt_sha512_LDADD = libcrypt.la
test_crypt_sunmd5_LDADD = libcrypt.la
test_crypt_yescrypt_LDADD = libcrypt.la
test_badsalt_LDADD = libcrypt.la
test_badsetting_LDADD = libcrypt.la
test_gensalt_LDADD = libcrypt.la
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Please send bug reports, questions and suggestions to

Version 4.2.0
* Implement yescrypt ($y$) and scrypt ($7$) hashing algorithms.
* For scrypt the implemented gensalt function ensures every new hash
is computed using at least 32 MiBytes of RAM.

Version 4.1.2
* Add optional 'check-valgrind' target to the Makefile.
Expand Down
4 changes: 2 additions & 2 deletions alg-yescrypt-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "crypt-port.h"

#if INCLUDE_yescrypt
#if INCLUDE_yescrypt || INCLUDE_scrypt

#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -598,4 +598,4 @@ uint8_t *yescrypt_encode_params_r(const yescrypt_params_t *params,
return buf;
}

#endif /* INCLUDE_yescrypt */
#endif /* INCLUDE_yescrypt || INCLUDE_scrypt */
4 changes: 2 additions & 2 deletions alg-yescrypt-opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "crypt-port.h"

#if INCLUDE_yescrypt
#if INCLUDE_yescrypt || INCLUDE_scrypt

#pragma GCC diagnostic ignored "-Wcast-align"
#ifdef __clang__
Expand Down Expand Up @@ -1426,4 +1426,4 @@ int yescrypt_free_local(yescrypt_local_t *local)
return free_region(local);
}

#endif /* INCLUDE_yescrypt */
#endif /* INCLUDE_yescrypt || INCLUDE_scrypt */
4 changes: 2 additions & 2 deletions alg-yescrypt-sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "crypt-port.h"

#if INCLUDE_yescrypt
#if INCLUDE_yescrypt || INCLUDE_scrypt

#include <assert.h>
#include <stdint.h>
Expand Down Expand Up @@ -649,4 +649,4 @@ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
insecure_memzero(&u, sizeof(u));
}

#endif /* INCLUDE_yescrypt */
#endif /* INCLUDE_yescrypt || INCLUDE_scrypt */
27 changes: 21 additions & 6 deletions crypt-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ typedef union
explicit_memset (s, 0x00, len)
#else
/* The best hope we have in this case. */
static inline
void _xcrypt_secure_memset (void *s, size_t len)
static inline void
_xcrypt_secure_memset (void *s, size_t len)
{
volatile unsigned char *c = s;
while (len--)
Expand All @@ -119,10 +119,25 @@ void _xcrypt_secure_memset (void *s, size_t len)
_xcrypt_secure_memset (s, len)
#endif

/* Provide a safe way to copy strings. */
#define XCRYPT_STRCPY_OR_ABORT(dest, destsize, src) \
assert (destsize >= strlen ((const char *) src) + 1); \
memcpy (dest, src, strlen ((const char *) src) + 1)
/* Provide a safe way to copy strings with the guarantee src,
including its terminating '\0', will fit d_size bytes.
The trailing bytes of d_size will be filled with '\0'.
dst and src must not be NULL. Returns strlen (src). */
static inline size_t
_xcrypt_strcpy_or_abort (char *dst, const size_t d_size,
const char *src)
{
assert (dst != NULL);
assert (src != NULL);
const size_t s_size = strlen (src);
assert (d_size >= s_size + 1);
memcpy (dst, src, s_size);
XCRYPT_SECURE_MEMSET (dst + s_size, d_size - s_size);
return s_size;
}
#define XCRYPT_STRCPY_OR_ABORT(dst, d_size, src) \
_xcrypt_strcpy_or_abort ((char *) dst, (const size_t) d_size, \
(const char *) src)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the casts in the definition of XCRYPT_STRCPY_OR_ABORT necessary? If it's because some callers pass char *, some pass unsigned char *, and some pass void *, instead I suggest making the inline function take void * and const void * arguments instead, and then casting in the body of the function. That way the compiler will at least still catch const-correctness errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to go ahead and merge this and then tinker with XCRYPT_STRCPY_OR_ABORT myself.


/* Per-symbol version tagging. Currently we only know how to do this
using GCC extensions. */
Expand Down
Loading