2014-12-20 19:30:34 +00:00
|
|
|
//
|
|
|
|
// mpw-algorithm.c
|
|
|
|
// MasterPassword
|
|
|
|
//
|
|
|
|
// Created by Maarten Billemont on 2014-12-20.
|
|
|
|
// Copyright (c) 2014 Lyndir. All rights reserved.
|
|
|
|
//
|
2014-10-15 19:32:10 +00:00
|
|
|
|
2014-12-21 17:37:21 +00:00
|
|
|
#include "mpw-algorithm.h"
|
2015-01-15 22:43:41 +00:00
|
|
|
#include "mpw-algorithm_v0.c"
|
|
|
|
#include "mpw-algorithm_v1.c"
|
|
|
|
#include "mpw-algorithm_v2.c"
|
|
|
|
#include "mpw-algorithm_v3.c"
|
2014-05-05 15:16:59 +00:00
|
|
|
|
|
|
|
#define MP_N 32768
|
|
|
|
#define MP_r 8
|
|
|
|
#define MP_p 2
|
|
|
|
#define MP_hash PearlHashSHA256
|
|
|
|
|
2015-01-15 22:43:41 +00:00
|
|
|
const uint8_t *mpw_masterKeyForUser(const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion) {
|
|
|
|
|
2016-07-23 15:44:17 +00:00
|
|
|
if (!fullName || !masterPassword)
|
|
|
|
return NULL;
|
|
|
|
|
2015-01-15 22:43:41 +00:00
|
|
|
switch (algorithmVersion) {
|
|
|
|
case MPAlgorithmVersion0:
|
|
|
|
return mpw_masterKeyForUser_v0( fullName, masterPassword );
|
|
|
|
case MPAlgorithmVersion1:
|
|
|
|
return mpw_masterKeyForUser_v1( fullName, masterPassword );
|
|
|
|
case MPAlgorithmVersion2:
|
|
|
|
return mpw_masterKeyForUser_v2( fullName, masterPassword );
|
|
|
|
case MPAlgorithmVersion3:
|
|
|
|
return mpw_masterKeyForUser_v3( fullName, masterPassword );
|
|
|
|
default:
|
|
|
|
ftl( "Unsupported version: %d", algorithmVersion );
|
|
|
|
return NULL;
|
2014-12-21 17:37:21 +00:00
|
|
|
}
|
2014-12-20 04:15:32 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 05:21:03 +00:00
|
|
|
const char *mpw_passwordForSite(const uint8_t *masterKey, const char *siteName, const MPSiteType siteType, const uint32_t siteCounter,
|
2015-01-15 22:43:41 +00:00
|
|
|
const MPSiteVariant siteVariant, const char *siteContext, const MPAlgorithmVersion algorithmVersion) {
|
|
|
|
|
2016-07-23 15:44:17 +00:00
|
|
|
if (!masterKey || !siteName)
|
|
|
|
return NULL;
|
|
|
|
|
2015-01-15 22:43:41 +00:00
|
|
|
switch (algorithmVersion) {
|
|
|
|
case MPAlgorithmVersion0:
|
|
|
|
return mpw_passwordForSite_v0( masterKey, siteName, siteType, siteCounter, siteVariant, siteContext );
|
|
|
|
case MPAlgorithmVersion1:
|
|
|
|
return mpw_passwordForSite_v1( masterKey, siteName, siteType, siteCounter, siteVariant, siteContext );
|
|
|
|
case MPAlgorithmVersion2:
|
|
|
|
return mpw_passwordForSite_v2( masterKey, siteName, siteType, siteCounter, siteVariant, siteContext );
|
|
|
|
case MPAlgorithmVersion3:
|
|
|
|
return mpw_passwordForSite_v3( masterKey, siteName, siteType, siteCounter, siteVariant, siteContext );
|
|
|
|
default:
|
|
|
|
ftl( "Unsupported version: %d", algorithmVersion );
|
|
|
|
return NULL;
|
2014-10-19 04:55:26 +00:00
|
|
|
}
|
2014-05-05 15:16:59 +00:00
|
|
|
}
|