2
0

Merge branch 'master' of github.com:Lyndir/MasterPassword

This commit is contained in:
Maarten Billemont 2014-10-18 15:30:58 -04:00
commit 6f741f6f2f
2 changed files with 27 additions and 9 deletions

View File

@ -85,8 +85,7 @@ depend() {
echo
echo "Checking dependency $1..."
objects=( "lib/$1"/*.o )
[[ -e $objects ]] && return
[[ -e "lib/$1/.built" ]] && return
pushd "lib/$1"
files=( * )
@ -113,6 +112,7 @@ depend() {
echo "Building dependency $1..."
if [[ -e Makefile ]]; then
make
date > .built
else
echo >&2 "error: Don't know how to build: $1"
exit 1
@ -125,6 +125,7 @@ depend() {
mpw() {
depend scrypt
echo
echo "Building target: $target..."
CFLAGS=(
# include paths
@ -155,6 +156,7 @@ mpw-bench() {
depend scrypt
depend bcrypt
echo
echo "Building target: $target..."
CFLAGS=(
# include paths
@ -198,6 +200,5 @@ cc() {
}
for target in "${targets[@]}"; do
echo
"$target" "$@"
done

View File

@ -110,7 +110,8 @@ int main(int argc, char *const argv[]) {
}
memset(sitePasswordSeed, 0, sizeof(sitePasswordSeed));
fprintf( stderr, "\riteration %d / %d..", i, iterations );
if (i % 1 == 0)
fprintf( stderr, "\rmpw: iteration %d / %d..", i, iterations );
}
// Output timing results.
@ -122,7 +123,8 @@ int main(int argc, char *const argv[]) {
long long secs = (endTime.tv_sec - startTime.tv_sec);
long long usecs = (endTime.tv_usec - startTime.tv_usec);
double elapsed = secs + usecs / 1000000.0;
fprintf( stdout, "Master Password: %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, iterations / elapsed );
double mpwSpeed = iterations / elapsed;
fprintf( stdout, " done. %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, mpwSpeed );
// Start SHA-256
if (gettimeofday(&startTime, NULL) != 0) {
@ -132,9 +134,13 @@ int main(int argc, char *const argv[]) {
iterations = 50000000;
uint8_t hash[32];
for (int i = 0; i < iterations; ++i)
for (int i = 0; i < iterations; ++i) {
SHA256_Buf(masterPassword, strlen(masterPassword), hash);
if (i % 1000 == 0)
fprintf( stderr, "\rsha256: iteration %d / %d..", i, iterations );
}
// Output timing results.
if (gettimeofday(&endTime, NULL) != 0) {
fprintf(stderr, "Could not get time: %d\n", errno);
@ -143,7 +149,8 @@ int main(int argc, char *const argv[]) {
secs = (endTime.tv_sec - startTime.tv_sec);
usecs = (endTime.tv_usec - startTime.tv_usec);
elapsed = secs + usecs / 1000000.0;
fprintf( stdout, "SHA-256: %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, iterations / elapsed );
double sha256Speed = iterations / elapsed;
fprintf( stdout, " done. %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, sha256Speed );
// Start BCrypt
if (gettimeofday(&startTime, NULL) != 0) {
@ -153,9 +160,13 @@ int main(int argc, char *const argv[]) {
int bcrypt_cost = 9;
iterations = 600;
for (int i = 0; i < iterations; ++i)
for (int i = 0; i < iterations; ++i) {
crypt(masterPassword, crypt_gensalt("$2b$", bcrypt_cost, userName, strlen(userName)));
if (i % 10 == 0)
fprintf( stderr, "\rbcrypt (cost %d): iteration %d / %d..", bcrypt_cost, i, iterations );
}
// Output timing results.
if (gettimeofday(&endTime, NULL) != 0) {
fprintf(stderr, "Could not get time: %d\n", errno);
@ -164,7 +175,13 @@ int main(int argc, char *const argv[]) {
secs = (endTime.tv_sec - startTime.tv_sec);
usecs = (endTime.tv_usec - startTime.tv_usec);
elapsed = secs + usecs / 1000000.0;
fprintf( stdout, "BCrypt (cost %d): %d iterations in %llds %lldµs -> %.2f/s\n", bcrypt_cost, iterations, secs, usecs, iterations / elapsed );
double bcrypt9Speed = iterations / elapsed;
fprintf( stdout, " done. %d iterations in %llds %lldµs -> %.2f/s\n", iterations, secs, usecs, bcrypt9Speed );
// Summarize.
fprintf( stdout, "\n== SUMMARY ==\nOn this machine,\n" );
fprintf( stdout, "mpw is %f times slower than sha256\n", sha256Speed / mpwSpeed );
fprintf( stdout, "mpw is %f times slower than bcrypt (cost 9)\n", bcrypt9Speed / mpwSpeed );
return 0;
}