2017-04-05 20:56:22 +00:00
|
|
|
//==============================================================================
|
|
|
|
// This file is part of Master Password.
|
|
|
|
// Copyright (c) 2011-2017, Maarten Billemont.
|
2014-12-20 19:30:34 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// 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.
|
2014-12-20 19:30:34 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// 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.
|
2014-12-20 19:30:34 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// You can find a copy of the GNU General Public License in the
|
|
|
|
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
|
|
|
|
//==============================================================================
|
2014-12-20 19:30:34 +00:00
|
|
|
|
2015-03-12 05:03:02 +00:00
|
|
|
// NOTE: mpw is currently NOT thread-safe.
|
2015-01-20 04:21:10 +00:00
|
|
|
#include "mpw-types.h"
|
2015-01-15 22:43:41 +00:00
|
|
|
|
2017-07-16 01:13:49 +00:00
|
|
|
#ifndef _MPW_ALGORITHM_H
|
|
|
|
#define _MPW_ALGORITHM_H
|
|
|
|
|
|
|
|
typedef enum( unsigned int, MPAlgorithmVersion ) {
|
2015-01-15 22:43:41 +00:00
|
|
|
/** V0 did math with chars whose signedness was platform-dependent. */
|
|
|
|
MPAlgorithmVersion0,
|
|
|
|
/** V1 miscounted the byte-length of multi-byte site names. */
|
|
|
|
MPAlgorithmVersion1,
|
|
|
|
/** V2 miscounted the byte-length of multi-byte user names. */
|
|
|
|
MPAlgorithmVersion2,
|
|
|
|
/** V3 is the current version. */
|
|
|
|
MPAlgorithmVersion3,
|
2017-07-16 01:13:49 +00:00
|
|
|
|
|
|
|
MPAlgorithmVersionCurrent = MPAlgorithmVersion3,
|
2017-07-23 01:38:53 +00:00
|
|
|
MPAlgorithmVersionFirst = MPAlgorithmVersion0,
|
|
|
|
MPAlgorithmVersionLast = MPAlgorithmVersion3,
|
2015-01-15 22:43:41 +00:00
|
|
|
};
|
2014-12-21 17:37:21 +00:00
|
|
|
|
2014-12-20 19:30:34 +00:00
|
|
|
/** Derive the master key for a user based on their name and master password.
|
2017-08-01 12:31:39 +00:00
|
|
|
* @return A new MPMasterKeySize-byte allocated buffer or NULL if an error occurred. */
|
|
|
|
MPMasterKey mpw_masterKey(
|
2015-01-15 22:43:41 +00:00
|
|
|
const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion);
|
2014-12-20 19:30:34 +00:00
|
|
|
|
2017-08-01 12:31:39 +00:00
|
|
|
/** 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(
|
2017-08-08 00:27:08 +00:00
|
|
|
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
|
2017-08-01 17:45:54 +00:00
|
|
|
const MPKeyPurpose keyPurpose, const char *keyContext, const MPAlgorithmVersion algorithmVersion);
|
2017-07-16 01:13:49 +00:00
|
|
|
|
2017-08-22 22:18:24 +00:00
|
|
|
/** 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.
|
2017-08-01 12:31:39 +00:00
|
|
|
* @return A newly allocated string or NULL if an error occurred. */
|
2017-08-10 16:30:42 +00:00
|
|
|
const char *mpw_siteResult(
|
|
|
|
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
|
|
|
|
const MPKeyPurpose keyPurpose, const char *keyContext,
|
|
|
|
const MPResultType resultType, const char *resultParam,
|
|
|
|
const MPAlgorithmVersion algorithmVersion);
|
2017-08-01 12:31:39 +00:00
|
|
|
|
2017-08-22 22:18:24 +00:00
|
|
|
/** Encrypt a stateful site token for persistence.
|
|
|
|
* @param resultParam A parameter for the resultType. For stateful result types, the desired mpw_siteResult.
|
|
|
|
* @return A newly allocated string or NULL if an error occurred. */
|
2017-08-10 16:30:42 +00:00
|
|
|
const char *mpw_siteState(
|
|
|
|
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter,
|
|
|
|
const MPKeyPurpose keyPurpose, const char *keyContext,
|
2017-08-22 22:18:24 +00:00
|
|
|
const MPResultType resultType, const char *resultParam,
|
2017-08-10 16:30:42 +00:00
|
|
|
const MPAlgorithmVersion algorithmVersion);
|
2017-08-04 14:43:46 +00:00
|
|
|
|
2017-07-16 01:13:49 +00:00
|
|
|
#endif // _MPW_ALGORITHM_H
|