keepassxc
1/*
2* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
3*
4* This program is free software: you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation, either version 2 or (at your option)
7* version 3 of the License.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "Kdf.h"19
20#include "crypto/Random.h"21
22Kdf::Kdf(const QUuid& uuid)23: m_rounds(KDF_DEFAULT_ROUNDS)24, m_seed(QByteArray(KDF_MAX_SEED_SIZE, 0))25, m_uuid(uuid)26{
27}
28
29const QUuid& Kdf::uuid() const30{
31return m_uuid;32}
33
34int Kdf::rounds() const35{
36return m_rounds;37}
38
39QByteArray Kdf::seed() const40{
41return m_seed;42}
43
44bool Kdf::setRounds(int rounds)45{
46if (rounds >= 1 && rounds < INT_MAX) {47m_rounds = rounds;48return true;49}50m_rounds = 1;51return false;52}
53
54bool Kdf::setSeed(const QByteArray& seed)55{
56if (seed.size() < KDF_MIN_SEED_SIZE || seed.size() > KDF_MAX_SEED_SIZE) {57return false;58}59
60m_seed = seed;61return true;62}
63
64void Kdf::randomizeSeed()65{
66setSeed(randomGen()->randomArray(m_seed.size()));67}
68