13 template <
typename T,
typename S>
17 std::shared_ptr<T> ledger_secrets;
32 hdr.set_iv_term(tx_id.
term);
35 hdr.set_iv_is_snapshot();
40 TxEncryptor(
const std::shared_ptr<T>& secrets) : ledger_secrets(secrets) {}
44 return S::serialised_size();
47 uint64_t
get_term(
const uint8_t* data,
size_t size)
override
50 s.deserialise(data, size);
73 const std::vector<uint8_t>& plain,
74 const std::vector<uint8_t>& additional_data,
75 std::vector<uint8_t>& serialised_header,
76 std::vector<uint8_t>& cipher,
79 bool historical_hint =
false)
override
83 set_iv(hdr, tx_id, entry_type);
86 ledger_secrets->get_encryption_key_for(tx_id.
version, historical_hint);
92 key->encrypt(hdr.get_iv(), plain, additional_data, cipher, hdr.tag);
94 serialised_header = hdr.serialise();
116 const std::vector<uint8_t>& cipher,
117 const std::vector<uint8_t>& additional_data,
118 const std::vector<uint8_t>& serialised_header,
119 std::vector<uint8_t>& plain,
122 bool historical_hint =
false)
override
125 hdr.deserialise(serialised_header);
126 term = hdr.get_term();
129 ledger_secrets->get_encryption_key_for(version, historical_hint);
136 key->decrypt(hdr.get_iv(), hdr.tag, cipher, additional_data, plain);
146 const TxID& tx_id,
bool historical_hint =
false)
override
149 ledger_secrets->get_secret_for(tx_id.
version, historical_hint);
150 if (secret ==
nullptr)
152 throw std::logic_error(
"Failed to get encryption key");
154 auto txid_str = tx_id.
str();
155 std::vector<uint8_t> txid = {
156 txid_str.data(), txid_str.data() + txid_str.size()};
172 ledger_secrets->rollback(version);
Definition kv_types.h:547
Definition encryptor.h:15
size_t get_header_length() override
Definition encryptor.h:42
uint64_t get_term(const uint8_t *data, size_t size) override
Definition encryptor.h:47
bool encrypt(const std::vector< uint8_t > &plain, const std::vector< uint8_t > &additional_data, std::vector< uint8_t > &serialised_header, std::vector< uint8_t > &cipher, const TxID &tx_id, EntryType entry_type=EntryType::WriteSet, bool historical_hint=false) override
Definition encryptor.h:72
TxEncryptor(const std::shared_ptr< T > &secrets)
Definition encryptor.h:40
void rollback(Version version) override
Definition encryptor.h:163
ccf::crypto::HashBytes get_commit_nonce(const TxID &tx_id, bool historical_hint=false) override
Definition encryptor.h:145
bool decrypt(const std::vector< uint8_t > &cipher, const std::vector< uint8_t > &additional_data, const std::vector< uint8_t > &serialised_header, std::vector< uint8_t > &plain, Version version, Term &term, bool historical_hint=false) override
Definition encryptor.h:115
HashBytes hmac(MDType type, const std::vector< uint8_t > &key, const std::vector< uint8_t > &data)
Definition hmac.cpp:43
std::vector< uint8_t > HashBytes
Definition hash_bytes.h:10
Definition app_interface.h:19
uint64_t Term
Definition kv_types.h:48
EntryType
Definition kv_types.h:269
uint64_t Version
Definition version.h:8
std::string str() const
Definition kv_types.h:73
Version version
Definition kv_types.h:54
Term term
Definition kv_types.h:53