2
0

More standard way to separate algorithm versions.

This commit is contained in:
Maarten Billemont
2019-09-27 22:38:32 -04:00
parent ff9a5eaf04
commit a2b1f22b53
12 changed files with 269 additions and 75 deletions

View File

@@ -17,10 +17,15 @@
//==============================================================================
#include "mpw-algorithm.h"
#include "mpw-algorithm_v0.c"
#include "mpw-algorithm_v1.c"
#include "mpw-algorithm_v2.c"
#include "mpw-algorithm_v3.c"
#include "mpw-algorithm_v0.h"
#include "mpw-algorithm_v1.h"
#include "mpw-algorithm_v2.h"
#include "mpw-algorithm_v3.h"
#include "mpw-util.h"
MP_LIBS_BEGIN
#include <string.h>
MP_LIBS_END
const MPMasterKey mpw_master_key(const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion) {

View File

@@ -16,6 +16,7 @@
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
#include "mpw-algorithm_v0.h"
#include "mpw-util.h"
#include "base64.h"
@@ -31,7 +32,7 @@ MP_LIBS_END
#define MP_otp_window 5 * 60 /* s */
// Algorithm version helpers.
static const char *mpw_type_template_v0(MPResultType type, uint16_t templateIndex) {
const char *mpw_type_template_v0(MPResultType type, uint16_t templateIndex) {
size_t count = 0;
const char **templates = mpw_type_templates( type, &count );
@@ -40,7 +41,7 @@ static const char *mpw_type_template_v0(MPResultType type, uint16_t templateInde
return template;
}
static const char mpw_class_character_v0(char characterClass, uint16_t classIndex) {
const char mpw_class_character_v0(char characterClass, uint16_t classIndex) {
const char *classCharacters = mpw_class_characters( characterClass );
if (!classCharacters)
@@ -50,7 +51,7 @@ static const char mpw_class_character_v0(char characterClass, uint16_t classInde
}
// Algorithm version overrides.
static MPMasterKey mpw_master_key_v0(
MPMasterKey mpw_master_key_v0(
const char *fullName, const char *masterPassword) {
const char *keyScope = mpw_purpose_scope( MPKeyPurposeAuthentication );
@@ -84,7 +85,7 @@ static MPMasterKey mpw_master_key_v0(
return masterKey;
}
static MPSiteKey mpw_site_key_v0(
MPSiteKey mpw_site_key_v0(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext) {
@@ -128,7 +129,7 @@ static MPSiteKey mpw_site_key_v0(
return siteKey;
}
static const char *mpw_site_template_password_v0(
const char *mpw_site_template_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
const char *_siteKey = (const char *)siteKey;
@@ -158,7 +159,7 @@ static const char *mpw_site_template_password_v0(
return sitePassword;
}
static const char *mpw_site_crypted_password_v0(
const char *mpw_site_crypted_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
if (!cipherText) {
@@ -183,12 +184,13 @@ static const char *mpw_site_crypted_password_v0(
mpw_free( &plainBytes, bufSize );
if (!plainText)
err( "AES decryption error: %s", strerror( errno ) );
trc( "decrypted -> plainText: %zu bytes = %s = %s", strlen( plainText ), plainText, mpw_hex( plainText, strlen( plainText ) ) );
else
trc( "decrypted -> plainText: %zu bytes = %s = %s", strlen( plainText ), plainText, mpw_hex( plainText, strlen( plainText ) ) );
return plainText;
}
static const char *mpw_site_derived_password_v0(
const char *mpw_site_derived_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
switch (resultType) {
@@ -233,7 +235,7 @@ static const char *mpw_site_derived_password_v0(
}
}
static const char *mpw_site_state_v0(
const char *mpw_site_state_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *plainText) {
// Encrypt

View File

@@ -0,0 +1,42 @@
//==============================================================================
// This file is part of Master Password.
// Copyright (c) 2011-2017, Maarten Billemont.
//
// Master Password is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Master Password is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You can find a copy of the GNU General Public License in the
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
#ifndef _MPW_ALGORITHM_V0_H
#define _MPW_ALGORITHM_V0_H
#include "mpw-algorithm.h"
const char *mpw_type_template_v0(
MPResultType type, uint16_t templateIndex);
const char mpw_class_character_v0(
char characterClass, uint16_t classIndex);
MPMasterKey mpw_master_key_v0(
const char *fullName, const char *masterPassword);
MPSiteKey mpw_site_key_v0(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_site_template_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_crypted_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_site_derived_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_state_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *plainText);
#endif // _MPW_ALGORITHM_V0_H

View File

@@ -16,6 +16,7 @@
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
#include "mpw-algorithm_v1.h"
#include "mpw-util.h"
MP_LIBS_BEGIN
@@ -27,34 +28,21 @@ MP_LIBS_END
#define MP_p 2U
#define MP_otp_window 5 * 60 /* s */
// Inherited functions.
MPMasterKey mpw_master_key_v0(
const char *fullName, const char *masterPassword);
MPSiteKey mpw_site_key_v0(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_site_crypted_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_site_derived_password_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_state_v0(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides.
static MPMasterKey mpw_master_key_v1(
MPMasterKey mpw_master_key_v1(
const char *fullName, const char *masterPassword) {
return mpw_master_key_v0( fullName, masterPassword );
}
static MPSiteKey mpw_site_key_v1(
MPSiteKey mpw_site_key_v1(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext) {
return mpw_site_key_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext );
}
static const char *mpw_site_template_password_v1(
const char *mpw_site_template_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
// Determine the template.
@@ -81,19 +69,19 @@ static const char *mpw_site_template_password_v1(
return sitePassword;
}
static const char *mpw_site_crypted_password_v1(
const char *mpw_site_crypted_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_site_crypted_password_v0( masterKey, siteKey, resultType, cipherText );
}
static const char *mpw_site_derived_password_v1(
const char *mpw_site_derived_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_site_derived_password_v0( masterKey, siteKey, resultType, resultParam );
}
static const char *mpw_site_state_v1(
const char *mpw_site_state_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_site_state_v0( masterKey, siteKey, resultType, state );

View File

@@ -0,0 +1,42 @@
//==============================================================================
// This file is part of Master Password.
// Copyright (c) 2011-2017, Maarten Billemont.
//
// Master Password is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Master Password is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You can find a copy of the GNU General Public License in the
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
#ifndef _MPW_ALGORITHM_V1_H
#define _MPW_ALGORITHM_V1_H
#include "mpw-algorithm_v0.h"
const char *mpw_type_template_v1(
MPResultType type, uint16_t templateIndex);
const char mpw_class_character_v1(
char characterClass, uint16_t classIndex);
MPMasterKey mpw_master_key_v1(
const char *fullName, const char *masterPassword);
MPSiteKey mpw_site_key_v1(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_site_template_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_crypted_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_site_derived_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_state_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *plainText);
#endif // _MPW_ALGORITHM_V1_H

View File

@@ -16,6 +16,7 @@
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
#include "mpw-algorithm_v2.h"
#include "mpw-util.h"
MP_LIBS_BEGIN
@@ -29,26 +30,14 @@ MP_LIBS_END
#define MP_p 2U
#define MP_otp_window 5 * 60 /* s */
// Inherited functions.
MPMasterKey mpw_master_key_v1(
const char *fullName, const char *masterPassword);
const char *mpw_site_template_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_crypted_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_site_derived_password_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_state_v1(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides.
static MPMasterKey mpw_master_key_v2(
MPMasterKey mpw_master_key_v2(
const char *fullName, const char *masterPassword) {
return mpw_master_key_v1( fullName, masterPassword );
}
static MPSiteKey mpw_site_key_v2(
MPSiteKey mpw_site_key_v2(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext) {
@@ -92,25 +81,25 @@ static MPSiteKey mpw_site_key_v2(
return siteKey;
}
static const char *mpw_site_template_password_v2(
const char *mpw_site_template_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_site_template_password_v1( masterKey, siteKey, resultType, resultParam );
}
static const char *mpw_site_crypted_password_v2(
const char *mpw_site_crypted_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_site_crypted_password_v1( masterKey, siteKey, resultType, cipherText );
}
static const char *mpw_site_derived_password_v2(
const char *mpw_site_derived_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_site_derived_password_v1( masterKey, siteKey, resultType, resultParam );
}
static const char *mpw_site_state_v2(
const char *mpw_site_state_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_site_state_v1( masterKey, siteKey, resultType, state );

View File

@@ -0,0 +1,42 @@
//==============================================================================
// This file is part of Master Password.
// Copyright (c) 2011-2017, Maarten Billemont.
//
// Master Password is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Master Password is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You can find a copy of the GNU General Public License in the
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
#ifndef _MPW_ALGORITHM_V2_H
#define _MPW_ALGORITHM_V2_H
#include "mpw-algorithm_v1.h"
const char *mpw_type_template_v2(
MPResultType type, uint16_t templateIndex);
const char mpw_class_character_v2(
char characterClass, uint16_t classIndex);
MPMasterKey mpw_master_key_v2(
const char *fullName, const char *masterPassword);
MPSiteKey mpw_site_key_v2(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_site_template_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_crypted_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_site_derived_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_state_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *plainText);
#endif // _MPW_ALGORITHM_V2_H

View File

@@ -16,6 +16,7 @@
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
#include "mpw-algorithm_v3.h"
#include "mpw-util.h"
MP_LIBS_BEGIN
@@ -28,21 +29,8 @@ MP_LIBS_END
#define MP_p 2U
#define MP_otp_window 5 * 60 /* s */
// Inherited functions.
MPSiteKey mpw_site_key_v2(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_site_template_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_crypted_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_site_derived_password_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_state_v2(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides.
static MPMasterKey mpw_master_key_v3(
MPMasterKey mpw_master_key_v3(
const char *fullName, const char *masterPassword) {
const char *keyScope = mpw_purpose_scope( MPKeyPurposeAuthentication );
@@ -76,32 +64,32 @@ static MPMasterKey mpw_master_key_v3(
return masterKey;
}
static MPSiteKey mpw_site_key_v3(
MPSiteKey mpw_site_key_v3(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext) {
return mpw_site_key_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext );
}
static const char *mpw_site_template_password_v3(
const char *mpw_site_template_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_site_template_password_v2( masterKey, siteKey, resultType, resultParam );
}
static const char *mpw_site_crypted_password_v3(
const char *mpw_site_crypted_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_site_crypted_password_v2( masterKey, siteKey, resultType, cipherText );
}
static const char *mpw_site_derived_password_v3(
const char *mpw_site_derived_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_site_derived_password_v2( masterKey, siteKey, resultType, resultParam );
}
static const char *mpw_site_state_v3(
const char *mpw_site_state_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_site_state_v2( masterKey, siteKey, resultType, state );

View File

@@ -0,0 +1,42 @@
//==============================================================================
// This file is part of Master Password.
// Copyright (c) 2011-2017, Maarten Billemont.
//
// Master Password is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Master Password is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You can find a copy of the GNU General Public License in the
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
#ifndef _MPW_ALGORITHM_V3_H
#define _MPW_ALGORITHM_V3_H
#include "mpw-algorithm_v2.h"
const char *mpw_type_template_v3(
MPResultType type, uint16_t templateIndex);
const char mpw_class_character_v3(
char characterClass, uint16_t classIndex);
MPMasterKey mpw_master_key_v3(
const char *fullName, const char *masterPassword);
MPSiteKey mpw_site_key_v3(
MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_site_template_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_crypted_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_site_derived_password_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_site_state_v3(
MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *plainText);
#endif // _MPW_ALGORITHM_V3_H