2018-01-01 13:21:02 -05:00
|
|
|
/*
|
2018-01-06 17:06:51 +01:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2018-01-01 13:21:02 -05:00
|
|
|
*
|
|
|
|
* This program 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 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program 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 should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEEPASSX_ARGON2KDF_H
|
|
|
|
#define KEEPASSX_ARGON2KDF_H
|
|
|
|
|
|
|
|
#include "Kdf.h"
|
|
|
|
|
2025-03-08 09:25:34 -05:00
|
|
|
constexpr auto ARGON2_DEFAULT_VERSION = 0x13;
|
|
|
|
constexpr auto ARGON2_DEFAULT_ROUNDS = 10;
|
|
|
|
constexpr auto ARGON2_DEFAULT_MEMORY = 1 << 16;
|
|
|
|
constexpr auto ARGON2_DEFAULT_PARALLELISM = 2;
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
class Argon2Kdf : public Kdf
|
|
|
|
{
|
2018-01-01 13:21:02 -05:00
|
|
|
public:
|
2020-11-20 21:49:56 +01:00
|
|
|
enum class Type
|
|
|
|
{
|
|
|
|
Argon2d,
|
|
|
|
Argon2id
|
|
|
|
};
|
|
|
|
|
|
|
|
Argon2Kdf(Type type);
|
2018-01-01 13:21:02 -05:00
|
|
|
|
2018-01-05 10:41:29 -05:00
|
|
|
bool processParameters(const QVariantMap& p) override;
|
|
|
|
QVariantMap writeParameters() override;
|
2018-01-01 13:21:02 -05:00
|
|
|
bool transform(const QByteArray& raw, QByteArray& result) const override;
|
|
|
|
QSharedPointer<Kdf> clone() const override;
|
|
|
|
|
2018-01-05 10:41:29 -05:00
|
|
|
quint32 version() const;
|
|
|
|
bool setVersion(quint32 version);
|
2020-11-20 21:49:56 +01:00
|
|
|
Type type() const;
|
2018-01-05 10:41:29 -05:00
|
|
|
quint64 memory() const;
|
|
|
|
bool setMemory(quint64 kibibytes);
|
2018-01-01 13:21:02 -05:00
|
|
|
quint32 parallelism() const;
|
|
|
|
bool setParallelism(quint32 threads);
|
2020-01-26 23:44:31 -05:00
|
|
|
QString toString() const override;
|
2018-01-01 13:21:02 -05:00
|
|
|
|
2021-04-04 08:56:00 -04:00
|
|
|
int benchmark(int msec) const override;
|
2018-01-01 13:21:02 -05:00
|
|
|
|
2025-03-08 09:25:34 -05:00
|
|
|
static quint64 toMebibytes(quint64 kibibytes)
|
|
|
|
{
|
|
|
|
return kibibytes >> 10;
|
|
|
|
}
|
|
|
|
static quint64 toKibibytes(quint64 mebibits)
|
|
|
|
{
|
|
|
|
return mebibits << 10;
|
|
|
|
}
|
|
|
|
|
2018-01-05 10:41:29 -05:00
|
|
|
quint32 m_version;
|
|
|
|
quint64 m_memory;
|
2018-01-01 13:21:02 -05:00
|
|
|
quint32 m_parallelism;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // KEEPASSX_ARGON2KDF_H
|