Adapt to cpputils crypto library

This commit is contained in:
Sebastian Messmer 2015-10-27 23:46:54 +01:00
parent 340bbf842e
commit 0d5a7d9d10
10 changed files with 20 additions and 25 deletions

View File

@ -1,6 +1,6 @@
#include "CryCipher.h"
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
#include <messmer/cpp-utils/crypto/symmetric/ciphers.h>
#include <messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h>
using std::vector;
@ -12,9 +12,10 @@ using std::shared_ptr;
using std::make_shared;
using boost::optional;
using boost::none;
using blockstore::encrypted::EncryptedBlockStore;
using namespace cryfs;
using namespace blockstore::encrypted;
using namespace cpputils;
template<typename Cipher>
class CryCipherInstance: public CryCipher {

View File

@ -1,6 +1,5 @@
#include "CryConfigCreator.h"
#include "CryCipher.h"
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
using cpputils::Console;
using cpputils::unique_ref;

View File

@ -5,7 +5,7 @@
#include <boost/optional.hpp>
#include <boost/filesystem.hpp>
#include "CryConfig.h"
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
#include <messmer/cpp-utils/crypto/symmetric/ciphers.h>
#include "crypto/CryConfigEncryptorFactory.h"
namespace cryfs {
@ -33,7 +33,7 @@ namespace cryfs {
template<class SCryptSettings>
CryConfigFile CryConfigFile::create(const boost::filesystem::path &path, CryConfig config, const std::string &password) {
using ConfigCipher = blockstore::encrypted::AES256_GCM; // TODO Take cipher from config instead
using ConfigCipher = cpputils::AES256_GCM; // TODO Take cipher from config instead
if (boost::filesystem::exists(path)) {
throw std::runtime_error("Config file exists already.");
}

View File

@ -7,7 +7,7 @@
#include <messmer/cpp-utils/data/Serializer.h>
#include "InnerEncryptor.h"
#include <messmer/cpp-utils/crypto/kdf/DerivedKeyConfig.h>
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
#include <messmer/cpp-utils/crypto/symmetric/ciphers.h>
namespace cryfs {
//TODO Test
@ -17,7 +17,7 @@ namespace cryfs {
//TODO To get rid of many size fields, introduce Serializer::writeNullTerminatedString() and Serializer::writeUnterminatedData() (the latter one just writes until the end)
class CryConfigEncryptor {
public:
using OuterCipher = blockstore::encrypted::AES256_GCM;
using OuterCipher = cpputils::AES256_GCM;
static constexpr size_t CONFIG_SIZE = 1024; // Config data is grown to this size before encryption to hide its actual size
CryConfigEncryptor(cpputils::unique_ref<InnerEncryptor> innerEncryptor, OuterCipher::EncryptionKey outerKey, cpputils::DerivedKeyConfig keyConfig);

View File

@ -1,5 +1,5 @@
#include "CryConfigEncryptorFactory.h"
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
#include <messmer/cpp-utils/crypto/symmetric/ciphers.h>
using namespace cpputils::logging;
using boost::optional;
@ -16,7 +16,7 @@ namespace cryfs {
optional<unique_ref<CryConfigEncryptor>> CryConfigEncryptorFactory::loadKey(const Data &ciphertext,
const string &password) {
using Cipher = blockstore::encrypted::AES256_GCM; //TODO Allow other ciphers
using Cipher = cpputils::AES256_GCM; //TODO Allow other ciphers
Deserializer deserializer(&ciphertext);
try {
CryConfigEncryptor::checkHeader(&deserializer);

View File

@ -1,5 +1,5 @@
#include <messmer/blockstore/implementations/caching/CachingBlockStore.h>
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
#include <messmer/cpp-utils/crypto/symmetric/ciphers.h>
#include "parallelaccessfsblobstore/DirBlobRef.h"
#include "CryDevice.h"
@ -24,7 +24,6 @@ using fspp::fuse::FuseErrnoException;
using blockstore::BlockStore;
using blockstore::Key;
using blockstore::encrypted::EncryptedBlockStore;
using blockstore::encrypted::AES256_CFB;
using blobstore::onblocks::BlobStoreOnBlocks;
using blobstore::onblocks::BlobOnBlocks;
using blockstore::caching::CachingBlockStore;

View File

@ -1,7 +1,7 @@
#include <google/gtest/gtest.h>
#include <google/gmock/gmock.h>
#include "../../src/config/CryCipher.h"
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
#include <messmer/cpp-utils/crypto/symmetric/ciphers.h>
#include <messmer/cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
#include <messmer/blockstore/implementations/testfake/FakeBlockStore.h>
#include <messmer/blockstore/implementations/encrypted/EncryptedBlockStore.h>
@ -19,11 +19,7 @@ using std::vector;
using std::find;
using boost::none;
using testing::MatchesRegex;
using cpputils::DataFixture;
using cpputils::Data;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
using cpputils::Random;
using namespace cpputils;
class CryCipherTest : public ::testing::Test {
public:

View File

@ -2,7 +2,7 @@
#include <google/gmock/gmock.h>
#include "../../src/config/CryConfigCreator.h"
#include "../../src/config/CryCipher.h"
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
#include <messmer/cpp-utils/crypto/symmetric/ciphers.h>
#include "../testutils/MockConsole.h"
using namespace cryfs;
@ -50,19 +50,19 @@ TEST_F(CryConfigCreatorTest, ChoosesEmptyRootBlobId) {
TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_448) {
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("mars-448-gcm"));
CryConfig config = creator.create();
blockstore::encrypted::Mars448_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
cpputils::Mars448_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_256) {
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("aes-256-gcm"));
CryConfig config = creator.create();
blockstore::encrypted::AES256_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
cpputils::AES256_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_128) {
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("aes-128-gcm"));
CryConfig config = creator.create();
blockstore::encrypted::AES128_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
cpputils::AES128_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
class CryConfigCreatorTest_ChooseCipher: public CryConfigCreatorTest, public ::testing::WithParamInterface<string> {

View File

@ -3,7 +3,7 @@
#include "../../src/config/CryConfigFile.h"
#include <messmer/cpp-utils/tempfile/TempFile.h>
#include <boost/optional/optional_io.hpp>
#include <messmer/cpp-utils/test/crypto/testutils/SCryptTestSettings.h>
#include <messmer/cpp-utils/test/crypto/kdf/testutils/SCryptTestSettings.h>
using namespace cryfs;
using cpputils::TempFile;

View File

@ -3,8 +3,8 @@
#include "../testutils/MockConsole.h"
#include <messmer/cpp-utils/tempfile/TempFile.h>
#include <messmer/cpp-utils/random/Random.h>
#include <messmer/blockstore/implementations/encrypted/ciphers/ciphers.h>
#include <messmer/cpp-utils/test/crypto/testutils/SCryptTestSettings.h>
#include <messmer/cpp-utils/crypto/symmetric/ciphers.h>
#include <messmer/cpp-utils/test/crypto/kdf/testutils/SCryptTestSettings.h>
using cpputils::unique_ref;
using cpputils::make_unique_ref;
@ -93,7 +93,7 @@ TEST_F(CryConfigLoaderTest, EncryptionKey_Load) {
TEST_F(CryConfigLoaderTest, EncryptionKey_Create) {
auto created = Create();
//aes-256-gcm is the default cipher chosen by mockConsole()
blockstore::encrypted::AES256_GCM::EncryptionKey::FromString(created.config()->EncryptionKey()); // This crashes if key is invalid
cpputils::AES256_GCM::EncryptionKey::FromString(created.config()->EncryptionKey()); // This crashes if key is invalid
}
TEST_F(CryConfigLoaderTest, Cipher_Load) {