2
0

Support for dynamically linking libscrypt & libsodium as alternative to statically linking Tarsnap's scrypt.

This commit is contained in:
Maarten Billemont
2017-04-08 14:25:54 -04:00
parent 98c5ee3425
commit 4058d33202
10 changed files with 170 additions and 40 deletions

View File

@@ -41,13 +41,11 @@ fi
# Optional features.
mpw_color=${mpw_color:-1} # Colorized Identicon, requires libncurses-dev
# Distribution specific configuration.
# Homebrew
if hash brew 2>/dev/null; then
opensslPath=$(brew --prefix openssl)
export CFLAGS="$CFLAGS -I$opensslPath/include"
export LDFLAGS="$LDFLAGS -L$opensslPath/lib"
fi
# Default build flags.
export CFLAGS="-O3 $CFLAGS"
export LDFLAGS="$LDFLAGS"
### DEPENDENCIES
@@ -208,26 +206,40 @@ depend() {
popd
popd
}
depend_scrypt() {
if haslib scrypt && haslib sodium; then
CFLAGS+=" -DHAS_SCRYPT_SODIUM=1"
LDFLAGS+=" -lscrypt -lsodium"
return
fi
depend scrypt
local objects=(
"lib/scrypt/src/libcperciva/"*/*.o
"lib/scrypt/src/lib/crypto/"*.o
)
CFLAGS+=" -DHAS_CPERCIVA=1"
LDFLAGS+=" -Llib/scrypt/src ${objects[*]}"
}
### MPW
mpw() {
depend scrypt
depend_scrypt
echo
echo "Building target: $target..."
local CFLAGS=(
$CFLAGS
# library paths
-I"lib/include"
# mpw paths
-I"core" -I"cli"
)
local LDFLAGS=(
# scrypt
"lib/scrypt/src/libcperciva/"*/*.o
"lib/scrypt/src/lib/crypto/"*.o
# library paths
-L"lib/scrypt/src"
$LDFLAGS
# link libraries
-l"crypto"
)
@@ -245,28 +257,28 @@ mpw() {
### MPW-BENCH
mpw-bench() {
depend scrypt
depend_scrypt
depend bcrypt
echo
echo "Building target: $target..."
local CFLAGS=(
$CFLAGS
# library paths
-I"lib/include"
# mpw paths
-I"core" -I"cli"
)
local LDFLAGS=(
# scrypt
"lib/scrypt/src/libcperciva/"*/*.o
"lib/scrypt/src/lib/crypto/"*.o
$LDFLAGS
# bcrypt
"lib/bcrypt/src/crypt_blowfish.o"
"lib/bcrypt/src/crypt_gensalt.o"
"lib/bcrypt/src/wrapper.o"
"lib/bcrypt/src/x86.o"
# library paths
-L"lib/scrypt/src"
-L"lib/bcrypt/src"
# link libraries
-l"crypto"
@@ -283,11 +295,13 @@ mpw-bench() {
### MPW-TESTS
mpw-tests() {
depend scrypt
depend_scrypt
echo
echo "Building target: $target..."
local CFLAGS=(
$CFLAGS
# library paths
-I"lib/include"
-I"/usr/include/libxml2"
@@ -296,11 +310,8 @@ mpw-tests() {
-I"core" -I"cli"
)
local LDFLAGS=(
# scrypt
"lib/scrypt/src/libcperciva/"*/*.o
"lib/scrypt/src/lib/crypto/"*.o
# library paths
-L"lib/scrypt/src"
$LDFLAGS
# link libraries
-l"crypto" -l"xml2"
)

View File

@@ -13,7 +13,6 @@
#include <errno.h>
#include <sys/time.h>
#include <scrypt/sha256.h>
#include <bcrypt/ow-crypt.h>
#include "mpw-algorithm.h"

View File

@@ -213,8 +213,12 @@ int main(int argc, char *const argv[]) {
// Summarize operation.
const char *identicon = mpw_identicon( fullName, masterPassword );
fprintf( stderr, "%s's password for %s:\n[ %s ]: ", fullName, siteName, identicon );
mpw_free_string( identicon );
if (!identicon) {
err( "Couldn't determine identicon.\n" );
} else {
fprintf( stderr, "%s's password for %s:\n[ %s ]: ", fullName, siteName, identicon );
mpw_free_string( identicon );
}
// Output the password.
const uint8_t *masterKey = mpw_masterKeyForUser(

View File

@@ -15,6 +15,11 @@ int main(int argc, char *const argv[]) {
int failedTests = 0;
xmlNodePtr tests = xmlDocGetRootElement( xmlParseFile( "mpw_tests.xml" ) );
if (!tests) {
ftl( "Couldn't find test case: mpw_tests.xml\n" );
abort();
}
for (xmlNodePtr testCase = tests->children; testCase; testCase = testCase->next) {
if (testCase->type != XML_ELEMENT_NODE || xmlStrcmp( testCase->name, BAD_CAST "case" ) != 0)
continue;