Refactor key creation
This commit is contained in:
parent
62549eeae6
commit
caaf528031
@ -19,13 +19,8 @@ public:
|
||||
|
||||
using EncryptionKey = cpputils::FixedSizeData<KeySize>;
|
||||
|
||||
static EncryptionKey CreateKey() {
|
||||
return cpputils::Random::OSRandom().getFixedSize<EncryptionKey::BINARY_LENGTH>();
|
||||
}
|
||||
|
||||
// Used in test cases for fast key creation
|
||||
static EncryptionKey CreatePseudoRandomKey() {
|
||||
return cpputils::Random::PseudoRandom().getFixedSize<EncryptionKey::BINARY_LENGTH>();
|
||||
static EncryptionKey CreateKey(cpputils::RandomGenerator &randomGenerator) {
|
||||
return randomGenerator.getFixedSize<EncryptionKey::BINARY_LENGTH>();
|
||||
}
|
||||
|
||||
static constexpr unsigned int ciphertextSize(unsigned int plaintextBlockSize) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <cstdint>
|
||||
#include <messmer/cpp-utils/data/Data.h>
|
||||
#include <messmer/cpp-utils/random/Random.h>
|
||||
|
||||
namespace blockstore {
|
||||
namespace encrypted {
|
||||
@ -15,10 +16,9 @@ public:
|
||||
BOOST_CONCEPT_USAGE(CipherConcept) {
|
||||
same_type(UINT32_C(0), X::ciphertextSize(UINT32_C(5)));
|
||||
same_type(UINT32_C(0), X::plaintextSize(UINT32_C(5)));
|
||||
typename X::EncryptionKey key1 = X::CreateKey();
|
||||
typename X::EncryptionKey key2 = X::CreatePseudoRandomKey();
|
||||
same_type(cpputils::Data(0), X::encrypt((uint8_t*)nullptr, UINT32_C(0), key1));
|
||||
same_type(boost::optional<cpputils::Data>(cpputils::Data(0)), X::decrypt((uint8_t*)nullptr, UINT32_C(0), key2));
|
||||
typename X::EncryptionKey key = X::CreateKey(cpputils::Random::OSRandom());
|
||||
same_type(cpputils::Data(0), X::encrypt((uint8_t*)nullptr, UINT32_C(0), key));
|
||||
same_type(boost::optional<cpputils::Data>(cpputils::Data(0)), X::decrypt((uint8_t*)nullptr, UINT32_C(0), key));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -18,13 +18,8 @@ public:
|
||||
|
||||
using EncryptionKey = cpputils::FixedSizeData<KeySize>;
|
||||
|
||||
static EncryptionKey CreateKey() {
|
||||
return cpputils::Random::OSRandom().getFixedSize<EncryptionKey::BINARY_LENGTH>();
|
||||
}
|
||||
|
||||
// Used in test cases for fast key creation
|
||||
static EncryptionKey CreatePseudoRandomKey() {
|
||||
return cpputils::Random::PseudoRandom().getFixedSize<EncryptionKey::BINARY_LENGTH>();
|
||||
static EncryptionKey CreateKey(cpputils::RandomGenerator &randomGenerator) {
|
||||
return randomGenerator.getFixedSize<EncryptionKey::BINARY_LENGTH>();
|
||||
}
|
||||
|
||||
static constexpr unsigned int ciphertextSize(unsigned int plaintextBlockSize) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "../../../../implementations/encrypted/ciphers/Cipher.h"
|
||||
#include <messmer/cpp-utils/data/FixedSizeData.h>
|
||||
#include <messmer/cpp-utils/random/Random.h>
|
||||
|
||||
struct FakeKey {
|
||||
static FakeKey FromBinary(const void *data) {
|
||||
@ -21,12 +22,9 @@ public:
|
||||
|
||||
using EncryptionKey = FakeKey;
|
||||
|
||||
static EncryptionKey CreateKey() {
|
||||
return FakeKey{(uint8_t)rand()};
|
||||
}
|
||||
|
||||
static EncryptionKey CreatePseudoRandomKey() {
|
||||
return FakeKey{(uint8_t)rand()};
|
||||
static EncryptionKey CreateKey(cpputils::RandomGenerator &randomGenerator) {
|
||||
auto data = randomGenerator.getFixedSize<1>();
|
||||
return FakeKey{*((uint8_t*)data.data())};
|
||||
}
|
||||
|
||||
static EncryptionKey Key1() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user