From a2b1f22b537a39496de541ea1d899186e1a46091 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 27 Sep 2019 22:38:32 -0400 Subject: [PATCH] More standard way to separate algorithm versions. --- .../project.pbxproj | 20 ++++++++- .../xcschemes/MasterPassword iOS.xcscheme | 6 +-- .../project.pbxproj | 40 ++++++++++++++++++ .../c/core/src/mpw-algorithm.c | 13 ++++-- .../c/core/src/mpw-algorithm_v0.c | 20 +++++---- .../c/core/src/mpw-algorithm_v0.h | 42 +++++++++++++++++++ .../c/core/src/mpw-algorithm_v1.c | 26 ++++-------- .../c/core/src/mpw-algorithm_v1.h | 42 +++++++++++++++++++ .../c/core/src/mpw-algorithm_v2.c | 25 ++++------- .../c/core/src/mpw-algorithm_v2.h | 42 +++++++++++++++++++ .../c/core/src/mpw-algorithm_v3.c | 26 ++++-------- .../c/core/src/mpw-algorithm_v3.h | 42 +++++++++++++++++++ 12 files changed, 269 insertions(+), 75 deletions(-) create mode 100644 platform-independent/c/core/src/mpw-algorithm_v0.h create mode 100644 platform-independent/c/core/src/mpw-algorithm_v1.h create mode 100644 platform-independent/c/core/src/mpw-algorithm_v2.h create mode 100644 platform-independent/c/core/src/mpw-algorithm_v3.h diff --git a/platform-darwin/MasterPassword-iOS.xcodeproj/project.pbxproj b/platform-darwin/MasterPassword-iOS.xcodeproj/project.pbxproj index c2648b81..2dfd030c 100644 --- a/platform-darwin/MasterPassword-iOS.xcodeproj/project.pbxproj +++ b/platform-darwin/MasterPassword-iOS.xcodeproj/project.pbxproj @@ -158,6 +158,10 @@ DA32D07C19D7D784004F3F0E /* background.png in Resources */ = {isa = PBXBuildFile; fileRef = DA32D07919D7D784004F3F0E /* background.png */; }; DA3509FE15F101A500C14A8E /* PearlQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = DA3509FC15F101A500C14A8E /* PearlQueue.h */; }; DA3509FF15F101A500C14A8E /* PearlQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = DA3509FD15F101A500C14A8E /* PearlQueue.m */; }; + DA35148A233EF93400BCF504 /* mpw-algorithm_v0.c in Sources */ = {isa = PBXBuildFile; fileRef = 93D390A99850139D0FF0211E /* mpw-algorithm_v0.c */; }; + DA35148B233EF93400BCF504 /* mpw-algorithm_v1.c in Sources */ = {isa = PBXBuildFile; fileRef = 93D396F918E6470DB846C17F /* mpw-algorithm_v1.c */; }; + DA35148C233EF93400BCF504 /* mpw-algorithm_v2.c in Sources */ = {isa = PBXBuildFile; fileRef = 93D390A3B351FEF1B9EDAB56 /* mpw-algorithm_v2.c */; }; + DA35148D233EF93400BCF504 /* mpw-algorithm_v3.c in Sources */ = {isa = PBXBuildFile; fileRef = 93D39D4E713564B7654341B0 /* mpw-algorithm_v3.c */; }; DA3BCFCB19BD09D5006B2681 /* SourceCodePro-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = DA3BCFCA19BD09D5006B2681 /* SourceCodePro-Regular.otf */; }; DA4522441902355C008F650A /* icon_book.png in Resources */ = {isa = PBXBuildFile; fileRef = DABD370C1711E29500CF925C /* icon_book.png */; }; DA4522451902355C008F650A /* icon_book@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DABD370D1711E29500CF925C /* icon_book@2x.png */; }; @@ -732,6 +736,10 @@ DA3509FC15F101A500C14A8E /* PearlQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PearlQueue.h; sourceTree = ""; }; DA3509FD15F101A500C14A8E /* PearlQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PearlQueue.m; sourceTree = ""; }; DA3B844D190FC5DF00246EEA /* Crashlytics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Crashlytics.framework; path = ../../../External/iOS/Crashlytics.framework; sourceTree = ""; }; + DA351486233EF8FE00BCF504 /* mpw-algorithm_v2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mpw-algorithm_v2.h"; sourceTree = ""; }; + DA351487233EF8FE00BCF504 /* mpw-algorithm_v1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mpw-algorithm_v1.h"; sourceTree = ""; }; + DA351488233EF8FE00BCF504 /* mpw-algorithm_v3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mpw-algorithm_v3.h"; sourceTree = ""; }; + DA351489233EF8FE00BCF504 /* mpw-algorithm_v0.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mpw-algorithm_v0.h"; sourceTree = ""; }; DA3BCFCA19BD09D5006B2681 /* SourceCodePro-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SourceCodePro-Regular.otf"; sourceTree = ""; }; DA45711B1F572F1E00D54152 /* PearlCryptUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PearlCryptUtils.m; sourceTree = ""; }; DA45711C1F572F1E00D54152 /* PearlCryptUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PearlCryptUtils.h; sourceTree = ""; }; @@ -1770,9 +1778,13 @@ DA5B0B3E1F36469400B663F0 /* base64.c */, DA5B0B3F1F36469400B663F0 /* base64.h */, 93D390A99850139D0FF0211E /* mpw-algorithm_v0.c */, + DA351489233EF8FE00BCF504 /* mpw-algorithm_v0.h */, 93D396F918E6470DB846C17F /* mpw-algorithm_v1.c */, + DA351487233EF8FE00BCF504 /* mpw-algorithm_v1.h */, 93D390A3B351FEF1B9EDAB56 /* mpw-algorithm_v2.c */, + DA351486233EF8FE00BCF504 /* mpw-algorithm_v2.h */, 93D39D4E713564B7654341B0 /* mpw-algorithm_v3.c */, + DA351488233EF8FE00BCF504 /* mpw-algorithm_v3.h */, 93D3969393A3A46BD27D7078 /* mpw-algorithm.c */, 93D3990D850D76A94C6B7A4D /* mpw-algorithm.h */, DAB7AE981F3DDEE000C856B1 /* mpw-marshal-util.c */, @@ -1949,11 +1961,11 @@ isa = PBXGroup; children = ( 93D39A2239FFFE6BEC83E191 /* core */, - DABD3B9F1711E2DB00CF925C /* Source */, - DACA23B41705DF7D002C6C22 /* Resources */, DACA22121705DDC5002C6C22 /* External */, DA5BFA47147E415C00F98B1E /* Frameworks */, DA5BFA45147E415C00F98B1E /* Products */, + DACA23B41705DF7D002C6C22 /* Resources */, + DABD3B9F1711E2DB00CF925C /* Source */, ); sourceTree = ""; }; @@ -4008,6 +4020,7 @@ 93D396D8B67DA6522CDBA142 /* MPCoachmarkViewController.m in Sources */, DAADBFE01A68763B00F7A756 /* mpw-algorithm.c in Sources */, DA0CC54E1EB6AD0E009A8ED9 /* MasterPassword.xcdatamodeld in Sources */, + DA35148D233EF93400BCF504 /* mpw-algorithm_v3.c in Sources */, DAB07C9D1F7725C500CC6D43 /* aes.c in Sources */, 93D39EAA4D064193074D3021 /* MPFixable.m in Sources */, 93D394982CBD25D46692DD7C /* MPWebViewController.m in Sources */, @@ -4021,6 +4034,9 @@ 93D395B715D15F2B56F2A2EE /* mpw-types.c in Sources */, 93D39943D01E70DAC3B0DF76 /* mpw-util.c in Sources */, DA5B0B401F36469400B663F0 /* base64.c in Sources */, + DA35148B233EF93400BCF504 /* mpw-algorithm_v1.c in Sources */, + DA35148A233EF93400BCF504 /* mpw-algorithm_v0.c in Sources */, + DA35148C233EF93400BCF504 /* mpw-algorithm_v2.c in Sources */, 93D39577FD8BB0945DB2F0A3 /* MPAlgorithmV3.m in Sources */, 93D39E5F7F6D7F5C0FAD090F /* MPTypes.m in Sources */, DA0CC58C1EB6B030009A8ED9 /* MPGeneratedSiteEntity+CoreDataClass.m in Sources */, diff --git a/platform-darwin/MasterPassword-iOS.xcodeproj/xcshareddata/xcschemes/MasterPassword iOS.xcscheme b/platform-darwin/MasterPassword-iOS.xcodeproj/xcshareddata/xcschemes/MasterPassword iOS.xcscheme index cc7db435..e45d53e3 100644 --- a/platform-darwin/MasterPassword-iOS.xcodeproj/xcshareddata/xcschemes/MasterPassword iOS.xcscheme +++ b/platform-darwin/MasterPassword-iOS.xcodeproj/xcshareddata/xcschemes/MasterPassword iOS.xcscheme @@ -28,8 +28,6 @@ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" language = "" shouldUseLaunchSchemeArgsEnv = "YES"> - - - - + + +MP_LIBS_END const MPMasterKey mpw_master_key(const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion) { diff --git a/platform-independent/c/core/src/mpw-algorithm_v0.c b/platform-independent/c/core/src/mpw-algorithm_v0.c index a994e056..a729aac3 100644 --- a/platform-independent/c/core/src/mpw-algorithm_v0.c +++ b/platform-independent/c/core/src/mpw-algorithm_v0.c @@ -16,6 +16,7 @@ // LICENSE file. Alternatively, see . //============================================================================== +#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 diff --git a/platform-independent/c/core/src/mpw-algorithm_v0.h b/platform-independent/c/core/src/mpw-algorithm_v0.h new file mode 100644 index 00000000..d17aa26a --- /dev/null +++ b/platform-independent/c/core/src/mpw-algorithm_v0.h @@ -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 . +//============================================================================== + +#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 diff --git a/platform-independent/c/core/src/mpw-algorithm_v1.c b/platform-independent/c/core/src/mpw-algorithm_v1.c index ccbd0ec3..4b92a5f5 100644 --- a/platform-independent/c/core/src/mpw-algorithm_v1.c +++ b/platform-independent/c/core/src/mpw-algorithm_v1.c @@ -16,6 +16,7 @@ // LICENSE file. Alternatively, see . //============================================================================== +#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 ); diff --git a/platform-independent/c/core/src/mpw-algorithm_v1.h b/platform-independent/c/core/src/mpw-algorithm_v1.h new file mode 100644 index 00000000..f6181edd --- /dev/null +++ b/platform-independent/c/core/src/mpw-algorithm_v1.h @@ -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 . +//============================================================================== + +#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 diff --git a/platform-independent/c/core/src/mpw-algorithm_v2.c b/platform-independent/c/core/src/mpw-algorithm_v2.c index 4d9b6451..14bd8564 100644 --- a/platform-independent/c/core/src/mpw-algorithm_v2.c +++ b/platform-independent/c/core/src/mpw-algorithm_v2.c @@ -16,6 +16,7 @@ // LICENSE file. Alternatively, see . //============================================================================== +#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 ); diff --git a/platform-independent/c/core/src/mpw-algorithm_v2.h b/platform-independent/c/core/src/mpw-algorithm_v2.h new file mode 100644 index 00000000..3ca28959 --- /dev/null +++ b/platform-independent/c/core/src/mpw-algorithm_v2.h @@ -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 . +//============================================================================== + +#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 diff --git a/platform-independent/c/core/src/mpw-algorithm_v3.c b/platform-independent/c/core/src/mpw-algorithm_v3.c index a4489247..ded33932 100644 --- a/platform-independent/c/core/src/mpw-algorithm_v3.c +++ b/platform-independent/c/core/src/mpw-algorithm_v3.c @@ -16,6 +16,7 @@ // LICENSE file. Alternatively, see . //============================================================================== +#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 ); diff --git a/platform-independent/c/core/src/mpw-algorithm_v3.h b/platform-independent/c/core/src/mpw-algorithm_v3.h new file mode 100644 index 00000000..60a16f10 --- /dev/null +++ b/platform-independent/c/core/src/mpw-algorithm_v3.h @@ -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 . +//============================================================================== + +#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