CCF
Loading...
Searching...
No Matches
encryptor.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
6#include "kv/encryptor.h"
7#include "ledger_secrets.h"
8
9namespace ccf
10{
11 // Extends 12-byte IV GcmHeader with interpretation of those bytes as term,
12 // seqno, and snapshot indicator:
13 // - 8 LSB are unique sequence number
14 // - 4 MSB (except final bit) are the 4 LSB of term
15 // - Final bit indicates a snapshot
17 {
18 using ccf::crypto::StandardGcmHeader::StandardGcmHeader;
19 constexpr static uint8_t IV_DELIMITER = 8;
20
21 void set_iv_seq(uint64_t seq)
22 {
23 *reinterpret_cast<uint64_t*>(iv.data()) = seq;
24 }
25
26 void set_iv_term(uint64_t term)
27 {
28 if (term > 0x7FFFFFFF)
29 {
30 throw std::logic_error(fmt::format(
31 "term should fit in 31 bits of IV. Value is: 0x{0:x}", term));
32 }
33
34 *reinterpret_cast<uint32_t*>(iv.data() + IV_DELIMITER) =
35 static_cast<uint32_t>(term);
36 }
37
38 uint64_t get_term() const
39 {
40 return *reinterpret_cast<const uint32_t*>(iv.data() + IV_DELIMITER);
41 }
42
44 {
45 // Set very last bit in IV
46 iv.back() |= (1 << ((sizeof(uint8_t) * 8) - 1));
47 }
48 };
49
51}
Definition encryptor.h:15
Definition app_interface.h:14
Definition encryptor.h:17
void set_iv_is_snapshot()
Definition encryptor.h:43
uint64_t get_term() const
Definition encryptor.h:38
static constexpr uint8_t IV_DELIMITER
Definition encryptor.h:19
void set_iv_seq(uint64_t seq)
Definition encryptor.h:21
void set_iv_term(uint64_t term)
Definition encryptor.h:26
std::vector< uint8_t > iv
Definition symmetric_key.h:21