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

@ -1,4 +1,4 @@
home=http://www.tarsnap.com/scrypt.html home=http://www.tarsnap.com/scrypt.html
git=https://github.com/Tarsnap/scrypt.git git=https://github.com/Tarsnap/scrypt.git
pkg=http://www.tarsnap.com/scrypt/scrypt-1.2.0.tgz pkg=https://www.tarsnap.com/scrypt/scrypt-1.2.1.tgz
pkg_sha256=1754bc89405277c8ac14220377a4c240ddc34b1ce70882aa92cd01bfdc8569d4 pkg_sha256=4621f5e7da2f802e20850436219370092e9fcda93bd598f6d4236cce33f4c577

View File

@ -20,14 +20,23 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef COLOR #if COLOR
#include <unistd.h> #include <unistd.h>
#include <curses.h> #include <curses.h>
#include <term.h> #include <term.h>
#endif #endif
#include <scrypt/sha256.h> #if HAS_CPERCIVA
#include <scrypt/crypto_scrypt.h> #include <scrypt/crypto_scrypt.h>
#include <scrypt/sha256.h>
#elif HAS_SCRYPT_SODIUM
#include <libscrypt.h>
#include <sodium.h>
#endif
#ifndef trc
int mpw_verbosity;
#endif
#include "mpw-util.h" #include "mpw-util.h"
@ -85,30 +94,62 @@ uint8_t const *mpw_scrypt(const size_t keySize, const char *secret, const uint8_
if (!key) if (!key)
return NULL; return NULL;
#if HAS_CPERCIVA
if (crypto_scrypt( (const uint8_t *)secret, strlen( secret ), salt, saltSize, N, r, p, key, keySize ) < 0) { if (crypto_scrypt( (const uint8_t *)secret, strlen( secret ), salt, saltSize, N, r, p, key, keySize ) < 0) {
mpw_free( key, keySize ); mpw_free( key, keySize );
return NULL; return NULL;
} }
#elif HAS_SCRYPT_SODIUM
if (crypto_pwhash_scryptsalsa208sha256_ll( (const uint8_t *)secret, strlen( secret ), salt, saltSize, N, r, p, key, keySize) != 0 ) {
mpw_free( key, keySize );
return NULL;
}
#endif
return key; return key;
} }
uint8_t const *mpw_hmac_sha256(const uint8_t *key, const size_t keySize, const uint8_t *salt, const size_t saltSize) { uint8_t const *mpw_hmac_sha256(const uint8_t *key, const size_t keySize, const uint8_t *salt, const size_t saltSize) {
#if HAS_CPERCIVA
uint8_t *const buffer = malloc( 32 ); uint8_t *const buffer = malloc( 32 );
if (!buffer) if (!buffer)
return NULL; return NULL;
HMAC_SHA256_Buf( key, keySize, salt, saltSize, buffer ); HMAC_SHA256_Buf( key, keySize, salt, saltSize, buffer );
return buffer; return buffer;
#elif HAS_SCRYPT_SODIUM
uint8_t *const buffer = malloc( crypto_auth_hmacsha256_BYTES );
if (!buffer)
return NULL;
crypto_auth_hmacsha256_state state;
if (crypto_auth_hmacsha256_init( &state, key, keySize ) != 0 ||
crypto_auth_hmacsha256_update( &state, salt, saltSize ) != 0 ||
crypto_auth_hmacsha256_final( &state, buffer ) != 0) {
mpw_free( buffer, crypto_auth_hmacsha256_BYTES );
return NULL;
}
return buffer;
#endif
return NULL;
} }
const char *mpw_id_buf(const void *buf, size_t length) { const char *mpw_id_buf(const void *buf, size_t length) {
#if HAS_CPERCIVA
uint8_t hash[32]; uint8_t hash[32];
SHA256_Buf( buf, length, hash ); SHA256_Buf( buf, length, hash );
return mpw_hex( hash, 32 ); return mpw_hex( hash, 32 );
#elif HAS_SCRYPT_SODIUM
uint8_t hash[crypto_hash_sha256_BYTES];
crypto_hash_sha256( hash, buf, length );
return mpw_hex( hash, crypto_hash_sha256_BYTES );
#endif
} }
static char **mpw_hex_buf = NULL; static char **mpw_hex_buf = NULL;
@ -144,10 +185,10 @@ static int initputvar() {
if (!isatty(STDERR_FILENO)) if (!isatty(STDERR_FILENO))
return 0; return 0;
if (putvarc) if (putvarc)
free(putvarc); free( putvarc );
if (!termsetup) { if (!termsetup) {
int status; int status;
if (! (termsetup = (setupterm(NULL, STDERR_FILENO, &status) == OK && status == 1))) { if (! (termsetup = (setupterm( NULL, STDERR_FILENO, &status ) == 0 && status == 1))) {
wrn( "Terminal doesn't support color (setupterm errno %d).\n", status ); wrn( "Terminal doesn't support color (setupterm errno %d).\n", status );
return 0; return 0;
} }
@ -174,8 +215,9 @@ const char *mpw_identicon(const char *fullName, const char *masterPassword) {
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
}; };
uint8_t identiconSeed[32]; const uint8_t *identiconSeed = mpw_hmac_sha256( (const uint8_t *)masterPassword, strlen( masterPassword ), (const uint8_t *)fullName, strlen( fullName ) );
HMAC_SHA256_Buf( masterPassword, strlen( masterPassword ), fullName, strlen( fullName ), identiconSeed ); if (!identiconSeed)
return NULL;
char *colorString, *resetString; char *colorString, *resetString;
#ifdef COLOR #ifdef COLOR
@ -203,6 +245,7 @@ const char *mpw_identicon(const char *fullName, const char *masterPassword) {
accessory[identiconSeed[3] % (sizeof( accessory ) / sizeof( accessory[0] ))], accessory[identiconSeed[3] % (sizeof( accessory ) / sizeof( accessory[0] ))],
resetString ); resetString );
mpw_free( identiconSeed, 32 );
free( colorString ); free( colorString );
free( resetString ); free( resetString );
return identicon; return identicon;

View File

@ -22,7 +22,7 @@
//// Logging. //// Logging.
#ifndef trc #ifndef trc
int mpw_verbosity; extern int mpw_verbosity;
#define trc_level 3 #define trc_level 3
#define trc(...) \ #define trc(...) \
if (mpw_verbosity >= 3) \ if (mpw_verbosity >= 3) \

View File

@ -3916,6 +3916,7 @@
"\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"", "\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"",
"$(inherited)", "$(inherited)",
); );
OTHER_CFLAGS = "-DHAS_CPERCIVA=1";
OTHER_LDFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)";
"OTHER_LDFLAGS[sdk=iphoneos*]" = ( "OTHER_LDFLAGS[sdk=iphoneos*]" = (
"$(inherited)", "$(inherited)",
@ -4192,6 +4193,7 @@
"\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"", "\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"",
"$(inherited)", "$(inherited)",
); );
OTHER_CFLAGS = "-DHAS_CPERCIVA=1";
OTHER_LDFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)";
"OTHER_LDFLAGS[sdk=iphoneos*]" = ( "OTHER_LDFLAGS[sdk=iphoneos*]" = (
"$(inherited)", "$(inherited)",
@ -4230,6 +4232,7 @@
"\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"", "\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"",
"$(inherited)", "$(inherited)",
); );
OTHER_CFLAGS = "-DHAS_CPERCIVA=1";
OTHER_LDFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)";
"OTHER_LDFLAGS[sdk=iphoneos*]" = ( "OTHER_LDFLAGS[sdk=iphoneos*]" = (
"$(inherited)", "$(inherited)",

View File

@ -23,6 +23,13 @@
93D39F833DEC1C89B2F795AC /* MPPasswordWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39A57A7823DE98A0FF83C /* MPPasswordWindowController.m */; }; 93D39F833DEC1C89B2F795AC /* MPPasswordWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39A57A7823DE98A0FF83C /* MPPasswordWindowController.m */; };
DA0933CC1747AD2D00DE1CEF /* shot-laptop-leaning-iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0933CB1747AD2D00DE1CEF /* shot-laptop-leaning-iphone.png */; }; DA0933CC1747AD2D00DE1CEF /* shot-laptop-leaning-iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0933CB1747AD2D00DE1CEF /* shot-laptop-leaning-iphone.png */; };
DA0933D01747B91B00DE1CEF /* appstore.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0933CF1747B91B00DE1CEF /* appstore.png */; }; DA0933D01747B91B00DE1CEF /* appstore.png in Resources */ = {isa = PBXBuildFile; fileRef = DA0933CF1747B91B00DE1CEF /* appstore.png */; };
DA0974541E9957F300F0BFE8 /* libopensslcrypto-osx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DAE8E65319867ADA00416A0F /* libopensslcrypto-osx.a */; };
DA0974551E9957F300F0BFE8 /* libscryptenc-osx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DA5E5C8717248AA1003798D8 /* libscryptenc-osx.a */; };
DA09745A1E99582900F0BFE8 /* mpw-tests-util.c in Sources */ = {isa = PBXBuildFile; fileRef = DA0974561E99582200F0BFE8 /* mpw-tests-util.c */; };
DA09745B1E99582900F0BFE8 /* mpw-tests.c in Sources */ = {isa = PBXBuildFile; fileRef = DA0974571E99582200F0BFE8 /* mpw-tests.c */; };
DA09745E1E99586600F0BFE8 /* libxml2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = DA09745D1E99586600F0BFE8 /* libxml2.tbd */; };
DA0974621E9961F100F0BFE8 /* libsodium.18.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DA0974611E9961F100F0BFE8 /* libsodium.18.dylib */; };
DA0974641E99620400F0BFE8 /* libscrypt.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DA0974631E99620400F0BFE8 /* libscrypt.0.dylib */; };
DA10007F1998A4C6002B873F /* scrypt in Headers */ = {isa = PBXBuildFile; fileRef = DAE8E65619867AF500416A0F /* scrypt */; settings = {ATTRIBUTES = (Public, ); }; }; DA10007F1998A4C6002B873F /* scrypt in Headers */ = {isa = PBXBuildFile; fileRef = DAE8E65619867AF500416A0F /* scrypt */; settings = {ATTRIBUTES = (Public, ); }; };
DA1000801998A4C6002B873F /* openssl in Headers */ = {isa = PBXBuildFile; fileRef = DAE8E65719867AF500416A0F /* openssl */; settings = {ATTRIBUTES = (Public, ); }; }; DA1000801998A4C6002B873F /* openssl in Headers */ = {isa = PBXBuildFile; fileRef = DAE8E65719867AF500416A0F /* openssl */; settings = {ATTRIBUTES = (Public, ); }; };
DA16B341170661DB000A0EAB /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA16B340170661DB000A0EAB /* Carbon.framework */; }; DA16B341170661DB000A0EAB /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA16B340170661DB000A0EAB /* Carbon.framework */; };
@ -285,6 +292,13 @@
DA0933C91747A56A00DE1CEF /* MPInitialWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MPInitialWindow.xib; sourceTree = "<group>"; }; DA0933C91747A56A00DE1CEF /* MPInitialWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MPInitialWindow.xib; sourceTree = "<group>"; };
DA0933CB1747AD2D00DE1CEF /* shot-laptop-leaning-iphone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "shot-laptop-leaning-iphone.png"; sourceTree = "<group>"; }; DA0933CB1747AD2D00DE1CEF /* shot-laptop-leaning-iphone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "shot-laptop-leaning-iphone.png"; sourceTree = "<group>"; };
DA0933CF1747B91B00DE1CEF /* appstore.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = appstore.png; sourceTree = "<group>"; }; DA0933CF1747B91B00DE1CEF /* appstore.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = appstore.png; sourceTree = "<group>"; };
DA0974561E99582200F0BFE8 /* mpw-tests-util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "mpw-tests-util.c"; path = "../../platform-independent/cli-c/cli/mpw-tests-util.c"; sourceTree = "<group>"; };
DA0974571E99582200F0BFE8 /* mpw-tests.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "mpw-tests.c"; path = "../../platform-independent/cli-c/cli/mpw-tests.c"; sourceTree = "<group>"; };
DA09745C1E99583B00F0BFE8 /* mpw-tests-util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "mpw-tests-util.h"; path = "../../platform-independent/cli-c/cli/mpw-tests-util.h"; sourceTree = "<group>"; };
DA09745D1E99586600F0BFE8 /* libxml2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxml2.tbd; path = usr/lib/libxml2.tbd; sourceTree = SDKROOT; };
DA09745F1E995EB500F0BFE8 /* mpw_tests.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = mpw_tests.xml; path = ../../core/java/tests/src/main/resources/mpw_tests.xml; sourceTree = "<group>"; };
DA0974611E9961F100F0BFE8 /* libsodium.18.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsodium.18.dylib; path = ../../../../../../../usr/local/Cellar/libsodium/1.0.12/lib/libsodium.18.dylib; sourceTree = "<group>"; };
DA0974631E99620400F0BFE8 /* libscrypt.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libscrypt.0.dylib; path = ../../../../../../../usr/local/Cellar/libscrypt/1.21/lib/libscrypt.0.dylib; sourceTree = "<group>"; };
DA16B340170661DB000A0EAB /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; }; DA16B340170661DB000A0EAB /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
DA16B343170661EE000A0EAB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; DA16B343170661EE000A0EAB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
DA2508F019511D3600AC23F1 /* MPPasswordWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MPPasswordWindowController.xib; sourceTree = "<group>"; }; DA2508F019511D3600AC23F1 /* MPPasswordWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MPPasswordWindowController.xib; sourceTree = "<group>"; };
@ -945,6 +959,11 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
DA0974641E99620400F0BFE8 /* libscrypt.0.dylib in Frameworks */,
DA0974621E9961F100F0BFE8 /* libsodium.18.dylib in Frameworks */,
DA09745E1E99586600F0BFE8 /* libxml2.tbd in Frameworks */,
DA0974541E9957F300F0BFE8 /* libopensslcrypto-osx.a in Frameworks */,
DA0974551E9957F300F0BFE8 /* libscryptenc-osx.a in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -1025,6 +1044,9 @@
DA5BFA47147E415C00F98B1E /* Frameworks */ = { DA5BFA47147E415C00F98B1E /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
DA0974631E99620400F0BFE8 /* libscrypt.0.dylib */,
DA0974611E9961F100F0BFE8 /* libsodium.18.dylib */,
DA09745D1E99586600F0BFE8 /* libxml2.tbd */,
DA6701B716406A4100B61001 /* Accounts.framework */, DA6701B716406A4100B61001 /* Accounts.framework */,
DA16B340170661DB000A0EAB /* Carbon.framework */, DA16B340170661DB000A0EAB /* Carbon.framework */,
DA16B343170661EE000A0EAB /* Cocoa.framework */, DA16B343170661EE000A0EAB /* Cocoa.framework */,
@ -1552,6 +1574,9 @@
DA831A2A1A6E1146000AC234 /* mpw-algorithm_v3.c */, DA831A2A1A6E1146000AC234 /* mpw-algorithm_v3.c */,
DA6773BB1A4746AF004F356A /* mpw-algorithm.c */, DA6773BB1A4746AF004F356A /* mpw-algorithm.c */,
DA6773BC1A4746AF004F356A /* mpw-algorithm.h */, DA6773BC1A4746AF004F356A /* mpw-algorithm.h */,
DA0974561E99582200F0BFE8 /* mpw-tests-util.c */,
DA09745C1E99583B00F0BFE8 /* mpw-tests-util.h */,
DA0974571E99582200F0BFE8 /* mpw-tests.c */,
DA6773C21A4746AF004F356A /* mpw-types.c */, DA6773C21A4746AF004F356A /* mpw-types.c */,
DA6773C31A4746AF004F356A /* mpw-types.h */, DA6773C31A4746AF004F356A /* mpw-types.h */,
DA6773C51A4746AF004F356A /* mpw-util.c */, DA6773C51A4746AF004F356A /* mpw-util.c */,
@ -1614,6 +1639,7 @@
DACA23B41705DF7D002C6C22 /* Resources */ = { DACA23B41705DF7D002C6C22 /* Resources */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
DA09745F1E995EB500F0BFE8 /* mpw_tests.xml */,
DACA26991705DF81002C6C22 /* Crashlytics */, DACA26991705DF81002C6C22 /* Crashlytics */,
DACA29701705E1A8002C6C22 /* Data */, DACA29701705E1A8002C6C22 /* Data */,
DACA23B51705DF7D002C6C22 /* Media */, DACA23B51705DF7D002C6C22 /* Media */,
@ -2252,6 +2278,8 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
DA09745B1E99582900F0BFE8 /* mpw-tests.c in Sources */,
DA09745A1E99582900F0BFE8 /* mpw-tests-util.c in Sources */,
DA6774451A474A3B004F356A /* mpw-types.c in Sources */, DA6774451A474A3B004F356A /* mpw-types.c in Sources */,
DA6774461A474A3B004F356A /* mpw-util.c in Sources */, DA6774461A474A3B004F356A /* mpw-util.c in Sources */,
DA6774431A474A3B004F356A /* mpw-algorithm.c in Sources */, DA6774431A474A3B004F356A /* mpw-algorithm.c in Sources */,
@ -2471,6 +2499,7 @@
"\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"", "\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"",
"$(inherited)", "$(inherited)",
); );
OTHER_CFLAGS = "-DHAS_CPERCIVA=1";
PRODUCT_BUNDLE_IDENTIFIER = com.lyndir.lhunath.MasterPassword.Mac; PRODUCT_BUNDLE_IDENTIFIER = com.lyndir.lhunath.MasterPassword.Mac;
SKIP_INSTALL = NO; SKIP_INSTALL = NO;
WRAPPER_NAME = "Master Password.${WRAPPER_EXTENSION}"; WRAPPER_NAME = "Master Password.${WRAPPER_EXTENSION}";
@ -2517,8 +2546,19 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = NO; CLANG_WARN_DOCUMENTATION_COMMENTS = NO;
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
/usr/include/libxml2, /usr/include/libxml2,
/usr/local/include,
);
LIBRARY_SEARCH_PATHS = (
"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib",
"$(inherited)",
"$(PROJECT_DIR)/External/Pearl/Pearl-Crypto/lib",
/usr/local/Cellar/libsodium/1.0.12/lib,
/usr/local/Cellar/libscrypt/1.21/lib,
);
OTHER_CFLAGS = (
"-DHAS_CPERCIVA=0",
"-DHAS_SCRYPT_SODIUM=1",
); );
}; };
name = Test; name = Test;
@ -2727,6 +2767,7 @@
"\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"", "\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"",
"$(inherited)", "$(inherited)",
); );
OTHER_CFLAGS = "-DHAS_CPERCIVA=1";
PRODUCT_BUNDLE_IDENTIFIER = com.lyndir.lhunath.MasterPassword.Mac; PRODUCT_BUNDLE_IDENTIFIER = com.lyndir.lhunath.MasterPassword.Mac;
SKIP_INSTALL = NO; SKIP_INSTALL = NO;
WRAPPER_NAME = "Master Password.${WRAPPER_EXTENSION}"; WRAPPER_NAME = "Master Password.${WRAPPER_EXTENSION}";
@ -2754,6 +2795,7 @@
"\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"", "\"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib\"",
"$(inherited)", "$(inherited)",
); );
OTHER_CFLAGS = "-DHAS_CPERCIVA=1";
PRODUCT_BUNDLE_IDENTIFIER = com.lyndir.lhunath.MasterPassword.Mac; PRODUCT_BUNDLE_IDENTIFIER = com.lyndir.lhunath.MasterPassword.Mac;
SKIP_INSTALL = NO; SKIP_INSTALL = NO;
WRAPPER_NAME = "Master Password.${WRAPPER_EXTENSION}"; WRAPPER_NAME = "Master Password.${WRAPPER_EXTENSION}";
@ -2766,8 +2808,19 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = NO; CLANG_WARN_DOCUMENTATION_COMMENTS = NO;
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
/usr/include/libxml2, /usr/include/libxml2,
/usr/local/include,
);
LIBRARY_SEARCH_PATHS = (
"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib",
"$(inherited)",
"$(PROJECT_DIR)/External/Pearl/Pearl-Crypto/lib",
/usr/local/Cellar/libsodium/1.0.12/lib,
/usr/local/Cellar/libscrypt/1.21/lib,
);
OTHER_CFLAGS = (
"-DHAS_CPERCIVA=0",
"-DHAS_SCRYPT_SODIUM=1",
); );
}; };
name = Debug; name = Debug;
@ -2778,8 +2831,19 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = NO; CLANG_WARN_DOCUMENTATION_COMMENTS = NO;
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
/usr/include/libxml2, /usr/include/libxml2,
/usr/local/include,
);
LIBRARY_SEARCH_PATHS = (
"$(SRCROOT)/External/Pearl/Pearl-Crypto/lib",
"$(inherited)",
"$(PROJECT_DIR)/External/Pearl/Pearl-Crypto/lib",
/usr/local/Cellar/libsodium/1.0.12/lib,
/usr/local/Cellar/libscrypt/1.21/lib,
);
OTHER_CFLAGS = (
"-DHAS_CPERCIVA=0",
"-DHAS_SCRYPT_SODIUM=1",
); );
}; };
name = Release; name = Release;

View File

@ -46,7 +46,8 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "YES"
customWorkingDirectory = "/Users/lhunath/Documents/workspace/lyndir/MasterPassword/platform-independent/cli-c"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal" debugServiceExtension = "internal"

View File

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

View File

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

View File

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

View File

@ -15,6 +15,11 @@ int main(int argc, char *const argv[]) {
int failedTests = 0; int failedTests = 0;
xmlNodePtr tests = xmlDocGetRootElement( xmlParseFile( "mpw_tests.xml" ) ); 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) { for (xmlNodePtr testCase = tests->children; testCase; testCase = testCase->next) {
if (testCase->type != XML_ELEMENT_NODE || xmlStrcmp( testCase->name, BAD_CAST "case" ) != 0) if (testCase->type != XML_ELEMENT_NODE || xmlStrcmp( testCase->name, BAD_CAST "case" ) != 0)
continue; continue;