Ejemplo n.º 1
0
const char *mpw_idForBuf(const void *buf, size_t length) {

    uint8_t hash[32];
    SHA256_Buf( buf, length, hash );

    return mpw_hex( hash, 32 );
}
Ejemplo n.º 2
0
int main(int argc, char *const argv[]) {

    const char *fullName = "Robert Lee Mitchel";
    const char *masterPassword = "******";
    const char *siteName = "masterpasswordapp.com";
    const uint32_t siteCounter = 1;
    const MPSiteType siteType = MPSiteTypeGeneratedLong;
    const MPSiteVariant siteVariant = MPSiteVariantPassword;
    const char *siteContext = NULL;
    struct timeval startTime;

    // Start MPW
    unsigned int iterations = 100;
    mpw_getTime( &startTime );
    for (int i = 0; i < iterations; ++i) {
        const uint8_t *masterKey = mpw_masterKeyForUser(
                fullName, masterPassword, MPAlgorithmVersionCurrent );
        if (!masterKey)
            ftl( "Could not allocate master key: %d\n", errno );
        free( (void *)mpw_passwordForSite(
                masterKey, siteName, siteType, siteCounter, siteVariant, siteContext, MPAlgorithmVersionCurrent ) );
        free( (void *)masterKey );

        if (i % ( iterations / 100 ) == 0)
            fprintf( stderr, "\rmpw: iteration %d / %d (%d%%)..", i, iterations, i * 100 / iterations );
    }
    const double mpwSpeed = mpw_showSpeed( startTime, iterations, "mpw" );

    // Start SHA-256
    iterations = 45000000;
    uint8_t hash[32];
    mpw_getTime( &startTime );
    for (int i = 0; i < iterations; ++i) {
        SHA256_Buf( masterPassword, strlen( masterPassword ), hash );

        if (i % ( iterations / 100 ) == 0)
            fprintf( stderr, "\rsha256: iteration %d / %d (%d%%)..", i, iterations, i * 100 / iterations );
    }
    const double sha256Speed = mpw_showSpeed( startTime, iterations, "sha256" );

    // Start BCrypt
    int bcrypt_cost = 9;
    iterations = 1000;
    mpw_getTime( &startTime );
    for (int i = 0; i < iterations; ++i) {
        crypt( masterPassword, crypt_gensalt( "$2b$", bcrypt_cost, fullName, strlen( fullName ) ) );

        if (i % ( iterations / 100 ) == 0)
            fprintf( stderr, "\rbcrypt (cost %d): iteration %d / %d (%d%%)..", bcrypt_cost, i, iterations, i * 100 / iterations );
    }
    const double bcrypt9Speed = mpw_showSpeed( startTime, iterations, "bcrypt9" );

    // Summarize.
    fprintf( stdout, "\n== SUMMARY ==\nOn this machine,\n" );
    fprintf( stdout, " - mpw is %f times slower than sha256 (reference: 320000 on an MBP Late 2013).\n", sha256Speed / mpwSpeed );
    fprintf( stdout, " - mpw is %f times slower than bcrypt (cost 9) (reference: 22 on an MBP Late 2013).\n", bcrypt9Speed / mpwSpeed );

    return 0;
}