libcryfs/test/cpp-utils/crypto/kdf/SCryptTest.cpp

51 lines
2.2 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
2016-02-11 12:53:42 +01:00
#include "cpp-utils/crypto/kdf/Scrypt.h"
2015-10-27 23:19:11 +01:00
using namespace cpputils;
TEST(SCryptTest, GeneratedKeyIsReproductible_448) {
2015-11-04 05:13:23 +01:00
auto created = SCrypt().generateKey<56>("mypassword", SCrypt::TestSettings);
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);
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);
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);
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);
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());
}
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());
}