2
0

Change the names of some utility functions to be more standard and consistent.

This commit is contained in:
Maarten Billemont 2016-11-03 10:04:18 -04:00
parent 73421b3299
commit f427e06692
10 changed files with 83 additions and 82 deletions

View File

@ -5,3 +5,4 @@ set -e
cd "${BASH_SOURCE%/*}" cd "${BASH_SOURCE%/*}"
rm -vfr lib/*/{.unpacked,.patched,src} lib/include rm -vfr lib/*/{.unpacked,.patched,src} lib/include
rm -vfr *.o *.dSYM mpw mpw-bench mpw-tests

View File

@ -38,7 +38,7 @@ static const uint8_t *mpw_masterKeyForUser_v0(const char *fullName, const char *
const char *mpKeyScope = mpw_scopeForVariant( MPSiteVariantPassword ); const char *mpKeyScope = mpw_scopeForVariant( MPSiteVariantPassword );
trc( "algorithm: v%d\n", 0 ); trc( "algorithm: v%d\n", 0 );
trc( "fullName: %s (%zu)\n", fullName, mpw_charlen( fullName ) ); trc( "fullName: %s (%zu)\n", fullName, mpw_utf8_strlen( fullName ) );
trc( "masterPassword: %s\n", masterPassword ); trc( "masterPassword: %s\n", masterPassword );
trc( "key scope: %s\n", mpKeyScope ); trc( "key scope: %s\n", mpKeyScope );
@ -46,14 +46,14 @@ static const uint8_t *mpw_masterKeyForUser_v0(const char *fullName, const char *
// masterKeySalt = mpKeyScope . #fullName . fullName // masterKeySalt = mpKeyScope . #fullName . fullName
size_t masterKeySaltSize = 0; size_t masterKeySaltSize = 0;
uint8_t *masterKeySalt = NULL; uint8_t *masterKeySalt = NULL;
mpw_pushString( &masterKeySalt, &masterKeySaltSize, mpKeyScope ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, mpKeyScope );
mpw_pushInt( &masterKeySalt, &masterKeySaltSize, htonl( mpw_charlen( fullName ) ) ); mpw_push_int( &masterKeySalt, &masterKeySaltSize, htonl( mpw_utf8_strlen( fullName ) ) );
mpw_pushString( &masterKeySalt, &masterKeySaltSize, fullName ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName );
if (!masterKeySalt) { if (!masterKeySalt) {
ftl( "Could not allocate master key salt: %d\n", errno ); ftl( "Could not allocate master key salt: %d\n", errno );
return NULL; return NULL;
} }
trc( "masterKeySalt ID: %s\n", mpw_idForBuf( masterKeySalt, masterKeySaltSize ) ); trc( "masterKeySalt ID: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) );
// Calculate the master key. // Calculate the master key.
// masterKey = scrypt( masterPassword, masterKeySalt ) // masterKey = scrypt( masterPassword, masterKeySalt )
@ -63,7 +63,7 @@ static const uint8_t *mpw_masterKeyForUser_v0(const char *fullName, const char *
ftl( "Could not allocate master key: %d\n", errno ); ftl( "Could not allocate master key: %d\n", errno );
return NULL; return NULL;
} }
trc( "masterKey ID: %s\n", mpw_idForBuf( masterKey, MP_dkLen ) ); trc( "masterKey ID: %s\n", mpw_id_buf( masterKey, MP_dkLen ) );
return masterKey; return masterKey;
} }
@ -87,19 +87,19 @@ static const char *mpw_passwordForSite_v0(const uint8_t *masterKey, const char *
// sitePasswordSeed = hmac-sha256( masterKey, siteScope . #siteName . siteName . siteCounter . #siteContext . siteContext ) // sitePasswordSeed = hmac-sha256( masterKey, siteScope . #siteName . siteName . siteCounter . #siteContext . siteContext )
size_t sitePasswordInfoSize = 0; size_t sitePasswordInfoSize = 0;
uint8_t *sitePasswordInfo = NULL; uint8_t *sitePasswordInfo = NULL;
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteScope ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteScope );
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( mpw_charlen( siteName ) ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( mpw_utf8_strlen( siteName ) ) );
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteName ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteName );
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( siteCounter ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( siteCounter ) );
if (siteContext) { if (siteContext) {
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( mpw_charlen( siteContext ) ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( mpw_utf8_strlen( siteContext ) ) );
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteContext ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteContext );
} }
if (!sitePasswordInfo) { if (!sitePasswordInfo) {
ftl( "Could not allocate site seed info: %d\n", errno ); ftl( "Could not allocate site seed info: %d\n", errno );
return NULL; return NULL;
} }
trc( "sitePasswordInfo ID: %s\n", mpw_idForBuf( sitePasswordInfo, sitePasswordInfoSize ) ); trc( "sitePasswordInfo ID: %s\n", mpw_id_buf( sitePasswordInfo, sitePasswordInfoSize ) );
const char *sitePasswordSeed = (const char *)mpw_hmac_sha256( masterKey, MP_dkLen, sitePasswordInfo, sitePasswordInfoSize ); const char *sitePasswordSeed = (const char *)mpw_hmac_sha256( masterKey, MP_dkLen, sitePasswordInfo, sitePasswordInfoSize );
mpw_free( sitePasswordInfo, sitePasswordInfoSize ); mpw_free( sitePasswordInfo, sitePasswordInfoSize );
@ -107,7 +107,7 @@ static const char *mpw_passwordForSite_v0(const uint8_t *masterKey, const char *
ftl( "Could not allocate site seed: %d\n", errno ); ftl( "Could not allocate site seed: %d\n", errno );
return NULL; return NULL;
} }
trc( "sitePasswordSeed ID: %s\n", mpw_idForBuf( sitePasswordSeed, 32 ) ); trc( "sitePasswordSeed ID: %s\n", mpw_id_buf( sitePasswordSeed, 32 ) );
// Determine the template. // Determine the template.
const char *template = mpw_templateForType_v0( siteType, htons( sitePasswordSeed[0] ) ); const char *template = mpw_templateForType_v0( siteType, htons( sitePasswordSeed[0] ) );

View File

@ -22,7 +22,7 @@ static const uint8_t *mpw_masterKeyForUser_v1(const char *fullName, const char *
const char *mpKeyScope = mpw_scopeForVariant( MPSiteVariantPassword ); const char *mpKeyScope = mpw_scopeForVariant( MPSiteVariantPassword );
trc( "algorithm: v%d\n", 1 ); trc( "algorithm: v%d\n", 1 );
trc( "fullName: %s (%zu)\n", fullName, mpw_charlen( fullName ) ); trc( "fullName: %s (%zu)\n", fullName, mpw_utf8_strlen( fullName ) );
trc( "masterPassword: %s\n", masterPassword ); trc( "masterPassword: %s\n", masterPassword );
trc( "key scope: %s\n", mpKeyScope ); trc( "key scope: %s\n", mpKeyScope );
@ -30,14 +30,14 @@ static const uint8_t *mpw_masterKeyForUser_v1(const char *fullName, const char *
// masterKeySalt = mpKeyScope . #fullName . fullName // masterKeySalt = mpKeyScope . #fullName . fullName
size_t masterKeySaltSize = 0; size_t masterKeySaltSize = 0;
uint8_t *masterKeySalt = NULL; uint8_t *masterKeySalt = NULL;
mpw_pushString( &masterKeySalt, &masterKeySaltSize, mpKeyScope ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, mpKeyScope );
mpw_pushInt( &masterKeySalt, &masterKeySaltSize, htonl( mpw_charlen( fullName ) ) ); mpw_push_int( &masterKeySalt, &masterKeySaltSize, htonl( mpw_utf8_strlen( fullName ) ) );
mpw_pushString( &masterKeySalt, &masterKeySaltSize, fullName ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName );
if (!masterKeySalt) { if (!masterKeySalt) {
ftl( "Could not allocate master key salt: %d\n", errno ); ftl( "Could not allocate master key salt: %d\n", errno );
return NULL; return NULL;
} }
trc( "masterKeySalt ID: %s\n", mpw_idForBuf( masterKeySalt, masterKeySaltSize ) ); trc( "masterKeySalt ID: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) );
// Calculate the master key. // Calculate the master key.
// masterKey = scrypt( masterPassword, masterKeySalt ) // masterKey = scrypt( masterPassword, masterKeySalt )
@ -47,7 +47,7 @@ static const uint8_t *mpw_masterKeyForUser_v1(const char *fullName, const char *
ftl( "Could not allocate master key: %d\n", errno ); ftl( "Could not allocate master key: %d\n", errno );
return NULL; return NULL;
} }
trc( "masterKey ID: %s\n", mpw_idForBuf( masterKey, MP_dkLen ) ); trc( "masterKey ID: %s\n", mpw_id_buf( masterKey, MP_dkLen ) );
return masterKey; return masterKey;
} }
@ -71,19 +71,19 @@ static const char *mpw_passwordForSite_v1(const uint8_t *masterKey, const char *
// sitePasswordSeed = hmac-sha256( masterKey, siteScope . #siteName . siteName . siteCounter . #siteContext . siteContext ) // sitePasswordSeed = hmac-sha256( masterKey, siteScope . #siteName . siteName . siteCounter . #siteContext . siteContext )
size_t sitePasswordInfoSize = 0; size_t sitePasswordInfoSize = 0;
uint8_t *sitePasswordInfo = NULL; uint8_t *sitePasswordInfo = NULL;
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteScope ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteScope );
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( mpw_charlen( siteName ) ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( mpw_utf8_strlen( siteName ) ) );
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteName ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteName );
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( siteCounter ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( siteCounter ) );
if (siteContext) { if (siteContext) {
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( mpw_charlen( siteContext ) ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( mpw_utf8_strlen( siteContext ) ) );
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteContext ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteContext );
} }
if (!sitePasswordInfo) { if (!sitePasswordInfo) {
ftl( "Could not allocate site seed info: %d\n", errno ); ftl( "Could not allocate site seed info: %d\n", errno );
return NULL; return NULL;
} }
trc( "sitePasswordInfo ID: %s\n", mpw_idForBuf( sitePasswordInfo, sitePasswordInfoSize ) ); trc( "sitePasswordInfo ID: %s\n", mpw_id_buf( sitePasswordInfo, sitePasswordInfoSize ) );
const uint8_t *sitePasswordSeed = mpw_hmac_sha256( masterKey, MP_dkLen, sitePasswordInfo, sitePasswordInfoSize ); const uint8_t *sitePasswordSeed = mpw_hmac_sha256( masterKey, MP_dkLen, sitePasswordInfo, sitePasswordInfoSize );
mpw_free( sitePasswordInfo, sitePasswordInfoSize ); mpw_free( sitePasswordInfo, sitePasswordInfoSize );
@ -91,7 +91,7 @@ static const char *mpw_passwordForSite_v1(const uint8_t *masterKey, const char *
ftl( "Could not allocate site seed: %d\n", errno ); ftl( "Could not allocate site seed: %d\n", errno );
return NULL; return NULL;
} }
trc( "sitePasswordSeed ID: %s\n", mpw_idForBuf( sitePasswordSeed, 32 ) ); trc( "sitePasswordSeed ID: %s\n", mpw_id_buf( sitePasswordSeed, 32 ) );
// Determine the template. // Determine the template.
const char *template = mpw_templateForType( siteType, sitePasswordSeed[0] ); const char *template = mpw_templateForType( siteType, sitePasswordSeed[0] );

View File

@ -22,7 +22,7 @@ static const uint8_t *mpw_masterKeyForUser_v2(const char *fullName, const char *
const char *mpKeyScope = mpw_scopeForVariant( MPSiteVariantPassword ); const char *mpKeyScope = mpw_scopeForVariant( MPSiteVariantPassword );
trc( "algorithm: v%d\n", 2 ); trc( "algorithm: v%d\n", 2 );
trc( "fullName: %s (%zu)\n", fullName, mpw_charlen( fullName ) ); trc( "fullName: %s (%zu)\n", fullName, mpw_utf8_strlen( fullName ) );
trc( "masterPassword: %s\n", masterPassword ); trc( "masterPassword: %s\n", masterPassword );
trc( "key scope: %s\n", mpKeyScope ); trc( "key scope: %s\n", mpKeyScope );
@ -30,14 +30,14 @@ static const uint8_t *mpw_masterKeyForUser_v2(const char *fullName, const char *
// masterKeySalt = mpKeyScope . #fullName . fullName // masterKeySalt = mpKeyScope . #fullName . fullName
size_t masterKeySaltSize = 0; size_t masterKeySaltSize = 0;
uint8_t *masterKeySalt = NULL; uint8_t *masterKeySalt = NULL;
mpw_pushString( &masterKeySalt, &masterKeySaltSize, mpKeyScope ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, mpKeyScope );
mpw_pushInt( &masterKeySalt, &masterKeySaltSize, htonl( mpw_charlen( fullName ) ) ); mpw_push_int( &masterKeySalt, &masterKeySaltSize, htonl( mpw_utf8_strlen( fullName ) ) );
mpw_pushString( &masterKeySalt, &masterKeySaltSize, fullName ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName );
if (!masterKeySalt) { if (!masterKeySalt) {
ftl( "Could not allocate master key salt: %d\n", errno ); ftl( "Could not allocate master key salt: %d\n", errno );
return NULL; return NULL;
} }
trc( "masterKeySalt ID: %s\n", mpw_idForBuf( masterKeySalt, masterKeySaltSize ) ); trc( "masterKeySalt ID: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) );
// Calculate the master key. // Calculate the master key.
// masterKey = scrypt( masterPassword, masterKeySalt ) // masterKey = scrypt( masterPassword, masterKeySalt )
@ -47,7 +47,7 @@ static const uint8_t *mpw_masterKeyForUser_v2(const char *fullName, const char *
ftl( "Could not allocate master key: %d\n", errno ); ftl( "Could not allocate master key: %d\n", errno );
return NULL; return NULL;
} }
trc( "masterKey ID: %s\n", mpw_idForBuf( masterKey, MP_dkLen ) ); trc( "masterKey ID: %s\n", mpw_id_buf( masterKey, MP_dkLen ) );
return masterKey; return masterKey;
} }
@ -71,19 +71,19 @@ static const char *mpw_passwordForSite_v2(const uint8_t *masterKey, const char *
// sitePasswordSeed = hmac-sha256( masterKey, siteScope . #siteName . siteName . siteCounter . #siteContext . siteContext ) // sitePasswordSeed = hmac-sha256( masterKey, siteScope . #siteName . siteName . siteCounter . #siteContext . siteContext )
size_t sitePasswordInfoSize = 0; size_t sitePasswordInfoSize = 0;
uint8_t *sitePasswordInfo = NULL; uint8_t *sitePasswordInfo = NULL;
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteScope ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteScope );
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( strlen( siteName ) ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( strlen( siteName ) ) );
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteName ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteName );
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( siteCounter ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( siteCounter ) );
if (siteContext) { if (siteContext) {
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( strlen( siteContext ) ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( strlen( siteContext ) ) );
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteContext ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteContext );
} }
if (!sitePasswordInfo) { if (!sitePasswordInfo) {
ftl( "Could not allocate site seed info: %d\n", errno ); ftl( "Could not allocate site seed info: %d\n", errno );
return NULL; return NULL;
} }
trc( "sitePasswordInfo ID: %s\n", mpw_idForBuf( sitePasswordInfo, sitePasswordInfoSize ) ); trc( "sitePasswordInfo ID: %s\n", mpw_id_buf( sitePasswordInfo, sitePasswordInfoSize ) );
const uint8_t *sitePasswordSeed = mpw_hmac_sha256( masterKey, MP_dkLen, sitePasswordInfo, sitePasswordInfoSize ); const uint8_t *sitePasswordSeed = mpw_hmac_sha256( masterKey, MP_dkLen, sitePasswordInfo, sitePasswordInfoSize );
mpw_free( sitePasswordInfo, sitePasswordInfoSize ); mpw_free( sitePasswordInfo, sitePasswordInfoSize );
@ -91,7 +91,7 @@ static const char *mpw_passwordForSite_v2(const uint8_t *masterKey, const char *
ftl( "Could not allocate site seed: %d\n", errno ); ftl( "Could not allocate site seed: %d\n", errno );
return NULL; return NULL;
} }
trc( "sitePasswordSeed ID: %s\n", mpw_idForBuf( sitePasswordSeed, 32 ) ); trc( "sitePasswordSeed ID: %s\n", mpw_id_buf( sitePasswordSeed, 32 ) );
// Determine the template. // Determine the template.
const char *template = mpw_templateForType( siteType, sitePasswordSeed[0] ); const char *template = mpw_templateForType( siteType, sitePasswordSeed[0] );

View File

@ -30,14 +30,14 @@ static const uint8_t *mpw_masterKeyForUser_v3(const char *fullName, const char *
// masterKeySalt = mpKeyScope . #fullName . fullName // masterKeySalt = mpKeyScope . #fullName . fullName
size_t masterKeySaltSize = 0; size_t masterKeySaltSize = 0;
uint8_t *masterKeySalt = NULL; uint8_t *masterKeySalt = NULL;
mpw_pushString( &masterKeySalt, &masterKeySaltSize, mpKeyScope ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, mpKeyScope );
mpw_pushInt( &masterKeySalt, &masterKeySaltSize, htonl( strlen( fullName ) ) ); mpw_push_int( &masterKeySalt, &masterKeySaltSize, htonl( strlen( fullName ) ) );
mpw_pushString( &masterKeySalt, &masterKeySaltSize, fullName ); mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName );
if (!masterKeySalt) { if (!masterKeySalt) {
ftl( "Could not allocate master key salt: %d\n", errno ); ftl( "Could not allocate master key salt: %d\n", errno );
return NULL; return NULL;
} }
trc( "masterKeySalt ID: %s\n", mpw_idForBuf( masterKeySalt, masterKeySaltSize ) ); trc( "masterKeySalt ID: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) );
// Calculate the master key. // Calculate the master key.
// masterKey = scrypt( masterPassword, masterKeySalt ) // masterKey = scrypt( masterPassword, masterKeySalt )
@ -47,7 +47,7 @@ static const uint8_t *mpw_masterKeyForUser_v3(const char *fullName, const char *
ftl( "Could not allocate master key: %d\n", errno ); ftl( "Could not allocate master key: %d\n", errno );
return NULL; return NULL;
} }
trc( "masterKey ID: %s\n", mpw_idForBuf( masterKey, MP_dkLen ) ); trc( "masterKey ID: %s\n", mpw_id_buf( masterKey, MP_dkLen ) );
return masterKey; return masterKey;
} }
@ -71,19 +71,19 @@ static const char *mpw_passwordForSite_v3(const uint8_t *masterKey, const char *
// sitePasswordSeed = hmac-sha256( masterKey, siteScope . #siteName . siteName . siteCounter . #siteContext . siteContext ) // sitePasswordSeed = hmac-sha256( masterKey, siteScope . #siteName . siteName . siteCounter . #siteContext . siteContext )
size_t sitePasswordInfoSize = 0; size_t sitePasswordInfoSize = 0;
uint8_t *sitePasswordInfo = NULL; uint8_t *sitePasswordInfo = NULL;
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteScope ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteScope );
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( strlen( siteName ) ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( strlen( siteName ) ) );
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteName ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteName );
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( siteCounter ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( siteCounter ) );
if (siteContext) { if (siteContext) {
mpw_pushInt( &sitePasswordInfo, &sitePasswordInfoSize, htonl( strlen( siteContext ) ) ); mpw_push_int( &sitePasswordInfo, &sitePasswordInfoSize, htonl( strlen( siteContext ) ) );
mpw_pushString( &sitePasswordInfo, &sitePasswordInfoSize, siteContext ); mpw_push_string( &sitePasswordInfo, &sitePasswordInfoSize, siteContext );
} }
if (!sitePasswordInfo) { if (!sitePasswordInfo) {
ftl( "Could not allocate site seed info: %d\n", errno ); ftl( "Could not allocate site seed info: %d\n", errno );
return NULL; return NULL;
} }
trc( "sitePasswordInfo ID: %s\n", mpw_idForBuf( sitePasswordInfo, sitePasswordInfoSize ) ); trc( "sitePasswordInfo ID: %s\n", mpw_id_buf( sitePasswordInfo, sitePasswordInfoSize ) );
const uint8_t *sitePasswordSeed = mpw_hmac_sha256( masterKey, MP_dkLen, sitePasswordInfo, sitePasswordInfoSize ); const uint8_t *sitePasswordSeed = mpw_hmac_sha256( masterKey, MP_dkLen, sitePasswordInfo, sitePasswordInfoSize );
mpw_free( sitePasswordInfo, sitePasswordInfoSize ); mpw_free( sitePasswordInfo, sitePasswordInfoSize );
@ -91,7 +91,7 @@ static const char *mpw_passwordForSite_v3(const uint8_t *masterKey, const char *
ftl( "Could not allocate site seed: %d\n", errno ); ftl( "Could not allocate site seed: %d\n", errno );
return NULL; return NULL;
} }
trc( "sitePasswordSeed ID: %s\n", mpw_idForBuf( sitePasswordSeed, 32 ) ); trc( "sitePasswordSeed ID: %s\n", mpw_id_buf( sitePasswordSeed, 32 ) );
// Determine the template. // Determine the template.
const char *template = mpw_templateForType( siteType, sitePasswordSeed[0] ); const char *template = mpw_templateForType( siteType, sitePasswordSeed[0] );

View File

@ -215,7 +215,7 @@ int main(int argc, char *const argv[]) {
// Output the password. // Output the password.
const uint8_t *masterKey = mpw_masterKeyForUser( const uint8_t *masterKey = mpw_masterKeyForUser(
fullName, masterPassword, algorithmVersion ); fullName, masterPassword, algorithmVersion );
mpw_freeString( masterPassword ); mpw_free_string( masterPassword );
if (!masterKey) if (!masterKey)
ftl( "Couldn't derive master key." ); ftl( "Couldn't derive master key." );

View File

@ -65,7 +65,7 @@ int main(int argc, char *const argv[]) {
} }
// Free test case. // Free test case.
mpw_freeString( sitePassword ); mpw_free_string( sitePassword );
xmlFree( id ); xmlFree( id );
xmlFree( fullName ); xmlFree( fullName );
xmlFree( masterPassword ); xmlFree( masterPassword );

View File

@ -63,11 +63,11 @@ const char **mpw_templatesForType(MPSiteType type, size_t *count) {
switch (type) { switch (type) {
case MPSiteTypeGeneratedMaximum: { case MPSiteTypeGeneratedMaximum: {
return alloc_array( *count, const char *, return mpw_alloc_array( *count, const char *,
"anoxxxxxxxxxxxxxxxxx", "axxxxxxxxxxxxxxxxxno" ); "anoxxxxxxxxxxxxxxxxx", "axxxxxxxxxxxxxxxxxno" );
} }
case MPSiteTypeGeneratedLong: { case MPSiteTypeGeneratedLong: {
return alloc_array( *count, const char *, return mpw_alloc_array( *count, const char *,
"CvcvnoCvcvCvcv", "CvcvCvcvnoCvcv", "CvcvCvcvCvcvno", "CvcvnoCvcvCvcv", "CvcvCvcvnoCvcv", "CvcvCvcvCvcvno",
"CvccnoCvcvCvcv", "CvccCvcvnoCvcv", "CvccCvcvCvcvno", "CvccnoCvcvCvcv", "CvccCvcvnoCvcv", "CvccCvcvCvcvno",
"CvcvnoCvccCvcv", "CvcvCvccnoCvcv", "CvcvCvccCvcvno", "CvcvnoCvccCvcv", "CvcvCvccnoCvcv", "CvcvCvccCvcvno",
@ -77,27 +77,27 @@ const char **mpw_templatesForType(MPSiteType type, size_t *count) {
"CvccnoCvcvCvcc", "CvccCvcvnoCvcc", "CvccCvcvCvccno" ); "CvccnoCvcvCvcc", "CvccCvcvnoCvcc", "CvccCvcvCvccno" );
} }
case MPSiteTypeGeneratedMedium: { case MPSiteTypeGeneratedMedium: {
return alloc_array( *count, const char *, return mpw_alloc_array( *count, const char *,
"CvcnoCvc", "CvcCvcno" ); "CvcnoCvc", "CvcCvcno" );
} }
case MPSiteTypeGeneratedBasic: { case MPSiteTypeGeneratedBasic: {
return alloc_array( *count, const char *, return mpw_alloc_array( *count, const char *,
"aaanaaan", "aannaaan", "aaannaaa" ); "aaanaaan", "aannaaan", "aaannaaa" );
} }
case MPSiteTypeGeneratedShort: { case MPSiteTypeGeneratedShort: {
return alloc_array( *count, const char *, return mpw_alloc_array( *count, const char *,
"Cvcn" ); "Cvcn" );
} }
case MPSiteTypeGeneratedPIN: { case MPSiteTypeGeneratedPIN: {
return alloc_array( *count, const char *, return mpw_alloc_array( *count, const char *,
"nnnn" ); "nnnn" );
} }
case MPSiteTypeGeneratedName: { case MPSiteTypeGeneratedName: {
return alloc_array( *count, const char *, return mpw_alloc_array( *count, const char *,
"cvccvcvcv" ); "cvccvcvcv" );
} }
case MPSiteTypeGeneratedPhrase: { case MPSiteTypeGeneratedPhrase: {
return alloc_array( *count, const char *, return mpw_alloc_array( *count, const char *,
"cvcc cvc cvccvcv cvc", "cvc cvccvcvcv cvcv", "cv cvccv cvc cvcvccv" ); "cvcc cvc cvccvcv cvc", "cvc cvccvcvcv cvcv", "cv cvccv cvc cvcvccv" );
} }
default: { default: {

View File

@ -21,7 +21,7 @@
#include "mpw-util.h" #include "mpw-util.h"
void mpw_pushBuf(uint8_t **const buffer, size_t *const bufferSize, const void *pushBuffer, const size_t pushSize) { void mpw_push_buf(uint8_t **const buffer, size_t *const bufferSize, const void *pushBuffer, const size_t pushSize) {
if (*bufferSize == (size_t)-1) if (*bufferSize == (size_t)-1)
// The buffer was marked as broken, it is missing a previous push. Abort to avoid corrupt content. // The buffer was marked as broken, it is missing a previous push. Abort to avoid corrupt content.
@ -42,14 +42,14 @@ void mpw_pushBuf(uint8_t **const buffer, size_t *const bufferSize, const void *p
memcpy( pushDst, pushBuffer, pushSize ); memcpy( pushDst, pushBuffer, pushSize );
} }
void mpw_pushString(uint8_t **buffer, size_t *const bufferSize, const char *pushString) { void mpw_push_string(uint8_t **buffer, size_t *const bufferSize, const char *pushString) {
mpw_pushBuf( buffer, bufferSize, pushString, strlen( pushString ) ); mpw_push_buf( buffer, bufferSize, pushString, strlen( pushString ) );
} }
void mpw_pushInt(uint8_t **const buffer, size_t *const bufferSize, const uint32_t pushInt) { void mpw_push_int(uint8_t **const buffer, size_t *const bufferSize, const uint32_t pushInt) {
mpw_pushBuf( buffer, bufferSize, &pushInt, sizeof( pushInt ) ); mpw_push_buf( buffer, bufferSize, &pushInt, sizeof( pushInt ) );
} }
void mpw_free(const void *buffer, const size_t bufferSize) { void mpw_free(const void *buffer, const size_t bufferSize) {
@ -60,7 +60,7 @@ void mpw_free(const void *buffer, const size_t bufferSize) {
} }
} }
void mpw_freeString(const char *string) { void mpw_free_string(const char *string) {
mpw_free( string, strlen( string ) ); mpw_free( string, strlen( string ) );
} }
@ -93,7 +93,7 @@ uint8_t const *mpw_hmac_sha256(const uint8_t *key, const size_t keySize, const u
return buffer; return buffer;
} }
const char *mpw_idForBuf(const void *buf, size_t length) { const char *mpw_id_buf(const void *buf, size_t length) {
uint8_t hash[32]; uint8_t hash[32];
SHA256_Buf( buf, length, hash ); SHA256_Buf( buf, length, hash );
@ -194,7 +194,7 @@ const char *mpw_identicon(const char *fullName, const char *masterPassword) {
/** /**
* @return the amount of bytes used by UTF-8 to encode a single character that starts with the given byte. * @return the amount of bytes used by UTF-8 to encode a single character that starts with the given byte.
*/ */
static int mpw_charByteSize(unsigned char utf8Byte) { static int mpw_utf8_sizeof(unsigned char utf8Byte) {
if (!utf8Byte) if (!utf8Byte)
return 0; return 0;
@ -212,11 +212,11 @@ static int mpw_charByteSize(unsigned char utf8Byte) {
return 0; return 0;
} }
const size_t mpw_charlen(const char *utf8String) { const size_t mpw_utf8_strlen(const char *utf8String) {
size_t charlen = 0; size_t charlen = 0;
char *remainingString = (char *)utf8String; char *remainingString = (char *)utf8String;
for (int charByteSize; (charByteSize = mpw_charByteSize( (unsigned char)*remainingString )); remainingString += charByteSize) for (int charByteSize; (charByteSize = mpw_utf8_sizeof( (unsigned char)*remainingString )); remainingString += charByteSize)
++charlen; ++charlen;
return charlen; return charlen;

View File

@ -54,7 +54,7 @@ int mpw_verbosity;
//// Buffers and memory. //// Buffers and memory.
#define alloc_array(_count, _type, ...) ({ \ #define mpw_alloc_array(_count, _type, ...) ({ \
_type stackElements[] = { __VA_ARGS__ }; \ _type stackElements[] = { __VA_ARGS__ }; \
_count = sizeof( stackElements ) / sizeof( _type ); \ _count = sizeof( stackElements ) / sizeof( _type ); \
_type *allocElements = malloc( sizeof( stackElements ) ); \ _type *allocElements = malloc( sizeof( stackElements ) ); \
@ -63,19 +63,19 @@ int mpw_verbosity;
}) })
/** Push a buffer onto a buffer. reallocs the given buffer and appends the given buffer. */ /** Push a buffer onto a buffer. reallocs the given buffer and appends the given buffer. */
void mpw_pushBuf( void mpw_push_buf(
uint8_t **const buffer, size_t *const bufferSize, const void *pushBuffer, const size_t pushSize); uint8_t **const buffer, size_t *const bufferSize, const void *pushBuffer, const size_t pushSize);
/** Push a string onto a buffer. reallocs the given buffer and appends the given string. */ /** Push a string onto a buffer. reallocs the given buffer and appends the given string. */
void mpw_pushString( void mpw_push_string(
uint8_t **buffer, size_t *const bufferSize, const char *pushString); uint8_t **buffer, size_t *const bufferSize, const char *pushString);
/** Push an integer onto a buffer. reallocs the given buffer and appends the given integer. */ /** Push an integer onto a buffer. reallocs the given buffer and appends the given integer. */
void mpw_pushInt( void mpw_push_int(
uint8_t **const buffer, size_t *const bufferSize, const uint32_t pushInt); uint8_t **const buffer, size_t *const bufferSize, const uint32_t pushInt);
/** Free a buffer after zero'ing its contents. */ /** Free a buffer after zero'ing its contents. */
void mpw_free( void mpw_free(
const void *buffer, const size_t bufferSize); const void *buffer, const size_t bufferSize);
/** Free a string after zero'ing its contents. */ /** Free a string after zero'ing its contents. */
void mpw_freeString( void mpw_free_string(
const char *string); const char *string);
//// Cryptographic functions. //// Cryptographic functions.
@ -98,7 +98,7 @@ const char *mpw_hex(const void *buf, size_t length);
const char *mpw_hex_l(uint32_t number); const char *mpw_hex_l(uint32_t number);
/** Encode a fingerprint for a buffer. /** Encode a fingerprint for a buffer.
* @return A C-string in a reused buffer, do not free or store it. */ * @return A C-string in a reused buffer, do not free or store it. */
const char *mpw_idForBuf(const void *buf, size_t length); const char *mpw_id_buf(const void *buf, size_t length);
/** Encode a visual fingerprint for a user. /** Encode a visual fingerprint for a user.
* @return A newly allocated string. */ * @return A newly allocated string. */
const char *mpw_identicon(const char *fullName, const char *masterPassword); const char *mpw_identicon(const char *fullName, const char *masterPassword);
@ -106,4 +106,4 @@ const char *mpw_identicon(const char *fullName, const char *masterPassword);
//// String utilities. //// String utilities.
/** @return The amount of display characters in the given UTF-8 string. */ /** @return The amount of display characters in the given UTF-8 string. */
const size_t mpw_charlen(const char *utf8String); const size_t mpw_utf8_strlen(const char *utf8String);