CCF
Loading...
Searching...
No Matches
src
node
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
5
#include "
ccf/crypto/symmetric_key.h
"
6
#include "
kv/encryptor.h
"
7
#include "
ledger_secrets.h
"
8
9
namespace
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
16
struct
TxGcmHeader
:
public
ccf::crypto::StandardGcmHeader
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
43
void
set_iv_is_snapshot
()
44
{
45
// Set very last bit in IV
46
iv
.back() |= (1 << ((
sizeof
(uint8_t) * 8) - 1));
47
}
48
};
49
50
using
NodeEncryptor
=
ccf::kv::TxEncryptor<ccf::LedgerSecrets, TxGcmHeader>
;
51
}
ccf::kv::TxEncryptor
Definition
encryptor.h:15
symmetric_key.h
encryptor.h
ledger_secrets.h
ccf
Definition
app_interface.h:14
ccf::TxGcmHeader
Definition
encryptor.h:17
ccf::TxGcmHeader::set_iv_is_snapshot
void set_iv_is_snapshot()
Definition
encryptor.h:43
ccf::TxGcmHeader::get_term
uint64_t get_term() const
Definition
encryptor.h:38
ccf::TxGcmHeader::IV_DELIMITER
static constexpr uint8_t IV_DELIMITER
Definition
encryptor.h:19
ccf::TxGcmHeader::set_iv_seq
void set_iv_seq(uint64_t seq)
Definition
encryptor.h:21
ccf::TxGcmHeader::set_iv_term
void set_iv_term(uint64_t term)
Definition
encryptor.h:26
ccf::crypto::FixedSizeGcmHeader< 12 >
ccf::crypto::GcmHeader::iv
std::vector< uint8_t > iv
Definition
symmetric_key.h:21
Generated by
1.9.8