Harmonize API naming.
This commit is contained in:
@@ -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;
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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 );
|
||||
}
|
||||
|
@@ -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 );
|
||||
}
|
||||
|
@@ -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 );
|
||||
}
|
||||
|
@@ -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 );
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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.
|
||||
|
@@ -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';
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user