2016-02-10 00:58:03 +01:00
|
|
|
#include <gtest/gtest.h>
|
2016-02-11 12:53:42 +01:00
|
|
|
#include "cpp-utils/crypto/kdf/DerivedKeyConfig.h"
|
|
|
|
#include "cpp-utils/data/DataFixture.h"
|
2015-10-27 22:19:06 +01:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
using namespace cpputils;
|
|
|
|
|
|
|
|
class DerivedKeyConfigTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
DerivedKeyConfig SaveAndLoad(const DerivedKeyConfig &source) {
|
|
|
|
Serializer serializer(source.serializedSize());
|
|
|
|
source.serialize(&serializer);
|
|
|
|
Data serialized = serializer.finished();
|
|
|
|
Deserializer deserializer(&serialized);
|
2015-11-13 00:31:11 +01:00
|
|
|
return DerivedKeyConfig::deserialize(&deserializer);
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, Salt) {
|
|
|
|
DerivedKeyConfig cfg(DataFixture::generate(32), 0, 0, 0);
|
|
|
|
EXPECT_EQ(DataFixture::generate(32), cfg.salt());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, Salt_Move) {
|
|
|
|
DerivedKeyConfig cfg(DataFixture::generate(32), 0, 0, 0);
|
|
|
|
DerivedKeyConfig moved = std::move(cfg);
|
|
|
|
EXPECT_EQ(DataFixture::generate(32), moved.salt());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, Salt_SaveAndLoad) {
|
|
|
|
DerivedKeyConfig cfg(DataFixture::generate(32), 0, 0, 0);
|
|
|
|
DerivedKeyConfig loaded = SaveAndLoad(cfg);
|
|
|
|
EXPECT_EQ(DataFixture::generate(32), loaded.salt());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, N) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 1024, 0, 0);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(1024u, cfg.N());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, N_Move) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 1024, 0, 0);
|
|
|
|
DerivedKeyConfig moved = std::move(cfg);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(1024u, moved.N());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, N_SaveAndLoad) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 1024, 0, 0);
|
|
|
|
DerivedKeyConfig loaded = SaveAndLoad(cfg);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(1024u, loaded.N());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, r) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 8, 0);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(8u, cfg.r());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, r_Move) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 8, 0);
|
|
|
|
DerivedKeyConfig moved = std::move(cfg);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(8u, moved.r());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, r_SaveAndLoad) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 8, 0);
|
|
|
|
DerivedKeyConfig loaded = SaveAndLoad(cfg);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(8u, loaded.r());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, p) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 0, 16);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(16u, cfg.p());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, p_Move) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 0, 16);
|
|
|
|
DerivedKeyConfig moved = std::move(cfg);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(16u, moved.p());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(DerivedKeyConfigTest, p_SaveAndLoad) {
|
|
|
|
DerivedKeyConfig cfg(Data(0), 0, 0, 16);
|
|
|
|
DerivedKeyConfig loaded = SaveAndLoad(cfg);
|
2016-02-11 12:04:49 +01:00
|
|
|
EXPECT_EQ(16u, loaded.p());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|