From 4b7350829208acbb767cc190b6e1981d8b8f9e1a Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 23 Jan 2020 15:53:55 -0500 Subject: [PATCH] Harmonize API naming. --- platform-independent/c/cli/src/mpw-bench.c | 30 ++-- platform-independent/c/cli/src/mpw-cli.c | 148 +++++++++--------- platform-independent/c/cli/src/mpw-tests.c | 8 +- .../c/core/src/mpw-algorithm.c | 74 ++++----- .../c/core/src/mpw-algorithm.h | 12 +- .../c/core/src/mpw-algorithm_v0.c | 28 ++-- .../c/core/src/mpw-algorithm_v1.c | 36 ++--- .../c/core/src/mpw-algorithm_v2.c | 34 ++-- .../c/core/src/mpw-algorithm_v3.c | 34 ++-- platform-independent/c/core/src/mpw-jni.c | 8 +- .../c/core/src/mpw-marshal-util.c | 4 +- .../c/core/src/mpw-marshal-util.h | 2 +- platform-independent/c/core/src/mpw-marshal.c | 38 ++--- platform-independent/c/core/src/mpw-marshal.h | 4 +- platform-independent/c/core/src/mpw-types.c | 54 +++---- platform-independent/c/core/src/mpw-types.h | 22 +-- 16 files changed, 268 insertions(+), 268 deletions(-) diff --git a/platform-independent/c/cli/src/mpw-bench.c b/platform-independent/c/cli/src/mpw-bench.c index a3e81d60..fd44562e 100644 --- a/platform-independent/c/cli/src/mpw-bench.c +++ b/platform-independent/c/cli/src/mpw-bench.c @@ -40,16 +40,16 @@ #define MP_r 8 #define MP_p 2 -static void mpw_getTime(struct timeval *time) { +static void mpw_time(struct timeval *time) { if (gettimeofday( time, NULL ) != 0) 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; - mpw_getTime( &endTime ); + mpw_time( &endTime ); const time_t dsec = (endTime.tv_sec - startTime.tv_sec); 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 uint8_t *sitePasswordInfo = malloc( 128 ); iterations = 4200000; /* tuned to ~10s on dev machine */ - masterKey = mpw_masterKey( fullName, masterPassword, MPAlgorithmVersionCurrent ); + masterKey = mpw_master_key( fullName, masterPassword, MPAlgorithmVersionCurrent ); if (!masterKey) { ftl( "Could not allocate master key: %s", strerror( errno ) ); abort(); } - mpw_getTime( &startTime ); + mpw_time( &startTime ); for (int i = 1; i <= iterations; ++i) { free( (void *)mpw_hash_hmac_sha256( masterKey, MPMasterKeySize, sitePasswordInfo, 128 ) ); if (modff( 100.f * i / iterations, &percent ) == 0) 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 ); // Start BCrypt // Similar to phase-one of mpw uint8_t bcrypt_rounds = 9; iterations = 170; /* tuned to ~10s on dev machine */ - mpw_getTime( &startTime ); + mpw_time( &startTime ); for (int i = 1; i <= iterations; ++i) { bcrypt( masterPassword, bcrypt_gensalt( bcrypt_rounds ) ); if (modff( 100.f * i / iterations, &percent ) == 0) 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 // Phase one of mpw iterations = 50; /* tuned to ~10s on dev machine */ - mpw_getTime( &startTime ); + mpw_time( &startTime ); 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) 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 // Both phases of mpw iterations = 50; /* tuned to ~10s on dev machine */ - mpw_getTime( &startTime ); + mpw_time( &startTime ); for (int i = 1; i <= iterations; ++i) { - masterKey = mpw_masterKey( fullName, masterPassword, MPAlgorithmVersionCurrent ); + masterKey = mpw_master_key( fullName, masterPassword, MPAlgorithmVersionCurrent ); if (!masterKey) { ftl( "Could not allocate master key: %s", strerror( errno ) ); break; } - free( (void *)mpw_siteResult( + free( (void *)mpw_site_result( masterKey, siteName, siteCounter, keyPurpose, keyContext, resultType, NULL, MPAlgorithmVersionCurrent ) ); free( (void *)masterKey ); if (modff( 100.f * i / iterations, &percent ) == 0) 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. fprintf( stdout, "\n== SUMMARY ==\nOn this machine,\n" ); diff --git a/platform-independent/c/cli/src/mpw-cli.c b/platform-independent/c/cli/src/mpw-cli.c index d379cff3..07693649 100644 --- a/platform-independent/c/cli/src/mpw-cli.c +++ b/platform-independent/c/cli/src/mpw-cli.c @@ -35,90 +35,90 @@ static void usage() { inf( "" - " Master Password v%s - CLI\n" - "--------------------------------------------------------------------------------\n" - " https://masterpassword.app\n", stringify_def( MP_VERSION ) ); + " Master Password v%s - CLI\n" + "--------------------------------------------------------------------------------\n" + " https://masterpassword.app\n", stringify_def( MP_VERSION ) ); inf( "" - "\nUSAGE\n\n" - " mpw [-u|-U full-name] [-m fd] [-t pw-type] [-P value] [-c counter]\n" - " [-a version] [-p purpose] [-C context] [-f|F format] [-R 0|1]\n" - " [-v|-q]* [-h] [site-name]\n" ); + "\nUSAGE\n\n" + " mpw [-u|-U full-name] [-m fd] [-t pw-type] [-P value] [-c counter]\n" + " [-a version] [-p purpose] [-C context] [-f|F format] [-R 0|1]\n" + " [-v|-q]* [-h] [site-name]\n" ); inf( "" - " -u full-name Specify the full name of the user.\n" - " -u checks the master password against the config,\n" - " -U allows updating to a new master password.\n" - " Defaults to %s in env or prompts.\n", MP_ENV_fullName ); + " -u full-name Specify the full name of the user.\n" + " -u checks the master password against the config,\n" + " -U allows updating to a new master password.\n" + " Defaults to %s in env or prompts.\n", MP_ENV_fullName ); dbg( "" - " -M master-pw Specify the master password of the user.\n" - " Passing secrets as arguments is unsafe, for use in testing only." ); + " -M master-pw Specify the master password of the user.\n" + " Passing secrets as arguments is unsafe, for use in testing only." ); inf( "" - " -m fd Read the master password of the user from a file descriptor.\n" - " Tip: don't send extra characters like newlines such as by using\n" - " echo in a pipe. Consider printf instead.\n" ); + " -m fd Read the master password of the user from a file descriptor.\n" + " Tip: don't send extra characters like newlines such as by using\n" + " echo in a pipe. Consider printf instead.\n" ); inf( "" - " -t pw-type Specify the password's template.\n" - " Defaults to 'long' (-p a), 'name' (-p i) or 'phrase' (-p r).\n" - " x, maximum | 20 characters, contains symbols.\n" - " l, long | Copy-friendly, 14 characters, symbols.\n" - " m, medium | Copy-friendly, 8 characters, symbols.\n" - " b, basic | 8 characters, no symbols.\n" - " s, short | Copy-friendly, 4 characters, no symbols.\n" - " i, pin | 4 numbers.\n" - " n, name | 9 letter name.\n" - " p, phrase | 20 character sentence.\n" - " K, key | encryption key (512 bit or -P bits).\n" - " P, personal | saved personal password (save with -P pw).\n" ); + " -t pw-type Specify the password's template.\n" + " Defaults to 'long' (-p a), 'name' (-p i) or 'phrase' (-p r).\n" + " x, maximum | 20 characters, contains symbols.\n" + " l, long | Copy-friendly, 14 characters, symbols.\n" + " m, medium | Copy-friendly, 8 characters, symbols.\n" + " b, basic | 8 characters, no symbols.\n" + " s, short | Copy-friendly, 4 characters, no symbols.\n" + " i, pin | 4 numbers.\n" + " n, name | 9 letter name.\n" + " p, phrase | 20 character sentence.\n" + " K, key | encryption key (512 bit or -P bits).\n" + " P, personal | saved personal password (save with -P pw).\n" ); inf( "" - " -P value The parameter value.\n" - " -p i | The login name for the site.\n" - " -t K | The bit size of the key to generate (eg. 256).\n" - " -t P | The personal password to encrypt.\n" ); + " -P value The parameter value.\n" + " -p i | The login name for the site.\n" + " -t K | The bit size of the key to generate (eg. 256).\n" + " -t P | The personal password to encrypt.\n" ); inf( "" - " -c counter The value of the counter.\n" - " Defaults to 1.\n" ); + " -c counter The value of the counter.\n" + " Defaults to 1.\n" ); inf( "" - " -a version The algorithm version to use, %d - %d.\n" - " Defaults to env var %s or %d.\n", + " -a version The algorithm version to use, %d - %d.\n" + " Defaults to env var %s or %d.\n", MPAlgorithmVersionFirst, MPAlgorithmVersionLast, MP_ENV_algorithm, MPAlgorithmVersionCurrent ); inf( "" - " -p purpose The purpose of the generated token.\n" - " Defaults to 'auth'.\n" - " a, auth | An authentication token such as a password.\n" - " i, ident | An identification token such as a username.\n" - " r, rec | A recovery token such as a security answer.\n" ); + " -p purpose The purpose of the generated token.\n" + " Defaults to 'auth'.\n" + " a, auth | An authentication token such as a password.\n" + " i, ident | An identification token such as a username.\n" + " r, rec | A recovery token such as a security answer.\n" ); inf( "" - " -C context A purpose-specific context.\n" - " Defaults to empty.\n" - " -p a | -\n" - " -p i | -\n" - " -p r | Most significant word in security question.\n" ); + " -C context A purpose-specific context.\n" + " Defaults to empty.\n" + " -p a | -\n" + " -p i | -\n" + " -p r | Most significant word in security question.\n" ); inf( "" - " -f|F format The mpsites format to use for reading/writing site parameters.\n" - " -F forces the use of the given format,\n" - " -f allows fallback/migration.\n" - " Defaults to env var %s or json, falls back to plain.\n" - " n, none | No file\n" - " f, flat | ~/.mpw.d/Full Name.%s\n" - " j, json | ~/.mpw.d/Full Name.%s\n", + " -f|F format The mpsites format to use for reading/writing site parameters.\n" + " -F forces the use of the given format,\n" + " -f allows fallback/migration.\n" + " Defaults to env var %s or json, falls back to plain.\n" + " n, none | No file\n" + " f, flat | ~/.mpw.d/Full Name.%s\n" + " j, json | ~/.mpw.d/Full Name.%s\n", MP_ENV_format, mpw_marshal_format_extension( MPMarshalFormatFlat ), mpw_marshal_format_extension( MPMarshalFormatJSON ) ); inf( "" - " -R redacted Whether to save the mpsites in redacted format or not.\n" - " Redaction omits or encrypts any secrets, making the file safe\n" - " for saving on or transmitting via untrusted media.\n" - " Defaults to 1, redacted.\n" ); + " -R redacted Whether to save the mpsites in redacted format or not.\n" + " Redaction omits or encrypts any secrets, making the file safe\n" + " for saving on or transmitting via untrusted media.\n" + " Defaults to 1, redacted.\n" ); inf( "" - " -v Increase output verbosity (can be repeated).\n" - " -q Decrease output verbosity (can be repeated).\n" ); + " -v Increase output verbosity (can be repeated).\n" + " -q Decrease output verbosity (can be repeated).\n" ); inf( "" - " -h Show this help output instead of performing any operation.\n" ); + " -h Show this help output instead of performing any operation.\n" ); inf( "" - " site-name Name of the site for which to generate a token.\n" ); + " site-name Name of the site for which to generate a token.\n" ); inf( "" - "\nENVIRONMENT\n\n" - " %-12s The full name of the user (see -u).\n" - " %-12s The default algorithm version (see -a).\n" - " %-12s The default mpsites format (see -f).\n" - " %-12s The askpass program to use for prompting the user.\n", + "\nENVIRONMENT\n\n" + " %-12s The full name of the user (see -u).\n" + " %-12s The default algorithm version (see -a).\n" + " %-12s The default mpsites format (see -f).\n" + " %-12s The askpass program to use for prompting the user.\n", MP_ENV_fullName, MP_ENV_algorithm, MP_ENV_format, MP_ENV_askpass ); exit( EX_OK ); } @@ -236,15 +236,15 @@ int main(const int argc, char *const argv[]) { if (operation.user) { dbg( "fullName : %s", operation.user->fullName ); 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 ); } if (operation.site) { dbg( "siteName : %s", operation.site->name ); 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( "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( "algorithmVersion : %u", operation.site->algorithm ); } @@ -426,7 +426,7 @@ void cli_sitesFormat(Arguments *args, Operation *operation) { if (!args->sitesFormat) return; - operation->sitesFormat = mpw_formatWithName( args->sitesFormat ); + operation->sitesFormat = mpw_format_named( args->sitesFormat ); if (ERR == (int)operation->sitesFormat) { ftl( "Invalid sites format: %s", args->sitesFormat ); cli_free( args, operation ); @@ -439,7 +439,7 @@ void cli_keyPurpose(Arguments *args, Operation *operation) { if (!args->keyPurpose) return; - operation->keyPurpose = mpw_purposeWithName( args->keyPurpose ); + operation->keyPurpose = mpw_purpose_named( args->keyPurpose ); if (ERR == (int)operation->keyPurpose) { ftl( "Invalid purpose: %s", args->keyPurpose ); cli_free( args, operation ); @@ -625,7 +625,7 @@ void cli_resultType(Arguments *args, Operation *operation) { if (!operation->site) abort(); - operation->resultType = mpw_typeWithName( args->resultType ); + operation->resultType = mpw_type_named( args->resultType ); if (ERR == (int)operation->resultType) { ftl( "Invalid type: %s", args->resultType ); cli_free( args, operation ); @@ -726,7 +726,7 @@ void cli_mpw(Arguments *args, Operation *operation) { // Update state from resultParam if stateful. if (operation->resultParam && operation->resultType & MPResultTypeClassStateful) { 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->site->algorithm ))) { ftl( "Couldn't encrypt site result." ); @@ -764,7 +764,7 @@ void cli_mpw(Arguments *args, Operation *operation) { operation->resultParam = mpw_strdup( operation->resultState ); // 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 ); mpw_free( &masterKey, MPMasterKeySize ); if (!result) { diff --git a/platform-independent/c/cli/src/mpw-tests.c b/platform-independent/c/cli/src/mpw-tests.c index 6dbda3bc..4162a03a 100644 --- a/platform-independent/c/cli/src/mpw-tests.c +++ b/platform-independent/c/cli/src/mpw-tests.c @@ -104,8 +104,8 @@ int main(int argc, char *const argv[]) { xmlChar *keyContext = mpw_xmlTestCaseString( testCase, "keyContext" ); xmlChar *result = mpw_xmlTestCaseString( testCase, "result" ); - MPResultType resultType = mpw_typeWithName( (char *)resultTypeString ); - MPKeyPurpose keyPurpose = mpw_purposeWithName( (char *)keyPurposeString ); + MPResultType resultType = mpw_type_named( (char *)resultTypeString ); + MPKeyPurpose keyPurpose = mpw_purpose_named( (char *)keyPurposeString ); // Run the test case. do { @@ -125,7 +125,7 @@ int main(int argc, char *const argv[]) { } // 1. calculate the master key. - MPMasterKey masterKey = mpw_masterKey( + MPMasterKey masterKey = mpw_master_key( (char *)fullName, (char *)masterPassword, algorithm ); if (!masterKey) { ftl( "Couldn't derive master key." ); @@ -141,7 +141,7 @@ int main(int argc, char *const argv[]) { } // 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 ); mpw_free( &masterKey, MPMasterKeySize ); if (!testResult) { diff --git a/platform-independent/c/core/src/mpw-algorithm.c b/platform-independent/c/core/src/mpw-algorithm.c index a0c87dcf..234c225f 100644 --- a/platform-independent/c/core/src/mpw-algorithm.c +++ b/platform-independent/c/core/src/mpw-algorithm.c @@ -22,14 +22,14 @@ #include "mpw-algorithm_v2.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 )) fullName = NULL; if (masterPassword && !strlen( masterPassword )) masterPassword = NULL; - trc( "-- mpw_masterKey (algorithm: %u)", algorithmVersion ); + trc( "-- mpw_master_key (algorithm: %u)", algorithmVersion ); trc( "fullName: %s", fullName ); trc( "masterPassword.id: %s", masterPassword? mpw_id_buf( masterPassword, strlen( masterPassword ) ): NULL ); if (!fullName || !masterPassword) @@ -37,50 +37,50 @@ MPMasterKey mpw_masterKey(const char *fullName, const char *masterPassword, cons switch (algorithmVersion) { case MPAlgorithmVersion0: - return mpw_masterKey_v0( fullName, masterPassword ); + return mpw_master_key_v0( fullName, masterPassword ); case MPAlgorithmVersion1: - return mpw_masterKey_v1( fullName, masterPassword ); + return mpw_master_key_v1( fullName, masterPassword ); case MPAlgorithmVersion2: - return mpw_masterKey_v2( fullName, masterPassword ); + return mpw_master_key_v2( fullName, masterPassword ); case MPAlgorithmVersion3: - return mpw_masterKey_v3( fullName, masterPassword ); + return mpw_master_key_v3( fullName, masterPassword ); default: err( "Unsupported version: %d", algorithmVersion ); return NULL; } } -MPSiteKey mpw_siteKey( +MPSiteKey mpw_site_key( MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, const MPKeyPurpose keyPurpose, const char *keyContext, const MPAlgorithmVersion algorithmVersion) { if (keyContext && !strlen( keyContext )) keyContext = NULL; - trc( "-- mpw_siteKey (algorithm: %u)", algorithmVersion ); + trc( "-- mpw_site_key (algorithm: %u)", algorithmVersion ); trc( "siteName: %s", siteName ); 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 ); if (!masterKey || !siteName) return NULL; switch (algorithmVersion) { case MPAlgorithmVersion0: - return mpw_siteKey_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext ); + return mpw_site_key_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext ); case MPAlgorithmVersion1: - return mpw_siteKey_v1( masterKey, siteName, siteCounter, keyPurpose, keyContext ); + return mpw_site_key_v1( masterKey, siteName, siteCounter, keyPurpose, keyContext ); case MPAlgorithmVersion2: - return mpw_siteKey_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext ); + return mpw_site_key_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext ); case MPAlgorithmVersion3: - return mpw_siteKey_v3( masterKey, siteName, siteCounter, keyPurpose, keyContext ); + return mpw_site_key_v3( masterKey, siteName, siteCounter, keyPurpose, keyContext ); default: err( "Unsupported version: %d", algorithmVersion ); return NULL; } } -const char *mpw_siteResult( +const char *mpw_site_result( MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, const MPKeyPurpose keyPurpose, const char *keyContext, const MPResultType resultType, const char *resultParam, @@ -91,25 +91,25 @@ const char *mpw_siteResult( if (resultParam && !strlen( resultParam )) 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) return NULL; - trc( "-- mpw_siteResult (algorithm: %u)", algorithmVersion ); - trc( "resultType: %d (%s)", resultType, mpw_shortNameForType( resultType ) ); + trc( "-- mpw_site_result (algorithm: %u)", algorithmVersion ); + trc( "resultType: %d (%s)", resultType, mpw_type_short_name( resultType ) ); trc( "resultParam: %s", resultParam ); char *sitePassword = NULL; if (resultType & MPResultTypeClassTemplate) { switch (algorithmVersion) { case MPAlgorithmVersion0: - return mpw_sitePasswordFromTemplate_v0( masterKey, siteKey, resultType, resultParam ); + return mpw_site_template_password_v0( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion1: - return mpw_sitePasswordFromTemplate_v1( masterKey, siteKey, resultType, resultParam ); + return mpw_site_template_password_v1( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion2: - return mpw_sitePasswordFromTemplate_v2( masterKey, siteKey, resultType, resultParam ); + return mpw_site_template_password_v2( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion3: - return mpw_sitePasswordFromTemplate_v3( masterKey, siteKey, resultType, resultParam ); + return mpw_site_template_password_v3( masterKey, siteKey, resultType, resultParam ); default: err( "Unsupported version: %d", algorithmVersion ); return NULL; @@ -118,13 +118,13 @@ const char *mpw_siteResult( else if (resultType & MPResultTypeClassStateful) { switch (algorithmVersion) { case MPAlgorithmVersion0: - return mpw_sitePasswordFromCrypt_v0( masterKey, siteKey, resultType, resultParam ); + return mpw_site_crypted_password_v0( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion1: - return mpw_sitePasswordFromCrypt_v1( masterKey, siteKey, resultType, resultParam ); + return mpw_site_crypted_password_v1( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion2: - return mpw_sitePasswordFromCrypt_v2( masterKey, siteKey, resultType, resultParam ); + return mpw_site_crypted_password_v2( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion3: - return mpw_sitePasswordFromCrypt_v3( masterKey, siteKey, resultType, resultParam ); + return mpw_site_crypted_password_v3( masterKey, siteKey, resultType, resultParam ); default: err( "Unsupported version: %d", algorithmVersion ); return NULL; @@ -133,13 +133,13 @@ const char *mpw_siteResult( else if (resultType & MPResultTypeClassDerive) { switch (algorithmVersion) { case MPAlgorithmVersion0: - return mpw_sitePasswordFromDerive_v0( masterKey, siteKey, resultType, resultParam ); + return mpw_site_derived_password_v0( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion1: - return mpw_sitePasswordFromDerive_v1( masterKey, siteKey, resultType, resultParam ); + return mpw_site_derived_password_v1( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion2: - return mpw_sitePasswordFromDerive_v2( masterKey, siteKey, resultType, resultParam ); + return mpw_site_derived_password_v2( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion3: - return mpw_sitePasswordFromDerive_v3( masterKey, siteKey, resultType, resultParam ); + return mpw_site_derived_password_v3( masterKey, siteKey, resultType, resultParam ); default: err( "Unsupported version: %d", algorithmVersion ); return NULL; @@ -152,7 +152,7 @@ const char *mpw_siteResult( return sitePassword; } -const char *mpw_siteState( +const char *mpw_site_state( MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, const MPKeyPurpose keyPurpose, const char *keyContext, const MPResultType resultType, const char *resultParam, @@ -163,25 +163,25 @@ const char *mpw_siteState( if (resultParam && !strlen( resultParam )) 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) return NULL; - trc( "-- mpw_siteState (algorithm: %u)", algorithmVersion ); - trc( "resultType: %d (%s)", resultType, mpw_shortNameForType( resultType ) ); + trc( "-- mpw_site_state (algorithm: %u)", algorithmVersion ); + trc( "resultType: %d (%s)", resultType, mpw_type_short_name( resultType ) ); trc( "resultParam: %zu bytes = %s", sizeof( resultParam ), resultParam ); if (!masterKey || !resultParam) return NULL; switch (algorithmVersion) { case MPAlgorithmVersion0: - return mpw_siteState_v0( masterKey, siteKey, resultType, resultParam ); + return mpw_site_state_v0( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion1: - return mpw_siteState_v1( masterKey, siteKey, resultType, resultParam ); + return mpw_site_state_v1( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion2: - return mpw_siteState_v2( masterKey, siteKey, resultType, resultParam ); + return mpw_site_state_v2( masterKey, siteKey, resultType, resultParam ); case MPAlgorithmVersion3: - return mpw_siteState_v3( masterKey, siteKey, resultType, resultParam ); + return mpw_site_state_v3( masterKey, siteKey, resultType, resultParam ); default: err( "Unsupported version: %d", algorithmVersion ); return NULL; diff --git a/platform-independent/c/core/src/mpw-algorithm.h b/platform-independent/c/core/src/mpw-algorithm.h index 3cf8d702..58bb2f2a 100644 --- a/platform-independent/c/core/src/mpw-algorithm.h +++ b/platform-independent/c/core/src/mpw-algorithm.h @@ -39,28 +39,28 @@ typedef mpw_enum( unsigned int, MPAlgorithmVersion ) { /** 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. */ -MPMasterKey mpw_masterKey( +MPMasterKey mpw_master_key( 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. * @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, const MPKeyPurpose keyPurpose, const char *keyContext, const MPAlgorithmVersion algorithmVersion); /** 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. */ -const char *mpw_siteResult( +const char *mpw_site_result( MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, const MPKeyPurpose keyPurpose, const char *keyContext, const MPResultType resultType, const char *resultParam, const MPAlgorithmVersion algorithmVersion); /** 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. */ -const char *mpw_siteState( +const char *mpw_site_state( MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, const MPKeyPurpose keyPurpose, const char *keyContext, const MPResultType resultType, const char *resultParam, diff --git a/platform-independent/c/core/src/mpw-algorithm_v0.c b/platform-independent/c/core/src/mpw-algorithm_v0.c index 26817d2f..574ba4cd 100644 --- a/platform-independent/c/core/src/mpw-algorithm_v0.c +++ b/platform-independent/c/core/src/mpw-algorithm_v0.c @@ -29,18 +29,18 @@ #define MP_otp_window 5 * 60 /* s */ // 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; - const char **templates = mpw_templatesForType( type, &count ); + const char **templates = mpw_type_templates( type, &count ); char const *template = templates && count? templates[templateIndex % count]: NULL; free( templates ); 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) return '\0'; @@ -48,10 +48,10 @@ static const char mpw_characterFromClass_v0(char characterClass, uint16_t classI } // Algorithm version overrides. -static MPMasterKey mpw_masterKey_v0( +static MPMasterKey mpw_master_key_v0( const char *fullName, const char *masterPassword) { - const char *keyScope = mpw_scopeForPurpose( MPKeyPurposeAuthentication ); + const char *keyScope = mpw_purpose_scope( MPKeyPurposeAuthentication ); trc( "keyScope: %s", keyScope ); // Calculate the master key salt. @@ -82,11 +82,11 @@ static MPMasterKey mpw_masterKey_v0( return masterKey; } -static MPSiteKey mpw_siteKey_v0( +static MPSiteKey mpw_site_key_v0( MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, MPKeyPurpose keyPurpose, const char *keyContext) { - const char *keyScope = mpw_scopeForPurpose( keyPurpose ); + const char *keyScope = mpw_purpose_scope( keyPurpose ); trc( "keyScope: %s", keyScope ); // OTP counter value. @@ -126,7 +126,7 @@ static MPSiteKey mpw_siteKey_v0( 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) { const char *_siteKey = (const char *)siteKey; @@ -134,7 +134,7 @@ static const char *mpw_sitePasswordFromTemplate_v0( // Determine the template. uint16_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 ); if (!template) return NULL; @@ -147,7 +147,7 @@ static const char *mpw_sitePasswordFromTemplate_v0( char *const sitePassword = calloc( strlen( template ) + 1, sizeof( char ) ); for (size_t c = 0; c < strlen( template ); ++c) { 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", template[c], seedByte, seedByte, sitePassword[c] ); } @@ -156,7 +156,7 @@ static const char *mpw_sitePasswordFromTemplate_v0( 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) { if (!cipherText) { @@ -186,7 +186,7 @@ static const char *mpw_sitePasswordFromCrypt_v0( 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) { 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) { // Encrypt diff --git a/platform-independent/c/core/src/mpw-algorithm_v1.c b/platform-independent/c/core/src/mpw-algorithm_v1.c index de683a4d..62553559 100644 --- a/platform-independent/c/core/src/mpw-algorithm_v1.c +++ b/platform-independent/c/core/src/mpw-algorithm_v1.c @@ -26,38 +26,38 @@ #define MP_otp_window 5 * 60 /* s */ // Inherited functions. -MPMasterKey mpw_masterKey_v0( +MPMasterKey mpw_master_key_v0( const char *fullName, const char *masterPassword); -MPSiteKey mpw_siteKey_v0( +MPSiteKey mpw_site_key_v0( MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, 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); -const char *mpw_sitePasswordFromDerive_v0( +const char *mpw_site_derived_password_v0( 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); // Algorithm version overrides. -static MPMasterKey mpw_masterKey_v1( +static MPMasterKey mpw_master_key_v1( 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, 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) { // Determine the template. 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 ); if (!template) return NULL; @@ -70,7 +70,7 @@ static const char *mpw_sitePasswordFromTemplate_v1( char *const sitePassword = calloc( strlen( template ) + 1, sizeof( char ) ); for (size_t c = 0; c < strlen( template ); ++c) { 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", template[c], seedByte, seedByte, sitePassword[c] ); } @@ -79,20 +79,20 @@ static const char *mpw_sitePasswordFromTemplate_v1( 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) { - 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) { - 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) { - return mpw_siteState_v0( masterKey, siteKey, resultType, state ); + return mpw_site_state_v0( masterKey, siteKey, resultType, state ); } diff --git a/platform-independent/c/core/src/mpw-algorithm_v2.c b/platform-independent/c/core/src/mpw-algorithm_v2.c index a6b3d44f..6cf519ea 100644 --- a/platform-independent/c/core/src/mpw-algorithm_v2.c +++ b/platform-independent/c/core/src/mpw-algorithm_v2.c @@ -28,29 +28,29 @@ #define MP_otp_window 5 * 60 /* s */ // Inherited functions. -MPMasterKey mpw_masterKey_v1( +MPMasterKey mpw_master_key_v1( 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); -const char *mpw_sitePasswordFromCrypt_v1( +const char *mpw_site_crypted_password_v1( 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); -const char *mpw_siteState_v1( +const char *mpw_site_state_v1( MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state); // Algorithm version overrides. -static MPMasterKey mpw_masterKey_v2( +static MPMasterKey mpw_master_key_v2( 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, MPKeyPurpose keyPurpose, const char *keyContext) { - const char *keyScope = mpw_scopeForPurpose( keyPurpose ); + const char *keyScope = mpw_purpose_scope( keyPurpose ); trc( "keyScope: %s", keyScope ); // OTP counter value. @@ -90,26 +90,26 @@ static MPSiteKey mpw_siteKey_v2( 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) { - 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) { - 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) { - 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) { - return mpw_siteState_v1( masterKey, siteKey, resultType, state ); + return mpw_site_state_v1( masterKey, siteKey, resultType, state ); } diff --git a/platform-independent/c/core/src/mpw-algorithm_v3.c b/platform-independent/c/core/src/mpw-algorithm_v3.c index 8dfb2992..1afea1d5 100644 --- a/platform-independent/c/core/src/mpw-algorithm_v3.c +++ b/platform-independent/c/core/src/mpw-algorithm_v3.c @@ -27,23 +27,23 @@ #define MP_otp_window 5 * 60 /* s */ // Inherited functions. -MPSiteKey mpw_siteKey_v2( +MPSiteKey mpw_site_key_v2( MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, 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); -const char *mpw_sitePasswordFromCrypt_v2( +const char *mpw_site_crypted_password_v2( 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); -const char *mpw_siteState_v2( +const char *mpw_site_state_v2( MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state); // Algorithm version overrides. -static MPMasterKey mpw_masterKey_v3( +static MPMasterKey mpw_master_key_v3( const char *fullName, const char *masterPassword) { - const char *keyScope = mpw_scopeForPurpose( MPKeyPurposeAuthentication ); + const char *keyScope = mpw_purpose_scope( MPKeyPurposeAuthentication ); trc( "keyScope: %s", keyScope ); // Calculate the master key salt. @@ -74,33 +74,33 @@ static MPMasterKey mpw_masterKey_v3( return masterKey; } -static MPSiteKey mpw_siteKey_v3( +static MPSiteKey mpw_site_key_v3( MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, 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) { - 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) { - 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) { - 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) { - return mpw_siteState_v2( masterKey, siteKey, resultType, state ); + return mpw_site_state_v2( masterKey, siteKey, resultType, state ); } diff --git a/platform-independent/c/core/src/mpw-jni.c b/platform-independent/c/core/src/mpw-jni.c index 33a72f73..05774d44 100644 --- a/platform-independent/c/core/src/mpw-jni.c +++ b/platform-independent/c/core/src/mpw-jni.c @@ -25,7 +25,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__ const char *fullNameString = (*env)->GetStringUTFChars( env, fullName, 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)->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 ); const char *siteNameString = (*env)->GetStringUTFChars( env, siteName, 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, (MPKeyPurpose)keyPurpose, keyContextString, (MPAlgorithmVersion)algorithmVersion ); (*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 *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, 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, (MPKeyPurpose)keyPurpose, keyContextString, (MPResultType)resultType, resultParamString, (MPAlgorithmVersion)algorithmVersion ); (*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 *keyContextString = keyContext? (*env)->GetStringUTFChars( env, keyContext, NULL ): 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, (MPKeyPurpose)keyPurpose, keyContextString, (MPResultType)resultType, resultParamString, (MPAlgorithmVersion)algorithmVersion ); (*env)->ReleaseByteArrayElements( env, masterKey, masterKeyBytes, JNI_ABORT ); diff --git a/platform-independent/c/core/src/mpw-marshal-util.c b/platform-independent/c/core/src/mpw-marshal-util.c index ab67a26e..6d369da8 100644 --- a/platform-independent/c/core/src/mpw-marshal-util.c +++ b/platform-independent/c/core/src/mpw-marshal-util.c @@ -103,13 +103,13 @@ bool mpw_get_json_boolean( } #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) { if (masterKey && (!*masterKey || *masterKeyAlgorithm != targetKeyAlgorithm)) { mpw_free( masterKey, MPMasterKeySize ); *masterKeyAlgorithm = targetKeyAlgorithm; - *masterKey = mpw_masterKey( fullName, masterPassword, *masterKeyAlgorithm ); + *masterKey = mpw_master_key( fullName, masterPassword, *masterKeyAlgorithm ); if (!*masterKey) { err( "Couldn't derive master key for user %s, algorithm %d.", fullName, *masterKeyAlgorithm ); return false; diff --git a/platform-independent/c/core/src/mpw-marshal-util.h b/platform-independent/c/core/src/mpw-marshal-util.h index a4db76b6..3567e6fe 100644 --- a/platform-independent/c/core/src/mpw-marshal-util.h +++ b/platform-independent/c/core/src/mpw-marshal-util.h @@ -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. * @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, const char *fullName, const char *masterPassword); diff --git a/platform-independent/c/core/src/mpw-marshal.c b/platform-independent/c/core/src/mpw-marshal.c index 743204cd..4b11f2a0 100644 --- a/platform-independent/c/core/src/mpw-marshal.c +++ b/platform-independent/c/core/src/mpw-marshal.c @@ -186,9 +186,9 @@ static bool mpw_marshal_write_flat( 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 ); - loginState = mpw_siteResult( masterKey, site->name, MPCounterValueInitial, + loginState = mpw_site_result( masterKey, site->name, MPCounterValueInitial, MPKeyPurposeIdentification, NULL, site->loginType, site->loginState, site->algorithm ); } else { @@ -269,9 +269,9 @@ static bool mpw_marshal_write_json( 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 ); - loginState = mpw_siteResult( masterKey, site->name, MPCounterValueInitial, + loginState = mpw_site_result( masterKey, site->name, MPCounterValueInitial, MPKeyPurposeIdentification, NULL, site->loginType, site->loginState, site->algorithm ); } else { @@ -311,7 +311,7 @@ static bool mpw_marshal_write_json( if (!user->redacted) { // 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 ); 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 ); if (strcmp( headerName, "Default Type" ) == 0) { 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 ) }; return NULL; } @@ -561,7 +561,7 @@ static MPMarshalledUser *mpw_marshal_read_flat( if (siteName && str_type && str_counter && str_algorithm && str_uses && str_lastUsed) { 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 ) }; return NULL; } @@ -601,10 +601,10 @@ static MPMarshalledUser *mpw_marshal_read_flat( } 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 ); 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 ); } else { @@ -703,7 +703,7 @@ static MPMarshalledUser *mpw_marshal_read_json( } MPAlgorithmVersion algorithm = (MPAlgorithmVersion)value; 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 ) }; return NULL; } @@ -745,7 +745,7 @@ static MPMarshalledUser *mpw_marshal_read_json( } MPAlgorithmVersion siteAlgorithm = (MPAlgorithmVersion)value; 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 ) }; return NULL; } @@ -788,10 +788,10 @@ static MPMarshalledUser *mpw_marshal_read_json( } 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 ); 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 ); } else { @@ -813,7 +813,7 @@ static MPMarshalledUser *mpw_marshal_read_json( if (!user->redacted) { // Clear Text 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 ); } else { @@ -874,24 +874,24 @@ MPMarshalledUser *mpw_marshal_read( } } -const MPMarshalFormat mpw_formatWithName( +const MPMarshalFormat mpw_format_named( const char *formatName) { if (!formatName || !strlen( formatName )) 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; - if (mpw_strncasecmp( mpw_nameForFormat( MPMarshalFormatFlat ), formatName, strlen( formatName ) ) == 0) + if (mpw_strncasecmp( mpw_format_name( MPMarshalFormatFlat ), formatName, strlen( formatName ) ) == 0) 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; dbg( "Not a format name: %s", formatName ); return (MPMarshalFormat)ERR; } -const char *mpw_nameForFormat( +const char *mpw_format_name( const MPMarshalFormat format) { switch (format) { diff --git a/platform-independent/c/core/src/mpw-marshal.h b/platform-independent/c/core/src/mpw-marshal.h index f4f3a45e..cc8c2700 100644 --- a/platform-independent/c/core/src/mpw-marshal.h +++ b/platform-independent/c/core/src/mpw-marshal.h @@ -152,12 +152,12 @@ bool mpw_marshal_free( /** * @return The purpose represented by the given name. */ -const MPMarshalFormat mpw_formatWithName( +const MPMarshalFormat mpw_format_named( const char *formatName); /** * @return The standard name for the given purpose. */ -const char *mpw_nameForFormat( +const char *mpw_format_name( const MPMarshalFormat format); /** * @return The file extension that's recommended for files that use the given marshalling format. diff --git a/platform-independent/c/core/src/mpw-types.c b/platform-independent/c/core/src/mpw-types.c index 07e9ced3..7a21ea5a 100644 --- a/platform-independent/c/core/src/mpw-types.c +++ b/platform-independent/c/core/src/mpw-types.c @@ -25,7 +25,7 @@ const size_t MPMasterKeySize = 64; 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. 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. - if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateMaximum ), typeName, strlen( typeName ) ) == 0) + if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateMaximum ), typeName, strlen( typeName ) ) == 0) 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; - if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateMedium ), typeName, strlen( typeName ) ) == 0) + if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateMedium ), typeName, strlen( typeName ) ) == 0) 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; - if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateShort ), typeName, strlen( typeName ) ) == 0) + if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateShort ), typeName, strlen( typeName ) ) == 0) 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; - if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateName ), typeName, strlen( typeName ) ) == 0) + if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeTemplateName ), typeName, strlen( typeName ) ) == 0) 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; - if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeStatefulPersonal ), typeName, strlen( typeName ) ) == 0) + if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeStatefulPersonal ), typeName, strlen( typeName ) ) == 0) 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; - if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeDeriveKey ), typeName, strlen( typeName ) ) == 0) + if (mpw_strncasecmp( mpw_type_short_name( MPResultTypeDeriveKey ), typeName, strlen( typeName ) ) == 0) return MPResultTypeDeriveKey; dbg( "Not a generated type name: %s", typeName ); return (MPResultType)ERR; } -const char *mpw_abbreviationForType(MPResultType resultType) { +const char *mpw_type_abbreviation(MPResultType resultType) { switch (resultType) { 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) { 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) { 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)) { 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; - const char **templates = mpw_templatesForType( type, &count ); + const char **templates = mpw_type_templates( type, &count ); char const *template = templates && count? templates[templateIndex % count]: NULL; free( templates ); 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; - if (mpw_strncasecmp( mpw_nameForPurpose( MPKeyPurposeIdentification ), purposeName, strlen( purposeName ) ) == 0) + if (mpw_strncasecmp( mpw_purpose_name( MPKeyPurposeIdentification ), purposeName, strlen( purposeName ) ) == 0) 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; dbg( "Not a purpose name: %s", purposeName ); return (MPKeyPurpose)ERR; } -const char *mpw_nameForPurpose(MPKeyPurpose purpose) { +const char *mpw_purpose_name(MPKeyPurpose purpose) { switch (purpose) { 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) { 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) { 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) return '\0'; diff --git a/platform-independent/c/core/src/mpw-types.h b/platform-independent/c/core/src/mpw-types.h index ed67f593..a05c1898 100644 --- a/platform-independent/c/core/src/mpw-types.h +++ b/platform-independent/c/core/src/mpw-types.h @@ -133,32 +133,32 @@ typedef struct { /** * @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. */ -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. */ -const char *mpw_scopeForPurpose(MPKeyPurpose purpose); +const char *mpw_purpose_scope(MPKeyPurpose purpose); /** * @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. */ -const char *mpw_abbreviationForType(MPResultType resultType); +const char *mpw_type_abbreviation(MPResultType resultType); /** * @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. */ -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. @@ -166,20 +166,20 @@ const char *mpw_longNameForType(MPResultType resultType); * 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. */ -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 * 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. */ -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. */ -const char mpw_characterFromClass(char characterClass, uint8_t seedByte); +const char mpw_class_character(char characterClass, uint8_t seedByte); #endif // _MPW_TYPES_H