2015-04-24 18:14:25 +02:00
|
|
|
#pragma once
|
|
|
|
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_ENCRYPTED_CIPHERS_AES256_CFB_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_ENCRYPTED_CIPHERS_AES256_CFB_H_
|
|
|
|
|
|
|
|
#include "../../../utils/FixedSizeData.h"
|
2015-04-24 21:08:36 +02:00
|
|
|
#include "../../../utils/Data.h"
|
2015-04-24 18:14:25 +02:00
|
|
|
#include <cryptopp/cryptopp/aes.h>
|
2015-04-24 21:08:36 +02:00
|
|
|
#include <boost/optional.hpp>
|
2015-04-24 18:14:25 +02:00
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
namespace encrypted {
|
|
|
|
|
2015-04-24 18:58:42 +02:00
|
|
|
//TODO Add contract/interface for ciphers
|
2015-04-24 18:14:25 +02:00
|
|
|
class AES256_CFB {
|
|
|
|
public:
|
|
|
|
using EncryptionKey = FixedSizeData<32>;
|
|
|
|
static_assert(32 == CryptoPP::AES::MAX_KEYLENGTH, "If AES offered larger keys, we should offer a variant with it");
|
|
|
|
|
|
|
|
AES256_CFB(const EncryptionKey &key);
|
|
|
|
|
|
|
|
static constexpr unsigned int ciphertextSize(unsigned int plaintextBlockSize) {
|
|
|
|
return plaintextBlockSize + IV_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr unsigned int plaintextSize(unsigned int ciphertextBlockSize) {
|
|
|
|
return ciphertextBlockSize - IV_SIZE;
|
|
|
|
}
|
|
|
|
|
2015-04-24 21:08:36 +02:00
|
|
|
static Data encrypt(const byte *plaintext, unsigned int plaintextSize, const EncryptionKey &encKey);
|
|
|
|
static boost::optional<Data> decrypt(const byte *ciphertext, unsigned int ciphertextSize, const EncryptionKey &encKey);
|
2015-04-24 18:14:25 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr unsigned int IV_SIZE = CryptoPP::AES::BLOCKSIZE;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|