2016-02-10 00:58:03 +01:00
|
|
|
#include <gtest/gtest.h>
|
2016-02-11 12:04:49 +01:00
|
|
|
#include "../../../../src/cpp-utils/crypto/kdf/Scrypt.h"
|
2015-10-27 22:19:06 +01:00
|
|
|
|
2015-10-27 23:19:11 +01:00
|
|
|
using namespace cpputils;
|
2015-10-27 22:19:06 +01:00
|
|
|
|
|
|
|
TEST(SCryptTest, GeneratedKeyIsReproductible_448) {
|
2015-11-04 05:13:23 +01:00
|
|
|
auto created = SCrypt().generateKey<56>("mypassword", SCrypt::TestSettings);
|
2015-10-27 22:19:06 +01:00
|
|
|
auto recreated = SCrypt().generateKeyFromConfig<56>("mypassword", created.config());
|
|
|
|
EXPECT_EQ(created.key(), recreated);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SCryptTest, GeneratedKeyIsReproductible_256) {
|
2015-11-04 05:13:23 +01:00
|
|
|
auto created = SCrypt().generateKey<32>("mypassword", SCrypt::TestSettings);
|
2015-10-27 22:19:06 +01:00
|
|
|
auto recreated = SCrypt().generateKeyFromConfig<32>("mypassword", created.config());
|
|
|
|
EXPECT_EQ(created.key(), recreated);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SCryptTest, GeneratedKeyIsReproductible_128) {
|
2015-11-04 05:13:23 +01:00
|
|
|
auto created = SCrypt().generateKey<16>("mypassword", SCrypt::TestSettings);
|
2015-10-27 22:19:06 +01:00
|
|
|
auto recreated = SCrypt().generateKeyFromConfig<16>("mypassword", created.config());
|
|
|
|
EXPECT_EQ(created.key(), recreated);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SCryptTest, GeneratedKeyIsReproductible_DefaultSettings) {
|
2015-11-04 05:13:23 +01:00
|
|
|
auto created = SCrypt().generateKey<16>("mypassword", SCrypt::DefaultSettings);
|
2015-10-27 22:19:06 +01:00
|
|
|
auto recreated = SCrypt().generateKeyFromConfig<16>("mypassword", created.config());
|
|
|
|
EXPECT_EQ(created.key(), recreated);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SCryptTest, DifferentPasswordResultsInDifferentKey) {
|
2015-11-04 05:13:23 +01:00
|
|
|
auto created = SCrypt().generateKey<16>("mypassword", SCrypt::TestSettings);
|
2015-10-27 22:19:06 +01:00
|
|
|
auto recreated = SCrypt().generateKeyFromConfig<16>("mypassword2", created.config());
|
|
|
|
EXPECT_NE(created.key(), recreated);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SCryptTest, UsesCorrectSettings) {
|
2015-11-04 05:13:23 +01:00
|
|
|
auto created = SCrypt().generateKey<16>("mypassword", SCrypt::TestSettings);
|
|
|
|
EXPECT_EQ(SCrypt::TestSettings.SALT_LEN, created.config().salt().size());
|
|
|
|
EXPECT_EQ(SCrypt::TestSettings.N, created.config().N());
|
|
|
|
EXPECT_EQ(SCrypt::TestSettings.r, created.config().r());
|
|
|
|
EXPECT_EQ(SCrypt::TestSettings.p, created.config().p());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SCryptTest, UsesCorrectDefaultSettings) {
|
2015-11-04 05:13:23 +01:00
|
|
|
auto created = SCrypt().generateKey<16>("mypassword", SCrypt::DefaultSettings);
|
|
|
|
EXPECT_EQ(SCrypt::DefaultSettings.SALT_LEN, created.config().salt().size());
|
|
|
|
EXPECT_EQ(SCrypt::DefaultSettings.N, created.config().N());
|
|
|
|
EXPECT_EQ(SCrypt::DefaultSettings.r, created.config().r());
|
|
|
|
EXPECT_EQ(SCrypt::DefaultSettings.p, created.config().p());
|
2015-10-27 22:19:06 +01:00
|
|
|
}
|