summaryrefslogtreecommitdiff
path: root/test-crypt-bcrypt.c
AgeCommit message (Collapse)AuthorFilesLines
2019-02-03Consolidate known answer tests for crypt* API.Zack Weinberg1-285/+0
Most of the hashing methods had their own test-crypt-xxx.c program that ran a short sequence of “known answer” tests: crypt(phrase, salt) = expected for fixed values of phrase, salt, and expected. The code involved was very repetitive, taken as a whole, and many of the programs were not very thorough. Consolidate all of these programs into a single program, test-crypt-kat.c (kat = known answer test); test all the hashing methods against the union of all the old programs’ input phrases; test all four supported crypt* APIs for each case; test that for each hash <- crypt(phrase, salt), hash == crypt(phrase, hash) as well. The known answers are generated from a table of combinations, using a Python program that uses an independent implementation of all the hashing methods (passlib <https://passlib.readthedocs.io>, forced to use its internal pure-Python reference implementations instead of C accelerators that may have too much code in common with libxcrypt’s implementations). This program is very slow, and passlib is not part of the Python standard library, and we don’t currently depend on Python during the build at all, so it is not run during a normal build. You have to run it by hand if you change it, and check in the output (test-crypt-kat.inc). passlib currently can’t calculate yescrypt or gost-yescrypt hashes, so we don’t have known answers to compare against for those, but we do still crank all of the passphrases through the algorithm and make sure the hash == crypt(phrase, hash) invariant holds for them. test-crypt-gost-yescrypt.c performs some extra, GY-specific tests as well as known-answer black box tests; that part of it is preserved. It is necessary to increase the timeout for running the test suite under valgrind on Travis, from 10 minutes to 60 minutes. This can’t be done in the documented manner because the “command” you’re supposed to use, travis_wait, is a bash function available in the parent script but not in our .travis_script.sh; it is necessary to replicate that logic in our script.
2019-01-21test-crypt-bcrypt: Fix -Werror=format-overflow.Björn Esser1-2/+3
2018-11-14Skip test-crypt-bcrypt, if no bcrypt method was enabled.Björn Esser1-0/+12
2018-11-10Make bcrypt variants independently configurable.Zack Weinberg1-72/+68
There are now separate INCLUDE_ macros for all four variants of bcrypt. --enable-hashes=bcrypt enables only the preferred $2b$ variant. The $2x$ variant, which has a bug that makes collisions easy to find for some passphrases, is no longer included in the STRONG group, and the OS compatibility groups have been adjusted so that each includes only the variants historically available on the OS we’re being compatible with. As a side-effect, this makes the “optional suffix on the name of the gensalt_fn” column of hashes.lst unnecessary, and allows simplification of gen-hashes.awk. The bcrypt-related tests have not actually changed, but many entries in test case arrays were rearranged to minimize the number of additional ifdefs needed.
2018-10-21Include crypt.h from crypt-port.h.Björn Esser1-1/+0
Since we have a guaranteed way to make sure all generated header files are always present before any object file is compiled, we can drop crypt-base.h and include the local version of crypt.h through crypt-port.h.
2018-08-07Add configure option --disable-failure-tokens.Zack Weinberg1-1/+5
When this option is given, crypt and crypt_r will return NULL on failure, instead of a special "failure token" string that isn't the hash of any passphrase. This was the historical behavior of glibc, FreeBSD libc, and several other implementations.
2018-07-04Make it possible to disable individual hashes at configure time.Zack Weinberg1-0/+12
The table of supported hash algorithms now lives in hashes.lst. The configure script accepts an option --enable-hashes which takes a comma-separated list of hash algorithms to include. We generate a header that defines INCLUDE_ macros for each hash that is enabled, and all of the code is conditionalized appropriately. The default is --enable-hashes=all. --enable-hashes=strong is the equivalent of the old --disable-weak-hashes. You could even do --enable-hashes=bcrypt,des to get a binary-compatible libcrypt.so.1 that still supports almost nothing other than bcrypt.
2018-01-31test-crypt-bcrypt: Fix test with GCC8Björn Esser1-1/+1
2017-10-26<string.h> gets imported through <crypt-port.h> nowBjörn Esser1-1/+0
2017-10-23Reformat all code files to match GNU styleBjörn Esser1-57/+114
2017-10-03For consistency, change all remaining uses of NULL to 0.Zack Weinberg1-1/+1
2017-10-02Grab bag of header-related cleanups.Zack Weinberg1-4/+5
Stop including crypt-symbols.h implicitly. It's a little too much _spukhafte Fernwirkung_ for my taste, and it makes Emacs have trouble parsing the compiler's error messages. Also, rename crypt-symbols.h to crypt-port.h as this is more consistent with its current function, and have it include stdbool.h, stddef.h, and stdint.h for everyone; have configure bomb out if the C99 headers we use are not available; and normalize the order of inclusion in all files. The value of CPPFLAGS passed to test scripts now includes every last one of Automake's CPPFLAGS-fragment variables.
2017-09-21Generate crypt.h for installation.Zack Weinberg1-1/+1
This allows us to cleanly use <sys/cdefs.h>'s definitions of __BEGIN_DECLS, __END_DECLS, __THROW, and __nonnull, with fallbacks if the header doesn't exist or doesn't provide the expected set of declarations. * crypt.h: Rename to crypt-base.h. Replace header and trailer with marker comments. * crypt-private.h: Include crypt-base.h and stddef.h, not crypt.h. * crypt-symbols.h: Based on configure results, conditionally include sys/cdefs.h and define __THROW and __nonnull. * test-crypt-bcrypt.c, test-crypt-des.c, test-crypt-md5.c * test-crypt-sha256.c, test-crypt-sha512.c, test-gensalt.c * test-des-obsolete.c: Include crypt-base.h, not crypt.h. * crypt-obsolete.h: Include crypt-base.h, not crypt.h. Remove extern "C" wrapper and all uses of __THROW; this header is not installed and never used from C++. * gen-crypt-h.awk: New build script. * Makefile.am (crypt.h): Generate from crypt-base.h and config.h, using gen-crypt-h.awk. * configure.ac: Add checks for sys/cdefs.h and the macros we want from it. (AC_CONFIG_SRCDIR): Key off crypt.c instead.
2017-09-17Data buffers for bcryptZack Weinberg1-53/+30
Move as much as possible of the sensitive intermediate data used by bcrypt into a buffer allocated by the caller. This is finickier than for the other hashes because the bcrypt code is more complicated; in particular, because BF_crypt no longer takes a simple pointer to where its output will be written, additional shuffling-around of data inside crypt_bcrypt_rn is necessary to accommodate the self-test. As a consequence of this change, it no longer makes sense for test-crypt-bcrypt to pass "output" buffers of varying sizes to crypt_rn.
2017-09-15Flatten the directory tree.Zack Weinberg1-0/+227
This project is not big enough that it's a problem to have all the source files at the top level, and this eliminates recursion in 'make all'.