2
0

Harmonize API naming.

This commit is contained in:
Maarten Billemont 2020-01-23 15:53:55 -05:00
parent dd123a431c
commit 4b73508292
16 changed files with 268 additions and 268 deletions

View File

@ -40,16 +40,16 @@
#define MP_r 8 #define MP_r 8
#define MP_p 2 #define MP_p 2
static void mpw_getTime(struct timeval *time) { static void mpw_time(struct timeval *time) {
if (gettimeofday( time, NULL ) != 0) if (gettimeofday( time, NULL ) != 0)
ftl( "Could not get time: %s", strerror( errno ) ); ftl( "Could not get time: %s", strerror( errno ) );
} }
static const double mpw_showSpeed(struct timeval startTime, const unsigned int iterations, const char *operation) { static const double mpw_show_speed(struct timeval startTime, const unsigned int iterations, const char *operation) {
struct timeval endTime; struct timeval endTime;
mpw_getTime( &endTime ); mpw_time( &endTime );
const time_t dsec = (endTime.tv_sec - startTime.tv_sec); const time_t dsec = (endTime.tv_sec - startTime.tv_sec);
const suseconds_t dusec = (endTime.tv_usec - startTime.tv_usec); const suseconds_t dusec = (endTime.tv_usec - startTime.tv_usec);
@ -80,65 +80,65 @@ int main(int argc, char *const argv[]) {
// Similar to phase-two of mpw // Similar to phase-two of mpw
uint8_t *sitePasswordInfo = malloc( 128 ); uint8_t *sitePasswordInfo = malloc( 128 );
iterations = 4200000; /* tuned to ~10s on dev machine */ iterations = 4200000; /* tuned to ~10s on dev machine */
masterKey = mpw_masterKey( fullName, masterPassword, MPAlgorithmVersionCurrent ); masterKey = mpw_master_key( fullName, masterPassword, MPAlgorithmVersionCurrent );
if (!masterKey) { if (!masterKey) {
ftl( "Could not allocate master key: %s", strerror( errno ) ); ftl( "Could not allocate master key: %s", strerror( errno ) );
abort(); abort();
} }
mpw_getTime( &startTime ); mpw_time( &startTime );
for (int i = 1; i <= iterations; ++i) { for (int i = 1; i <= iterations; ++i) {
free( (void *)mpw_hash_hmac_sha256( masterKey, MPMasterKeySize, sitePasswordInfo, 128 ) ); free( (void *)mpw_hash_hmac_sha256( masterKey, MPMasterKeySize, sitePasswordInfo, 128 ) );
if (modff( 100.f * i / iterations, &percent ) == 0) if (modff( 100.f * i / iterations, &percent ) == 0)
fprintf( stderr, "\rhmac-sha-256: iteration %d / %d (%.0f%%)..", i, iterations, percent ); fprintf( stderr, "\rhmac-sha-256: iteration %d / %d (%.0f%%)..", i, iterations, percent );
} }
const double hmacSha256Speed = mpw_showSpeed( startTime, iterations, "hmac-sha-256" ); const double hmacSha256Speed = mpw_show_speed( startTime, iterations, "hmac-sha-256" );
free( (void *)masterKey ); free( (void *)masterKey );
// Start BCrypt // Start BCrypt
// Similar to phase-one of mpw // Similar to phase-one of mpw
uint8_t bcrypt_rounds = 9; uint8_t bcrypt_rounds = 9;
iterations = 170; /* tuned to ~10s on dev machine */ iterations = 170; /* tuned to ~10s on dev machine */
mpw_getTime( &startTime ); mpw_time( &startTime );
for (int i = 1; i <= iterations; ++i) { for (int i = 1; i <= iterations; ++i) {
bcrypt( masterPassword, bcrypt_gensalt( bcrypt_rounds ) ); bcrypt( masterPassword, bcrypt_gensalt( bcrypt_rounds ) );
if (modff( 100.f * i / iterations, &percent ) == 0) if (modff( 100.f * i / iterations, &percent ) == 0)
fprintf( stderr, "\rbcrypt (rounds 10^%d): iteration %d / %d (%.0f%%)..", bcrypt_rounds, i, iterations, percent ); fprintf( stderr, "\rbcrypt (rounds 10^%d): iteration %d / %d (%.0f%%)..", bcrypt_rounds, i, iterations, percent );
} }
const double bcrypt9Speed = mpw_showSpeed( startTime, iterations, "bcrypt" ); const double bcrypt9Speed = mpw_show_speed( startTime, iterations, "bcrypt" );
// Start SCrypt // Start SCrypt
// Phase one of mpw // Phase one of mpw
iterations = 50; /* tuned to ~10s on dev machine */ iterations = 50; /* tuned to ~10s on dev machine */
mpw_getTime( &startTime ); mpw_time( &startTime );
for (int i = 1; i <= iterations; ++i) { for (int i = 1; i <= iterations; ++i) {
free( (void *)mpw_masterKey( fullName, masterPassword, MPAlgorithmVersionCurrent ) ); free( (void *)mpw_master_key( fullName, masterPassword, MPAlgorithmVersionCurrent ) );
if (modff( 100.f * i / iterations, &percent ) == 0) if (modff( 100.f * i / iterations, &percent ) == 0)
fprintf( stderr, "\rscrypt_mpw: iteration %d / %d (%.0f%%)..", i, iterations, percent ); fprintf( stderr, "\rscrypt_mpw: iteration %d / %d (%.0f%%)..", i, iterations, percent );
} }
const double scryptSpeed = mpw_showSpeed( startTime, iterations, "scrypt_mpw" ); const double scryptSpeed = mpw_show_speed( startTime, iterations, "scrypt_mpw" );
// Start MPW // Start MPW
// Both phases of mpw // Both phases of mpw
iterations = 50; /* tuned to ~10s on dev machine */ iterations = 50; /* tuned to ~10s on dev machine */
mpw_getTime( &startTime ); mpw_time( &startTime );
for (int i = 1; i <= iterations; ++i) { for (int i = 1; i <= iterations; ++i) {
masterKey = mpw_masterKey( fullName, masterPassword, MPAlgorithmVersionCurrent ); masterKey = mpw_master_key( fullName, masterPassword, MPAlgorithmVersionCurrent );
if (!masterKey) { if (!masterKey) {
ftl( "Could not allocate master key: %s", strerror( errno ) ); ftl( "Could not allocate master key: %s", strerror( errno ) );
break; break;
} }
free( (void *)mpw_siteResult( free( (void *)mpw_site_result(
masterKey, siteName, siteCounter, keyPurpose, keyContext, resultType, NULL, MPAlgorithmVersionCurrent ) ); masterKey, siteName, siteCounter, keyPurpose, keyContext, resultType, NULL, MPAlgorithmVersionCurrent ) );
free( (void *)masterKey ); free( (void *)masterKey );
if (modff( 100.f * i / iterations, &percent ) == 0) if (modff( 100.f * i / iterations, &percent ) == 0)
fprintf( stderr, "\rmpw: iteration %d / %d (%.0f%%)..", i, iterations, percent ); fprintf( stderr, "\rmpw: iteration %d / %d (%.0f%%)..", i, iterations, percent );
} }
const double mpwSpeed = mpw_showSpeed( startTime, iterations, "mpw" ); const double mpwSpeed = mpw_show_speed( startTime, iterations, "mpw" );
// Summarize. // Summarize.
fprintf( stdout, "\n== SUMMARY ==\nOn this machine,\n" ); fprintf( stdout, "\n== SUMMARY ==\nOn this machine,\n" );

View File

@ -236,15 +236,15 @@ int main(const int argc, char *const argv[]) {
if (operation.user) { if (operation.user) {
dbg( "fullName : %s", operation.user->fullName ); dbg( "fullName : %s", operation.user->fullName );
dbg( "identicon : %s", operation.identicon ); dbg( "identicon : %s", operation.identicon );
dbg( "sitesFormat : %s%s", mpw_nameForFormat( operation.sitesFormat ), operation.sitesFormatFixed? " (fixed)": "" ); dbg( "sitesFormat : %s%s", mpw_format_name( operation.sitesFormat ), operation.sitesFormatFixed? " (fixed)": "" );
dbg( "sitesPath : %s", operation.sitesPath ); dbg( "sitesPath : %s", operation.sitesPath );
} }
if (operation.site) { if (operation.site) {
dbg( "siteName : %s", operation.site->name ); dbg( "siteName : %s", operation.site->name );
dbg( "siteCounter : %u", operation.siteCounter ); dbg( "siteCounter : %u", operation.siteCounter );
dbg( "resultType : %s (%u)", mpw_shortNameForType( operation.resultType ), operation.resultType ); dbg( "resultType : %s (%u)", mpw_type_short_name( operation.resultType ), operation.resultType );
dbg( "resultParam : %s", operation.resultParam ); dbg( "resultParam : %s", operation.resultParam );
dbg( "keyPurpose : %s (%u)", mpw_nameForPurpose( operation.keyPurpose ), operation.keyPurpose ); dbg( "keyPurpose : %s (%u)", mpw_purpose_name( operation.keyPurpose ), operation.keyPurpose );
dbg( "keyContext : %s", operation.keyContext ); dbg( "keyContext : %s", operation.keyContext );
dbg( "algorithmVersion : %u", operation.site->algorithm ); dbg( "algorithmVersion : %u", operation.site->algorithm );
} }
@ -426,7 +426,7 @@ void cli_sitesFormat(Arguments *args, Operation *operation) {
if (!args->sitesFormat) if (!args->sitesFormat)
return; return;
operation->sitesFormat = mpw_formatWithName( args->sitesFormat ); operation->sitesFormat = mpw_format_named( args->sitesFormat );
if (ERR == (int)operation->sitesFormat) { if (ERR == (int)operation->sitesFormat) {
ftl( "Invalid sites format: %s", args->sitesFormat ); ftl( "Invalid sites format: %s", args->sitesFormat );
cli_free( args, operation ); cli_free( args, operation );
@ -439,7 +439,7 @@ void cli_keyPurpose(Arguments *args, Operation *operation) {
if (!args->keyPurpose) if (!args->keyPurpose)
return; return;
operation->keyPurpose = mpw_purposeWithName( args->keyPurpose ); operation->keyPurpose = mpw_purpose_named( args->keyPurpose );
if (ERR == (int)operation->keyPurpose) { if (ERR == (int)operation->keyPurpose) {
ftl( "Invalid purpose: %s", args->keyPurpose ); ftl( "Invalid purpose: %s", args->keyPurpose );
cli_free( args, operation ); cli_free( args, operation );
@ -625,7 +625,7 @@ void cli_resultType(Arguments *args, Operation *operation) {
if (!operation->site) if (!operation->site)
abort(); abort();
operation->resultType = mpw_typeWithName( args->resultType ); operation->resultType = mpw_type_named( args->resultType );
if (ERR == (int)operation->resultType) { if (ERR == (int)operation->resultType) {
ftl( "Invalid type: %s", args->resultType ); ftl( "Invalid type: %s", args->resultType );
cli_free( args, operation ); cli_free( args, operation );
@ -726,7 +726,7 @@ void cli_mpw(Arguments *args, Operation *operation) {
// Update state from resultParam if stateful. // Update state from resultParam if stateful.
if (operation->resultParam && operation->resultType & MPResultTypeClassStateful) { if (operation->resultParam && operation->resultType & MPResultTypeClassStateful) {
mpw_free_string( &operation->resultState ); mpw_free_string( &operation->resultState );
if (!(operation->resultState = mpw_siteState( masterKey, operation->site->name, operation->siteCounter, if (!(operation->resultState = mpw_site_state( masterKey, operation->site->name, operation->siteCounter,
operation->keyPurpose, operation->keyContext, operation->resultType, operation->resultParam, operation->keyPurpose, operation->keyContext, operation->resultType, operation->resultParam,
operation->site->algorithm ))) { operation->site->algorithm ))) {
ftl( "Couldn't encrypt site result." ); ftl( "Couldn't encrypt site result." );
@ -764,7 +764,7 @@ void cli_mpw(Arguments *args, Operation *operation) {
operation->resultParam = mpw_strdup( operation->resultState ); operation->resultParam = mpw_strdup( operation->resultState );
// Generate result. // Generate result.
const char *result = mpw_siteResult( masterKey, operation->site->name, operation->siteCounter, const char *result = mpw_site_result( masterKey, operation->site->name, operation->siteCounter,
operation->keyPurpose, operation->keyContext, operation->resultType, operation->resultParam, operation->site->algorithm ); operation->keyPurpose, operation->keyContext, operation->resultType, operation->resultParam, operation->site->algorithm );
mpw_free( &masterKey, MPMasterKeySize ); mpw_free( &masterKey, MPMasterKeySize );
if (!result) { if (!result) {

View File

@ -104,8 +104,8 @@ int main(int argc, char *const argv[]) {
xmlChar *keyContext = mpw_xmlTestCaseString( testCase, "keyContext" ); xmlChar *keyContext = mpw_xmlTestCaseString( testCase, "keyContext" );
xmlChar *result = mpw_xmlTestCaseString( testCase, "result" ); xmlChar *result = mpw_xmlTestCaseString( testCase, "result" );
MPResultType resultType = mpw_typeWithName( (char *)resultTypeString ); MPResultType resultType = mpw_type_named( (char *)resultTypeString );
MPKeyPurpose keyPurpose = mpw_purposeWithName( (char *)keyPurposeString ); MPKeyPurpose keyPurpose = mpw_purpose_named( (char *)keyPurposeString );
// Run the test case. // Run the test case.
do { do {
@ -125,7 +125,7 @@ int main(int argc, char *const argv[]) {
} }
// 1. calculate the master key. // 1. calculate the master key.
MPMasterKey masterKey = mpw_masterKey( MPMasterKey masterKey = mpw_master_key(
(char *)fullName, (char *)masterPassword, algorithm ); (char *)fullName, (char *)masterPassword, algorithm );
if (!masterKey) { if (!masterKey) {
ftl( "Couldn't derive master key." ); ftl( "Couldn't derive master key." );
@ -141,7 +141,7 @@ int main(int argc, char *const argv[]) {
} }
// 2. calculate the site password. // 2. calculate the site password.
const char *testResult = mpw_siteResult( const char *testResult = mpw_site_result(
masterKey, (char *)siteName, siteCounter, keyPurpose, (char *)keyContext, resultType, NULL, algorithm ); masterKey, (char *)siteName, siteCounter, keyPurpose, (char *)keyContext, resultType, NULL, algorithm );
mpw_free( &masterKey, MPMasterKeySize ); mpw_free( &masterKey, MPMasterKeySize );
if (!testResult) { if (!testResult) {

View File

@ -22,14 +22,14 @@
#include "mpw-algorithm_v2.c" #include "mpw-algorithm_v2.c"
#include "mpw-algorithm_v3.c" #include "mpw-algorithm_v3.c"
MPMasterKey mpw_masterKey(const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion) { MPMasterKey mpw_master_key(const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion) {
if (fullName && !strlen( fullName )) if (fullName && !strlen( fullName ))
fullName = NULL; fullName = NULL;
if (masterPassword && !strlen( masterPassword )) if (masterPassword && !strlen( masterPassword ))
masterPassword = NULL; masterPassword = NULL;
trc( "-- mpw_masterKey (algorithm: %u)", algorithmVersion ); trc( "-- mpw_master_key (algorithm: %u)", algorithmVersion );
trc( "fullName: %s", fullName ); trc( "fullName: %s", fullName );
trc( "masterPassword.id: %s", masterPassword? mpw_id_buf( masterPassword, strlen( masterPassword ) ): NULL ); trc( "masterPassword.id: %s", masterPassword? mpw_id_buf( masterPassword, strlen( masterPassword ) ): NULL );
if (!fullName || !masterPassword) if (!fullName || !masterPassword)
@ -37,50 +37,50 @@ MPMasterKey mpw_masterKey(const char *fullName, const char *masterPassword, cons
switch (algorithmVersion) { switch (algorithmVersion) {
case MPAlgorithmVersion0: case MPAlgorithmVersion0:
return mpw_masterKey_v0( fullName, masterPassword ); return mpw_master_key_v0( fullName, masterPassword );
case MPAlgorithmVersion1: case MPAlgorithmVersion1:
return mpw_masterKey_v1( fullName, masterPassword ); return mpw_master_key_v1( fullName, masterPassword );
case MPAlgorithmVersion2: case MPAlgorithmVersion2:
return mpw_masterKey_v2( fullName, masterPassword ); return mpw_master_key_v2( fullName, masterPassword );
case MPAlgorithmVersion3: case MPAlgorithmVersion3:
return mpw_masterKey_v3( fullName, masterPassword ); return mpw_master_key_v3( fullName, masterPassword );
default: default:
err( "Unsupported version: %d", algorithmVersion ); err( "Unsupported version: %d", algorithmVersion );
return NULL; return NULL;
} }
} }
MPSiteKey mpw_siteKey( MPSiteKey mpw_site_key(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext, const MPAlgorithmVersion algorithmVersion) { const MPKeyPurpose keyPurpose, const char *keyContext, const MPAlgorithmVersion algorithmVersion) {
if (keyContext && !strlen( keyContext )) if (keyContext && !strlen( keyContext ))
keyContext = NULL; keyContext = NULL;
trc( "-- mpw_siteKey (algorithm: %u)", algorithmVersion ); trc( "-- mpw_site_key (algorithm: %u)", algorithmVersion );
trc( "siteName: %s", siteName ); trc( "siteName: %s", siteName );
trc( "siteCounter: %d", siteCounter ); trc( "siteCounter: %d", siteCounter );
trc( "keyPurpose: %d (%s)", keyPurpose, mpw_nameForPurpose( keyPurpose ) ); trc( "keyPurpose: %d (%s)", keyPurpose, mpw_purpose_name( keyPurpose ) );
trc( "keyContext: %s", keyContext ); trc( "keyContext: %s", keyContext );
if (!masterKey || !siteName) if (!masterKey || !siteName)
return NULL; return NULL;
switch (algorithmVersion) { switch (algorithmVersion) {
case MPAlgorithmVersion0: case MPAlgorithmVersion0:
return mpw_siteKey_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext ); return mpw_site_key_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext );
case MPAlgorithmVersion1: case MPAlgorithmVersion1:
return mpw_siteKey_v1( masterKey, siteName, siteCounter, keyPurpose, keyContext ); return mpw_site_key_v1( masterKey, siteName, siteCounter, keyPurpose, keyContext );
case MPAlgorithmVersion2: case MPAlgorithmVersion2:
return mpw_siteKey_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext ); return mpw_site_key_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext );
case MPAlgorithmVersion3: case MPAlgorithmVersion3:
return mpw_siteKey_v3( masterKey, siteName, siteCounter, keyPurpose, keyContext ); return mpw_site_key_v3( masterKey, siteName, siteCounter, keyPurpose, keyContext );
default: default:
err( "Unsupported version: %d", algorithmVersion ); err( "Unsupported version: %d", algorithmVersion );
return NULL; return NULL;
} }
} }
const char *mpw_siteResult( const char *mpw_site_result(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext, const MPKeyPurpose keyPurpose, const char *keyContext,
const MPResultType resultType, const char *resultParam, const MPResultType resultType, const char *resultParam,
@ -91,25 +91,25 @@ const char *mpw_siteResult(
if (resultParam && !strlen( resultParam )) if (resultParam && !strlen( resultParam ))
resultParam = NULL; resultParam = NULL;
MPSiteKey siteKey = mpw_siteKey( masterKey, siteName, siteCounter, keyPurpose, keyContext, algorithmVersion ); MPSiteKey siteKey = mpw_site_key( masterKey, siteName, siteCounter, keyPurpose, keyContext, algorithmVersion );
if (!siteKey) if (!siteKey)
return NULL; return NULL;
trc( "-- mpw_siteResult (algorithm: %u)", algorithmVersion ); trc( "-- mpw_site_result (algorithm: %u)", algorithmVersion );
trc( "resultType: %d (%s)", resultType, mpw_shortNameForType( resultType ) ); trc( "resultType: %d (%s)", resultType, mpw_type_short_name( resultType ) );
trc( "resultParam: %s", resultParam ); trc( "resultParam: %s", resultParam );
char *sitePassword = NULL; char *sitePassword = NULL;
if (resultType & MPResultTypeClassTemplate) { if (resultType & MPResultTypeClassTemplate) {
switch (algorithmVersion) { switch (algorithmVersion) {
case MPAlgorithmVersion0: case MPAlgorithmVersion0:
return mpw_sitePasswordFromTemplate_v0( masterKey, siteKey, resultType, resultParam ); return mpw_site_template_password_v0( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion1: case MPAlgorithmVersion1:
return mpw_sitePasswordFromTemplate_v1( masterKey, siteKey, resultType, resultParam ); return mpw_site_template_password_v1( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion2: case MPAlgorithmVersion2:
return mpw_sitePasswordFromTemplate_v2( masterKey, siteKey, resultType, resultParam ); return mpw_site_template_password_v2( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion3: case MPAlgorithmVersion3:
return mpw_sitePasswordFromTemplate_v3( masterKey, siteKey, resultType, resultParam ); return mpw_site_template_password_v3( masterKey, siteKey, resultType, resultParam );
default: default:
err( "Unsupported version: %d", algorithmVersion ); err( "Unsupported version: %d", algorithmVersion );
return NULL; return NULL;
@ -118,13 +118,13 @@ const char *mpw_siteResult(
else if (resultType & MPResultTypeClassStateful) { else if (resultType & MPResultTypeClassStateful) {
switch (algorithmVersion) { switch (algorithmVersion) {
case MPAlgorithmVersion0: case MPAlgorithmVersion0:
return mpw_sitePasswordFromCrypt_v0( masterKey, siteKey, resultType, resultParam ); return mpw_site_crypted_password_v0( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion1: case MPAlgorithmVersion1:
return mpw_sitePasswordFromCrypt_v1( masterKey, siteKey, resultType, resultParam ); return mpw_site_crypted_password_v1( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion2: case MPAlgorithmVersion2:
return mpw_sitePasswordFromCrypt_v2( masterKey, siteKey, resultType, resultParam ); return mpw_site_crypted_password_v2( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion3: case MPAlgorithmVersion3:
return mpw_sitePasswordFromCrypt_v3( masterKey, siteKey, resultType, resultParam ); return mpw_site_crypted_password_v3( masterKey, siteKey, resultType, resultParam );
default: default:
err( "Unsupported version: %d", algorithmVersion ); err( "Unsupported version: %d", algorithmVersion );
return NULL; return NULL;
@ -133,13 +133,13 @@ const char *mpw_siteResult(
else if (resultType & MPResultTypeClassDerive) { else if (resultType & MPResultTypeClassDerive) {
switch (algorithmVersion) { switch (algorithmVersion) {
case MPAlgorithmVersion0: case MPAlgorithmVersion0:
return mpw_sitePasswordFromDerive_v0( masterKey, siteKey, resultType, resultParam ); return mpw_site_derived_password_v0( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion1: case MPAlgorithmVersion1:
return mpw_sitePasswordFromDerive_v1( masterKey, siteKey, resultType, resultParam ); return mpw_site_derived_password_v1( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion2: case MPAlgorithmVersion2:
return mpw_sitePasswordFromDerive_v2( masterKey, siteKey, resultType, resultParam ); return mpw_site_derived_password_v2( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion3: case MPAlgorithmVersion3:
return mpw_sitePasswordFromDerive_v3( masterKey, siteKey, resultType, resultParam ); return mpw_site_derived_password_v3( masterKey, siteKey, resultType, resultParam );
default: default:
err( "Unsupported version: %d", algorithmVersion ); err( "Unsupported version: %d", algorithmVersion );
return NULL; return NULL;
@ -152,7 +152,7 @@ const char *mpw_siteResult(
return sitePassword; return sitePassword;
} }
const char *mpw_siteState( const char *mpw_site_state(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext, const MPKeyPurpose keyPurpose, const char *keyContext,
const MPResultType resultType, const char *resultParam, const MPResultType resultType, const char *resultParam,
@ -163,25 +163,25 @@ const char *mpw_siteState(
if (resultParam && !strlen( resultParam )) if (resultParam && !strlen( resultParam ))
resultParam = NULL; resultParam = NULL;
MPSiteKey siteKey = mpw_siteKey( masterKey, siteName, siteCounter, keyPurpose, keyContext, algorithmVersion ); MPSiteKey siteKey = mpw_site_key( masterKey, siteName, siteCounter, keyPurpose, keyContext, algorithmVersion );
if (!siteKey) if (!siteKey)
return NULL; return NULL;
trc( "-- mpw_siteState (algorithm: %u)", algorithmVersion ); trc( "-- mpw_site_state (algorithm: %u)", algorithmVersion );
trc( "resultType: %d (%s)", resultType, mpw_shortNameForType( resultType ) ); trc( "resultType: %d (%s)", resultType, mpw_type_short_name( resultType ) );
trc( "resultParam: %zu bytes = %s", sizeof( resultParam ), resultParam ); trc( "resultParam: %zu bytes = %s", sizeof( resultParam ), resultParam );
if (!masterKey || !resultParam) if (!masterKey || !resultParam)
return NULL; return NULL;
switch (algorithmVersion) { switch (algorithmVersion) {
case MPAlgorithmVersion0: case MPAlgorithmVersion0:
return mpw_siteState_v0( masterKey, siteKey, resultType, resultParam ); return mpw_site_state_v0( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion1: case MPAlgorithmVersion1:
return mpw_siteState_v1( masterKey, siteKey, resultType, resultParam ); return mpw_site_state_v1( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion2: case MPAlgorithmVersion2:
return mpw_siteState_v2( masterKey, siteKey, resultType, resultParam ); return mpw_site_state_v2( masterKey, siteKey, resultType, resultParam );
case MPAlgorithmVersion3: case MPAlgorithmVersion3:
return mpw_siteState_v3( masterKey, siteKey, resultType, resultParam ); return mpw_site_state_v3( masterKey, siteKey, resultType, resultParam );
default: default:
err( "Unsupported version: %d", algorithmVersion ); err( "Unsupported version: %d", algorithmVersion );
return NULL; return NULL;

View File

@ -39,28 +39,28 @@ typedef mpw_enum( unsigned int, MPAlgorithmVersion ) {
/** Derive the master key for a user based on their name and master password. /** Derive the master key for a user based on their name and master password.
* @return A new MPMasterKeySize-byte allocated buffer or NULL if an error occurred. */ * @return A new MPMasterKeySize-byte allocated buffer or NULL if an error occurred. */
MPMasterKey mpw_masterKey( MPMasterKey mpw_master_key(
const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion); const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion);
/** Derive the site key for a user's site from the given master key and site parameters. /** Derive the site key for a user's site from the given master key and site parameters.
* @return A new MPSiteKeySize-byte allocated buffer or NULL if an error occurred. */ * @return A new MPSiteKeySize-byte allocated buffer or NULL if an error occurred. */
MPSiteKey mpw_siteKey( MPSiteKey mpw_site_key(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext, const MPAlgorithmVersion algorithmVersion); const MPKeyPurpose keyPurpose, const char *keyContext, const MPAlgorithmVersion algorithmVersion);
/** Generate a site result token from the given parameters. /** Generate a site result token from the given parameters.
* @param resultParam A parameter for the resultType. For stateful result types, the output of mpw_siteState. * @param resultParam A parameter for the resultType. For stateful result types, the output of mpw_site_state.
* @return A newly allocated string or NULL if an error occurred. */ * @return A newly allocated string or NULL if an error occurred. */
const char *mpw_siteResult( const char *mpw_site_result(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext, const MPKeyPurpose keyPurpose, const char *keyContext,
const MPResultType resultType, const char *resultParam, const MPResultType resultType, const char *resultParam,
const MPAlgorithmVersion algorithmVersion); const MPAlgorithmVersion algorithmVersion);
/** Encrypt a stateful site token for persistence. /** Encrypt a stateful site token for persistence.
* @param resultParam A parameter for the resultType. For stateful result types, the desired mpw_siteResult. * @param resultParam A parameter for the resultType. For stateful result types, the desired mpw_site_result.
* @return A newly allocated string or NULL if an error occurred. */ * @return A newly allocated string or NULL if an error occurred. */
const char *mpw_siteState( const char *mpw_site_state(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext, const MPKeyPurpose keyPurpose, const char *keyContext,
const MPResultType resultType, const char *resultParam, const MPResultType resultType, const char *resultParam,

View File

@ -29,18 +29,18 @@
#define MP_otp_window 5 * 60 /* s */ #define MP_otp_window 5 * 60 /* s */
// Algorithm version helpers. // Algorithm version helpers.
static const char *mpw_templateForType_v0(MPResultType type, uint16_t templateIndex) { static const char *mpw_type_template_v0(MPResultType type, uint16_t templateIndex) {
size_t count = 0; size_t count = 0;
const char **templates = mpw_templatesForType( type, &count ); const char **templates = mpw_type_templates( type, &count );
char const *template = templates && count? templates[templateIndex % count]: NULL; char const *template = templates && count? templates[templateIndex % count]: NULL;
free( templates ); free( templates );
return template; return template;
} }
static const char mpw_characterFromClass_v0(char characterClass, uint16_t classIndex) { static const char mpw_class_character_v0(char characterClass, uint16_t classIndex) {
const char *classCharacters = mpw_charactersInClass( characterClass ); const char *classCharacters = mpw_class_characters( characterClass );
if (!classCharacters) if (!classCharacters)
return '\0'; return '\0';
@ -48,10 +48,10 @@ static const char mpw_characterFromClass_v0(char characterClass, uint16_t classI
} }
// Algorithm version overrides. // Algorithm version overrides.
static MPMasterKey mpw_masterKey_v0( static MPMasterKey mpw_master_key_v0(
const char *fullName, const char *masterPassword) { const char *fullName, const char *masterPassword) {
const char *keyScope = mpw_scopeForPurpose( MPKeyPurposeAuthentication ); const char *keyScope = mpw_purpose_scope( MPKeyPurposeAuthentication );
trc( "keyScope: %s", keyScope ); trc( "keyScope: %s", keyScope );
// Calculate the master key salt. // Calculate the master key salt.
@ -82,11 +82,11 @@ static MPMasterKey mpw_masterKey_v0(
return masterKey; return masterKey;
} }
static MPSiteKey mpw_siteKey_v0( static MPSiteKey mpw_site_key_v0(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext) { MPKeyPurpose keyPurpose, const char *keyContext) {
const char *keyScope = mpw_scopeForPurpose( keyPurpose ); const char *keyScope = mpw_purpose_scope( keyPurpose );
trc( "keyScope: %s", keyScope ); trc( "keyScope: %s", keyScope );
// OTP counter value. // OTP counter value.
@ -126,7 +126,7 @@ static MPSiteKey mpw_siteKey_v0(
return siteKey; return siteKey;
} }
static const char *mpw_sitePasswordFromTemplate_v0( static const char *mpw_site_template_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
const char *_siteKey = (const char *)siteKey; const char *_siteKey = (const char *)siteKey;
@ -134,7 +134,7 @@ static const char *mpw_sitePasswordFromTemplate_v0(
// Determine the template. // Determine the template.
uint16_t seedByte; uint16_t seedByte;
mpw_uint16( (uint16_t)_siteKey[0], (uint8_t *)&seedByte ); mpw_uint16( (uint16_t)_siteKey[0], (uint8_t *)&seedByte );
const char *template = mpw_templateForType_v0( resultType, seedByte ); const char *template = mpw_type_template_v0( resultType, seedByte );
trc( "template: %u => %s", seedByte, template ); trc( "template: %u => %s", seedByte, template );
if (!template) if (!template)
return NULL; return NULL;
@ -147,7 +147,7 @@ static const char *mpw_sitePasswordFromTemplate_v0(
char *const sitePassword = calloc( strlen( template ) + 1, sizeof( char ) ); char *const sitePassword = calloc( strlen( template ) + 1, sizeof( char ) );
for (size_t c = 0; c < strlen( template ); ++c) { for (size_t c = 0; c < strlen( template ); ++c) {
mpw_uint16( (uint16_t)_siteKey[c + 1], (uint8_t *)&seedByte ); mpw_uint16( (uint16_t)_siteKey[c + 1], (uint8_t *)&seedByte );
sitePassword[c] = mpw_characterFromClass_v0( template[c], seedByte ); sitePassword[c] = mpw_class_character_v0( template[c], seedByte );
trc( " - class: %c, index: %5u (0x%02hX) => character: %c", trc( " - class: %c, index: %5u (0x%02hX) => character: %c",
template[c], seedByte, seedByte, sitePassword[c] ); template[c], seedByte, seedByte, sitePassword[c] );
} }
@ -156,7 +156,7 @@ static const char *mpw_sitePasswordFromTemplate_v0(
return sitePassword; return sitePassword;
} }
static const char *mpw_sitePasswordFromCrypt_v0( static const char *mpw_site_crypted_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
if (!cipherText) { if (!cipherText) {
@ -186,7 +186,7 @@ static const char *mpw_sitePasswordFromCrypt_v0(
return plainText; return plainText;
} }
static const char *mpw_sitePasswordFromDerive_v0( static const char *mpw_site_derived_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
switch (resultType) { switch (resultType) {
@ -231,7 +231,7 @@ static const char *mpw_sitePasswordFromDerive_v0(
} }
} }
static const char *mpw_siteState_v0( static const char *mpw_site_state_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *plainText) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *plainText) {
// Encrypt // Encrypt

View File

@ -26,38 +26,38 @@
#define MP_otp_window 5 * 60 /* s */ #define MP_otp_window 5 * 60 /* s */
// Inherited functions. // Inherited functions.
MPMasterKey mpw_masterKey_v0( MPMasterKey mpw_master_key_v0(
const char *fullName, const char *masterPassword); const char *fullName, const char *masterPassword);
MPSiteKey mpw_siteKey_v0( MPSiteKey mpw_site_key_v0(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext); MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_sitePasswordFromCrypt_v0( const char *mpw_site_crypted_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_sitePasswordFromDerive_v0( const char *mpw_site_derived_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_siteState_v0( const char *mpw_site_state_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides. // Algorithm version overrides.
static MPMasterKey mpw_masterKey_v1( static MPMasterKey mpw_master_key_v1(
const char *fullName, const char *masterPassword) { const char *fullName, const char *masterPassword) {
return mpw_masterKey_v0( fullName, masterPassword ); return mpw_master_key_v0( fullName, masterPassword );
} }
static MPSiteKey mpw_siteKey_v1( static MPSiteKey mpw_site_key_v1(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext) { MPKeyPurpose keyPurpose, const char *keyContext) {
return mpw_siteKey_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext ); return mpw_site_key_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext );
} }
static const char *mpw_sitePasswordFromTemplate_v1( static const char *mpw_site_template_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
// Determine the template. // Determine the template.
uint8_t seedByte = siteKey[0]; uint8_t seedByte = siteKey[0];
const char *template = mpw_templateForType( resultType, seedByte ); const char *template = mpw_type_template( resultType, seedByte );
trc( "template: %u => %s", seedByte, template ); trc( "template: %u => %s", seedByte, template );
if (!template) if (!template)
return NULL; return NULL;
@ -70,7 +70,7 @@ static const char *mpw_sitePasswordFromTemplate_v1(
char *const sitePassword = calloc( strlen( template ) + 1, sizeof( char ) ); char *const sitePassword = calloc( strlen( template ) + 1, sizeof( char ) );
for (size_t c = 0; c < strlen( template ); ++c) { for (size_t c = 0; c < strlen( template ); ++c) {
seedByte = siteKey[c + 1]; seedByte = siteKey[c + 1];
sitePassword[c] = mpw_characterFromClass( template[c], seedByte ); sitePassword[c] = mpw_class_character( template[c], seedByte );
trc( " - class: %c, index: %3u (0x%02hhX) => character: %c", trc( " - class: %c, index: %3u (0x%02hhX) => character: %c",
template[c], seedByte, seedByte, sitePassword[c] ); template[c], seedByte, seedByte, sitePassword[c] );
} }
@ -79,20 +79,20 @@ static const char *mpw_sitePasswordFromTemplate_v1(
return sitePassword; return sitePassword;
} }
static const char *mpw_sitePasswordFromCrypt_v1( static const char *mpw_site_crypted_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_sitePasswordFromCrypt_v0( masterKey, siteKey, resultType, cipherText ); return mpw_site_crypted_password_v0( masterKey, siteKey, resultType, cipherText );
} }
static const char *mpw_sitePasswordFromDerive_v1( static const char *mpw_site_derived_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromDerive_v0( masterKey, siteKey, resultType, resultParam ); return mpw_site_derived_password_v0( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_siteState_v1( static const char *mpw_site_state_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_siteState_v0( masterKey, siteKey, resultType, state ); return mpw_site_state_v0( masterKey, siteKey, resultType, state );
} }

View File

@ -28,29 +28,29 @@
#define MP_otp_window 5 * 60 /* s */ #define MP_otp_window 5 * 60 /* s */
// Inherited functions. // Inherited functions.
MPMasterKey mpw_masterKey_v1( MPMasterKey mpw_master_key_v1(
const char *fullName, const char *masterPassword); const char *fullName, const char *masterPassword);
const char *mpw_sitePasswordFromTemplate_v1( const char *mpw_site_template_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_sitePasswordFromCrypt_v1( const char *mpw_site_crypted_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_sitePasswordFromDerive_v1( const char *mpw_site_derived_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_siteState_v1( const char *mpw_site_state_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides. // Algorithm version overrides.
static MPMasterKey mpw_masterKey_v2( static MPMasterKey mpw_master_key_v2(
const char *fullName, const char *masterPassword) { const char *fullName, const char *masterPassword) {
return mpw_masterKey_v1( fullName, masterPassword ); return mpw_master_key_v1( fullName, masterPassword );
} }
static MPSiteKey mpw_siteKey_v2( static MPSiteKey mpw_site_key_v2(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext) { MPKeyPurpose keyPurpose, const char *keyContext) {
const char *keyScope = mpw_scopeForPurpose( keyPurpose ); const char *keyScope = mpw_purpose_scope( keyPurpose );
trc( "keyScope: %s", keyScope ); trc( "keyScope: %s", keyScope );
// OTP counter value. // OTP counter value.
@ -90,26 +90,26 @@ static MPSiteKey mpw_siteKey_v2(
return siteKey; return siteKey;
} }
static const char *mpw_sitePasswordFromTemplate_v2( static const char *mpw_site_template_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromTemplate_v1( masterKey, siteKey, resultType, resultParam ); return mpw_site_template_password_v1( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_sitePasswordFromCrypt_v2( static const char *mpw_site_crypted_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_sitePasswordFromCrypt_v1( masterKey, siteKey, resultType, cipherText ); return mpw_site_crypted_password_v1( masterKey, siteKey, resultType, cipherText );
} }
static const char *mpw_sitePasswordFromDerive_v2( static const char *mpw_site_derived_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromDerive_v1( masterKey, siteKey, resultType, resultParam ); return mpw_site_derived_password_v1( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_siteState_v2( static const char *mpw_site_state_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_siteState_v1( masterKey, siteKey, resultType, state ); return mpw_site_state_v1( masterKey, siteKey, resultType, state );
} }

View File

@ -27,23 +27,23 @@
#define MP_otp_window 5 * 60 /* s */ #define MP_otp_window 5 * 60 /* s */
// Inherited functions. // Inherited functions.
MPSiteKey mpw_siteKey_v2( MPSiteKey mpw_site_key_v2(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext); MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_sitePasswordFromTemplate_v2( const char *mpw_site_template_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_sitePasswordFromCrypt_v2( const char *mpw_site_crypted_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_sitePasswordFromDerive_v2( const char *mpw_site_derived_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_siteState_v2( const char *mpw_site_state_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides. // Algorithm version overrides.
static MPMasterKey mpw_masterKey_v3( static MPMasterKey mpw_master_key_v3(
const char *fullName, const char *masterPassword) { const char *fullName, const char *masterPassword) {
const char *keyScope = mpw_scopeForPurpose( MPKeyPurposeAuthentication ); const char *keyScope = mpw_purpose_scope( MPKeyPurposeAuthentication );
trc( "keyScope: %s", keyScope ); trc( "keyScope: %s", keyScope );
// Calculate the master key salt. // Calculate the master key salt.
@ -74,33 +74,33 @@ static MPMasterKey mpw_masterKey_v3(
return masterKey; return masterKey;
} }
static MPSiteKey mpw_siteKey_v3( static MPSiteKey mpw_site_key_v3(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext) { MPKeyPurpose keyPurpose, const char *keyContext) {
return mpw_siteKey_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext ); return mpw_site_key_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext );
} }
static const char *mpw_sitePasswordFromTemplate_v3( static const char *mpw_site_template_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromTemplate_v2( masterKey, siteKey, resultType, resultParam ); return mpw_site_template_password_v2( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_sitePasswordFromCrypt_v3( static const char *mpw_site_crypted_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_sitePasswordFromCrypt_v2( masterKey, siteKey, resultType, cipherText ); return mpw_site_crypted_password_v2( masterKey, siteKey, resultType, cipherText );
} }
static const char *mpw_sitePasswordFromDerive_v3( static const char *mpw_site_derived_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromDerive_v2( masterKey, siteKey, resultType, resultParam ); return mpw_site_derived_password_v2( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_siteState_v3( static const char *mpw_site_state_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_siteState_v2( masterKey, siteKey, resultType, state ); return mpw_site_state_v2( masterKey, siteKey, resultType, state );
} }

View File

@ -25,7 +25,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__
const char *fullNameString = (*env)->GetStringUTFChars( env, fullName, NULL ); const char *fullNameString = (*env)->GetStringUTFChars( env, fullName, NULL );
jbyte *masterPasswordString = (*env)->GetByteArrayElements( env, masterPassword, NULL ); jbyte *masterPasswordString = (*env)->GetByteArrayElements( env, masterPassword, NULL );
MPMasterKey masterKeyBytes = mpw_masterKey( fullNameString, (char *)masterPasswordString, (MPAlgorithmVersion)algorithmVersion ); MPMasterKey masterKeyBytes = mpw_master_key( fullNameString, (char *)masterPasswordString, (MPAlgorithmVersion)algorithmVersion );
(*env)->ReleaseStringUTFChars( env, fullName, fullNameString ); (*env)->ReleaseStringUTFChars( env, fullName, fullNameString );
(*env)->ReleaseByteArrayElements( env, masterPassword, masterPasswordString, JNI_ABORT ); (*env)->ReleaseByteArrayElements( env, masterPassword, masterPasswordString, JNI_ABORT );
@ -50,7 +50,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__
jbyte *masterKeyBytes = (*env)->GetByteArrayElements( env, masterKey, NULL ); jbyte *masterKeyBytes = (*env)->GetByteArrayElements( env, masterKey, NULL );
const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL ); const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL );
const char *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, NULL ): NULL; const char *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, NULL ): NULL;
MPMasterKey siteKeyBytes = mpw_siteKey( MPMasterKey siteKeyBytes = mpw_site_key(
(MPMasterKey)masterKeyBytes, siteNameString, (MPCounterValue)siteCounter, (MPMasterKey)masterKeyBytes, siteNameString, (MPCounterValue)siteCounter,
(MPKeyPurpose)keyPurpose, keyContextString, (MPAlgorithmVersion)algorithmVersion ); (MPKeyPurpose)keyPurpose, keyContextString, (MPAlgorithmVersion)algorithmVersion );
(*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT ); (*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT );
@ -83,7 +83,7 @@ JNIEXPORT jstring JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1si
const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL ); const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL );
const char *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, NULL ): NULL; const char *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, NULL ): NULL;
const char *resultParamString = resultParam? (*env)->GetStringUTFChars( env, resultParam, NULL ): NULL; const char *resultParamString = resultParam? (*env)->GetStringUTFChars( env, resultParam, NULL ): NULL;
const char *siteResultString = mpw_siteResult( const char *siteResultString = mpw_site_result(
(MPMasterKey)masterKeyBytes, siteNameString, (MPCounterValue)siteCounter, (MPMasterKey)masterKeyBytes, siteNameString, (MPCounterValue)siteCounter,
(MPKeyPurpose)keyPurpose, keyContextString, (MPResultType)resultType, resultParamString, (MPAlgorithmVersion)algorithmVersion ); (MPKeyPurpose)keyPurpose, keyContextString, (MPResultType)resultType, resultParamString, (MPAlgorithmVersion)algorithmVersion );
(*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT ); (*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT );
@ -118,7 +118,7 @@ JNIEXPORT jstring JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1si
const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL ); const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, NULL );
const char *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, NULL ): NULL; const char *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, NULL ): NULL;
const char *resultParamString = (*env)->GetStringUTFChars( env, resultParam, NULL ); const char *resultParamString = (*env)->GetStringUTFChars( env, resultParam, NULL );
const char *siteStateString = mpw_siteState( const char *siteStateString = mpw_site_state(
(MPMasterKey)masterKeyBytes, siteNameString, (MPCounterValue)siteCounter, (MPMasterKey)masterKeyBytes, siteNameString, (MPCounterValue)siteCounter,
(MPKeyPurpose)keyPurpose, keyContextString, (MPResultType)resultType, resultParamString, (MPAlgorithmVersion)algorithmVersion ); (MPKeyPurpose)keyPurpose, keyContextString, (MPResultType)resultType, resultParamString, (MPAlgorithmVersion)algorithmVersion );
(*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT ); (*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT );

View File

@ -103,13 +103,13 @@ bool mpw_get_json_boolean(
} }
#endif #endif
bool mpw_update_masterKey(MPMasterKey *masterKey, MPAlgorithmVersion *masterKeyAlgorithm, MPAlgorithmVersion targetKeyAlgorithm, bool mpw_update_master_key(MPMasterKey *masterKey, MPAlgorithmVersion *masterKeyAlgorithm, MPAlgorithmVersion targetKeyAlgorithm,
const char *fullName, const char *masterPassword) { const char *fullName, const char *masterPassword) {
if (masterKey && (!*masterKey || *masterKeyAlgorithm != targetKeyAlgorithm)) { if (masterKey && (!*masterKey || *masterKeyAlgorithm != targetKeyAlgorithm)) {
mpw_free( masterKey, MPMasterKeySize ); mpw_free( masterKey, MPMasterKeySize );
*masterKeyAlgorithm = targetKeyAlgorithm; *masterKeyAlgorithm = targetKeyAlgorithm;
*masterKey = mpw_masterKey( fullName, masterPassword, *masterKeyAlgorithm ); *masterKey = mpw_master_key( fullName, masterPassword, *masterKeyAlgorithm );
if (!*masterKey) { if (!*masterKey) {
err( "Couldn't derive master key for user %s, algorithm %d.", fullName, *masterKeyAlgorithm ); err( "Couldn't derive master key for user %s, algorithm %d.", fullName, *masterKeyAlgorithm );
return false; return false;

View File

@ -66,7 +66,7 @@ bool mpw_get_json_boolean(
/** Calculate a master key if the target master key algorithm is different from the given master key algorithm. /** Calculate a master key if the target master key algorithm is different from the given master key algorithm.
* @return false if an error occurred during the derivation of the master key. */ * @return false if an error occurred during the derivation of the master key. */
bool mpw_update_masterKey( bool mpw_update_master_key(
MPMasterKey *masterKey, MPAlgorithmVersion *masterKeyAlgorithm, MPAlgorithmVersion targetKeyAlgorithm, MPMasterKey *masterKey, MPAlgorithmVersion *masterKeyAlgorithm, MPAlgorithmVersion targetKeyAlgorithm,
const char *fullName, const char *masterPassword); const char *fullName, const char *masterPassword);

View File

@ -186,9 +186,9 @@ static bool mpw_marshal_write_flat(
return false; return false;
} }
resultState = mpw_siteResult( masterKey, site->name, site->counter, resultState = mpw_site_result( masterKey, site->name, site->counter,
MPKeyPurposeAuthentication, NULL, site->resultType, site->resultState, site->algorithm ); MPKeyPurposeAuthentication, NULL, site->resultType, site->resultState, site->algorithm );
loginState = mpw_siteResult( masterKey, site->name, MPCounterValueInitial, loginState = mpw_site_result( masterKey, site->name, MPCounterValueInitial,
MPKeyPurposeIdentification, NULL, site->loginType, site->loginState, site->algorithm ); MPKeyPurposeIdentification, NULL, site->loginType, site->loginState, site->algorithm );
} }
else { else {
@ -269,9 +269,9 @@ static bool mpw_marshal_write_json(
return false; return false;
} }
resultState = mpw_siteResult( masterKey, site->name, site->counter, resultState = mpw_site_result( masterKey, site->name, site->counter,
MPKeyPurposeAuthentication, NULL, site->resultType, site->resultState, site->algorithm ); MPKeyPurposeAuthentication, NULL, site->resultType, site->resultState, site->algorithm );
loginState = mpw_siteResult( masterKey, site->name, MPCounterValueInitial, loginState = mpw_site_result( masterKey, site->name, MPCounterValueInitial,
MPKeyPurposeIdentification, NULL, site->loginType, site->loginState, site->algorithm ); MPKeyPurposeIdentification, NULL, site->loginType, site->loginState, site->algorithm );
} }
else { else {
@ -311,7 +311,7 @@ static bool mpw_marshal_write_json(
if (!user->redacted) { if (!user->redacted) {
// Clear Text // Clear Text
const char *answerState = mpw_siteResult( masterKey, site->name, MPCounterValueInitial, const char *answerState = mpw_site_result( masterKey, site->name, MPCounterValueInitial,
MPKeyPurposeRecovery, question->keyword, question->type, question->state, site->algorithm ); MPKeyPurposeRecovery, question->keyword, question->type, question->state, site->algorithm );
json_object_object_add( json_site_question, "answer", json_object_new_string( answerState ) ); json_object_object_add( json_site_question, "answer", json_object_new_string( answerState ) );
} }
@ -500,7 +500,7 @@ static MPMarshalledUser *mpw_marshal_read_flat(
keyID = mpw_strdup( headerValue ); keyID = mpw_strdup( headerValue );
if (strcmp( headerName, "Default Type" ) == 0) { if (strcmp( headerName, "Default Type" ) == 0) {
int value = atoi( headerValue ); int value = atoi( headerValue );
if (!mpw_shortNameForType( (MPResultType)value )) { if (!mpw_type_short_name( (MPResultType)value )) {
*error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user default type: %s", headerValue ) }; *error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user default type: %s", headerValue ) };
return NULL; return NULL;
} }
@ -561,7 +561,7 @@ static MPMarshalledUser *mpw_marshal_read_flat(
if (siteName && str_type && str_counter && str_algorithm && str_uses && str_lastUsed) { if (siteName && str_type && str_counter && str_algorithm && str_uses && str_lastUsed) {
MPResultType siteType = (MPResultType)atoi( str_type ); MPResultType siteType = (MPResultType)atoi( str_type );
if (!mpw_shortNameForType( siteType )) { if (!mpw_type_short_name( siteType )) {
*error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid site type: %s: %s", siteName, str_type ) }; *error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid site type: %s: %s", siteName, str_type ) };
return NULL; return NULL;
} }
@ -601,10 +601,10 @@ static MPMarshalledUser *mpw_marshal_read_flat(
} }
if (siteResultState && strlen( siteResultState )) if (siteResultState && strlen( siteResultState ))
site->resultState = mpw_siteState( masterKey, site->name, site->counter, site->resultState = mpw_site_state( masterKey, site->name, site->counter,
MPKeyPurposeAuthentication, NULL, site->resultType, siteResultState, site->algorithm ); MPKeyPurposeAuthentication, NULL, site->resultType, siteResultState, site->algorithm );
if (siteLoginState && strlen( siteLoginState )) if (siteLoginState && strlen( siteLoginState ))
site->loginState = mpw_siteState( masterKey, site->name, MPCounterValueInitial, site->loginState = mpw_site_state( masterKey, site->name, MPCounterValueInitial,
MPKeyPurposeIdentification, NULL, site->loginType, siteLoginState, site->algorithm ); MPKeyPurposeIdentification, NULL, site->loginType, siteLoginState, site->algorithm );
} }
else { else {
@ -703,7 +703,7 @@ static MPMarshalledUser *mpw_marshal_read_json(
} }
MPAlgorithmVersion algorithm = (MPAlgorithmVersion)value; MPAlgorithmVersion algorithm = (MPAlgorithmVersion)value;
MPResultType defaultType = (MPResultType)mpw_get_json_int( json_file, "user.default_type", MPResultTypeDefault ); MPResultType defaultType = (MPResultType)mpw_get_json_int( json_file, "user.default_type", MPResultTypeDefault );
if (!mpw_shortNameForType( defaultType )) { if (!mpw_type_short_name( defaultType )) {
*error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user default type: %u", defaultType ) }; *error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user default type: %u", defaultType ) };
return NULL; return NULL;
} }
@ -745,7 +745,7 @@ static MPMarshalledUser *mpw_marshal_read_json(
} }
MPAlgorithmVersion siteAlgorithm = (MPAlgorithmVersion)value; MPAlgorithmVersion siteAlgorithm = (MPAlgorithmVersion)value;
MPResultType siteType = (MPResultType)mpw_get_json_int( json_site.val, "type", (int32_t)user->defaultType ); MPResultType siteType = (MPResultType)mpw_get_json_int( json_site.val, "type", (int32_t)user->defaultType );
if (!mpw_shortNameForType( siteType )) { if (!mpw_type_short_name( siteType )) {
*error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid site type: %s: %u", siteName, siteType ) }; *error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid site type: %s: %u", siteName, siteType ) };
return NULL; return NULL;
} }
@ -788,10 +788,10 @@ static MPMarshalledUser *mpw_marshal_read_json(
} }
if (siteResultState && strlen( siteResultState )) if (siteResultState && strlen( siteResultState ))
site->resultState = mpw_siteState( masterKey, site->name, site->counter, site->resultState = mpw_site_state( masterKey, site->name, site->counter,
MPKeyPurposeAuthentication, NULL, site->resultType, siteResultState, site->algorithm ); MPKeyPurposeAuthentication, NULL, site->resultType, siteResultState, site->algorithm );
if (siteLoginState && strlen( siteLoginState )) if (siteLoginState && strlen( siteLoginState ))
site->loginState = mpw_siteState( masterKey, site->name, MPCounterValueInitial, site->loginState = mpw_site_state( masterKey, site->name, MPCounterValueInitial,
MPKeyPurposeIdentification, NULL, site->loginType, siteLoginState, site->algorithm ); MPKeyPurposeIdentification, NULL, site->loginType, siteLoginState, site->algorithm );
} }
else { else {
@ -813,7 +813,7 @@ static MPMarshalledUser *mpw_marshal_read_json(
if (!user->redacted) { if (!user->redacted) {
// Clear Text // Clear Text
if (answerState && strlen( answerState )) if (answerState && strlen( answerState ))
question->state = mpw_siteState( masterKey, site->name, MPCounterValueInitial, question->state = mpw_site_state( masterKey, site->name, MPCounterValueInitial,
MPKeyPurposeRecovery, question->keyword, question->type, answerState, site->algorithm ); MPKeyPurposeRecovery, question->keyword, question->type, answerState, site->algorithm );
} }
else { else {
@ -874,24 +874,24 @@ MPMarshalledUser *mpw_marshal_read(
} }
} }
const MPMarshalFormat mpw_formatWithName( const MPMarshalFormat mpw_format_named(
const char *formatName) { const char *formatName) {
if (!formatName || !strlen( formatName )) if (!formatName || !strlen( formatName ))
return MPMarshalFormatNone; return MPMarshalFormatNone;
if (mpw_strncasecmp( mpw_nameForFormat( MPMarshalFormatNone ), formatName, strlen( formatName ) ) == 0) if (mpw_strncasecmp( mpw_format_name( MPMarshalFormatNone ), formatName, strlen( formatName ) ) == 0)
return MPMarshalFormatNone; return MPMarshalFormatNone;
if (mpw_strncasecmp( mpw_nameForFormat( MPMarshalFormatFlat ), formatName, strlen( formatName ) ) == 0) if (mpw_strncasecmp( mpw_format_name( MPMarshalFormatFlat ), formatName, strlen( formatName ) ) == 0)
return MPMarshalFormatFlat; return MPMarshalFormatFlat;
if (mpw_strncasecmp( mpw_nameForFormat( MPMarshalFormatJSON ), formatName, strlen( formatName ) ) == 0) if (mpw_strncasecmp( mpw_format_name( MPMarshalFormatJSON ), formatName, strlen( formatName ) ) == 0)
return MPMarshalFormatJSON; return MPMarshalFormatJSON;
dbg( "Not a format name: %s", formatName ); dbg( "Not a format name: %s", formatName );
return (MPMarshalFormat)ERR; return (MPMarshalFormat)ERR;
} }
const char *mpw_nameForFormat( const char *mpw_format_name(
const MPMarshalFormat format) { const MPMarshalFormat format) {
switch (format) { switch (format) {

View File

@ -152,12 +152,12 @@ bool mpw_marshal_free(
/** /**
* @return The purpose represented by the given name. * @return The purpose represented by the given name.
*/ */
const MPMarshalFormat mpw_formatWithName( const MPMarshalFormat mpw_format_named(
const char *formatName); const char *formatName);
/** /**
* @return The standard name for the given purpose. * @return The standard name for the given purpose.
*/ */
const char *mpw_nameForFormat( const char *mpw_format_name(
const MPMarshalFormat format); const MPMarshalFormat format);
/** /**
* @return The file extension that's recommended for files that use the given marshalling format. * @return The file extension that's recommended for files that use the given marshalling format.

View File

@ -25,7 +25,7 @@
const size_t MPMasterKeySize = 64; const size_t MPMasterKeySize = 64;
const size_t MPSiteKeySize = 256 / 8; // Size of HMAC-SHA-256 const size_t MPSiteKeySize = 256 / 8; // Size of HMAC-SHA-256
const MPResultType mpw_typeWithName(const char *typeName) { const MPResultType mpw_type_named(const char *typeName) {
// Find what password type is represented by the type letter. // Find what password type is represented by the type letter.
if (strlen( typeName ) == 1) { if (strlen( typeName ) == 1) {
@ -54,34 +54,34 @@ const MPResultType mpw_typeWithName(const char *typeName) {
} }
// Find what password type is represented by the type name. // Find what password type is represented by the type name.
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateMaximum ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateMaximum ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateMaximum; return MPResultTypeTemplateMaximum;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateLong ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateLong ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateLong; return MPResultTypeTemplateLong;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateMedium ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateMedium ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateMedium; return MPResultTypeTemplateMedium;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateBasic ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateBasic ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateBasic; return MPResultTypeTemplateBasic;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateShort ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateShort ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateShort; return MPResultTypeTemplateShort;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplatePIN ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplatePIN ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplatePIN; return MPResultTypeTemplatePIN;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateName ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateName ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateName; return MPResultTypeTemplateName;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplatePhrase ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplatePhrase ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplatePhrase; return MPResultTypeTemplatePhrase;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeStatefulPersonal ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeStatefulPersonal ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeStatefulPersonal; return MPResultTypeStatefulPersonal;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeStatefulDevice ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeStatefulDevice ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeStatefulDevice; return MPResultTypeStatefulDevice;
if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeDeriveKey ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeDeriveKey ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeDeriveKey; return MPResultTypeDeriveKey;
dbg( "Not a generated type name: %s", typeName ); dbg( "Not a generated type name: %s", typeName );
return (MPResultType)ERR; return (MPResultType)ERR;
} }
const char *mpw_abbreviationForType(MPResultType resultType) { const char *mpw_type_abbreviation(MPResultType resultType) {
switch (resultType) { switch (resultType) {
case MPResultTypeTemplateMaximum: case MPResultTypeTemplateMaximum:
@ -113,7 +113,7 @@ const char *mpw_abbreviationForType(MPResultType resultType) {
} }
} }
const char *mpw_shortNameForType(MPResultType resultType) { const char *mpw_type_short_name(MPResultType resultType) {
switch (resultType) { switch (resultType) {
case MPResultTypeTemplateMaximum: case MPResultTypeTemplateMaximum:
@ -145,7 +145,7 @@ const char *mpw_shortNameForType(MPResultType resultType) {
} }
} }
const char *mpw_longNameForType(MPResultType resultType) { const char *mpw_type_long_name(MPResultType resultType) {
switch (resultType) { switch (resultType) {
case MPResultTypeTemplateMaximum: case MPResultTypeTemplateMaximum:
@ -177,7 +177,7 @@ const char *mpw_longNameForType(MPResultType resultType) {
} }
} }
const char **mpw_templatesForType(MPResultType type, size_t *count) { const char **mpw_type_templates(MPResultType type, size_t *count) {
if (!(type & MPResultTypeClassTemplate)) { if (!(type & MPResultTypeClassTemplate)) {
dbg( "Not a generated type: %d", type ); dbg( "Not a generated type: %d", type );
@ -222,30 +222,30 @@ const char **mpw_templatesForType(MPResultType type, size_t *count) {
} }
} }
const char *mpw_templateForType(MPResultType type, uint8_t templateIndex) { const char *mpw_type_template(MPResultType type, uint8_t templateIndex) {
size_t count = 0; size_t count = 0;
const char **templates = mpw_templatesForType( type, &count ); const char **templates = mpw_type_templates( type, &count );
char const *template = templates && count? templates[templateIndex % count]: NULL; char const *template = templates && count? templates[templateIndex % count]: NULL;
free( templates ); free( templates );
return template; return template;
} }
const MPKeyPurpose mpw_purposeWithName(const char *purposeName) { const MPKeyPurpose mpw_purpose_named(const char *purposeName) {
if (mpw_strncasecmp( mpw_nameForPurpose( MPKeyPurposeAuthentication ), purposeName, strlen( purposeName ) ) == 0) if (mpw_strncasecmp( mpw_purpose_name( MPKeyPurposeAuthentication ), purposeName, strlen( purposeName ) ) == 0)
return MPKeyPurposeAuthentication; return MPKeyPurposeAuthentication;
if (mpw_strncasecmp( mpw_nameForPurpose( MPKeyPurposeIdentification ), purposeName, strlen( purposeName ) ) == 0) if (mpw_strncasecmp( mpw_purpose_name( MPKeyPurposeIdentification ), purposeName, strlen( purposeName ) ) == 0)
return MPKeyPurposeIdentification; return MPKeyPurposeIdentification;
if (mpw_strncasecmp( mpw_nameForPurpose( MPKeyPurposeRecovery ), purposeName, strlen( purposeName ) ) == 0) if (mpw_strncasecmp( mpw_purpose_name( MPKeyPurposeRecovery ), purposeName, strlen( purposeName ) ) == 0)
return MPKeyPurposeRecovery; return MPKeyPurposeRecovery;
dbg( "Not a purpose name: %s", purposeName ); dbg( "Not a purpose name: %s", purposeName );
return (MPKeyPurpose)ERR; return (MPKeyPurpose)ERR;
} }
const char *mpw_nameForPurpose(MPKeyPurpose purpose) { const char *mpw_purpose_name(MPKeyPurpose purpose) {
switch (purpose) { switch (purpose) {
case MPKeyPurposeAuthentication: case MPKeyPurposeAuthentication:
@ -261,7 +261,7 @@ const char *mpw_nameForPurpose(MPKeyPurpose purpose) {
} }
} }
const char *mpw_scopeForPurpose(MPKeyPurpose purpose) { const char *mpw_purpose_scope(MPKeyPurpose purpose) {
switch (purpose) { switch (purpose) {
case MPKeyPurposeAuthentication: case MPKeyPurposeAuthentication:
@ -277,7 +277,7 @@ const char *mpw_scopeForPurpose(MPKeyPurpose purpose) {
} }
} }
const char *mpw_charactersInClass(char characterClass) { const char *mpw_class_characters(char characterClass) {
switch (characterClass) { switch (characterClass) {
case 'V': case 'V':
@ -307,9 +307,9 @@ const char *mpw_charactersInClass(char characterClass) {
} }
} }
const char mpw_characterFromClass(char characterClass, uint8_t seedByte) { const char mpw_class_character(char characterClass, uint8_t seedByte) {
const char *classCharacters = mpw_charactersInClass( characterClass ); const char *classCharacters = mpw_class_characters( characterClass );
if (!classCharacters) if (!classCharacters)
return '\0'; return '\0';

View File

@ -133,32 +133,32 @@ typedef struct {
/** /**
* @return The purpose represented by the given name. * @return The purpose represented by the given name.
*/ */
const MPKeyPurpose mpw_purposeWithName(const char *purposeName); const MPKeyPurpose mpw_purpose_named(const char *purposeName);
/** /**
* @return The standard name for the given purpose. * @return The standard name for the given purpose.
*/ */
const char *mpw_nameForPurpose(MPKeyPurpose purpose); const char *mpw_purpose_name(MPKeyPurpose purpose);
/** /**
* @return An internal string containing the scope identifier to apply when encoding for the given purpose. * @return An internal string containing the scope identifier to apply when encoding for the given purpose.
*/ */
const char *mpw_scopeForPurpose(MPKeyPurpose purpose); const char *mpw_purpose_scope(MPKeyPurpose purpose);
/** /**
* @return The password type represented by the given name. * @return The password type represented by the given name.
*/ */
const MPResultType mpw_typeWithName(const char *typeName); const MPResultType mpw_type_named(const char *typeName);
/** /**
* @return The standard identifying name for the given password type. * @return The standard identifying name for the given password type.
*/ */
const char *mpw_abbreviationForType(MPResultType resultType); const char *mpw_type_abbreviation(MPResultType resultType);
/** /**
* @return The standard identifying name for the given password type. * @return The standard identifying name for the given password type.
*/ */
const char *mpw_shortNameForType(MPResultType resultType); const char *mpw_type_short_name(MPResultType resultType);
/** /**
* @return The descriptive name for the given password type. * @return The descriptive name for the given password type.
*/ */
const char *mpw_longNameForType(MPResultType resultType); const char *mpw_type_long_name(MPResultType resultType);
/** /**
* @return A newly allocated array of internal strings that express the templates to use for the given type. * @return A newly allocated array of internal strings that express the templates to use for the given type.
@ -166,20 +166,20 @@ const char *mpw_longNameForType(MPResultType resultType);
* If an unsupported type is given, count will be 0 and will return NULL. * If an unsupported type is given, count will be 0 and will return NULL.
* The array needs to be free'ed, the strings themselves must not be free'ed or modified. * The array needs to be free'ed, the strings themselves must not be free'ed or modified.
*/ */
const char **mpw_templatesForType(MPResultType type, size_t *count); const char **mpw_type_templates(MPResultType type, size_t *count);
/** /**
* @return An internal string that contains the password encoding template of the given type * @return An internal string that contains the password encoding template of the given type
* for a seed that starts with the given byte. * for a seed that starts with the given byte.
*/ */
const char *mpw_templateForType(MPResultType type, uint8_t templateIndex); const char *mpw_type_template(MPResultType type, uint8_t templateIndex);
/** /**
* @return An internal string that contains all the characters that occur in the given character class. * @return An internal string that contains all the characters that occur in the given character class.
*/ */
const char *mpw_charactersInClass(char characterClass); const char *mpw_class_characters(char characterClass);
/** /**
* @return A character from given character class that encodes the given byte. * @return A character from given character class that encodes the given byte.
*/ */
const char mpw_characterFromClass(char characterClass, uint8_t seedByte); const char mpw_class_character(char characterClass, uint8_t seedByte);
#endif // _MPW_TYPES_H #endif // _MPW_TYPES_H