1 #ifndef NDNPH_KEYCHAIN_IV_HPP
2 #define NDNPH_KEYCHAIN_IV_HPP
4 #include "../port/random/port.hpp"
5 #include "../tlv/nni.hpp"
6 #include "../tlv/value.hpp"
21 using IvLen = std::integral_constant<size_t, 12>;
24 using BlockSize = std::integral_constant<size_t, 16>;
44 uint64_t nBlocks =
divCeil(size, BlockSize::value);
45 uint64_t cnt =
static_cast<uint64_t
>(
counter) + nBlocks;
46 if (cnt > std::numeric_limits<uint32_t>::max()) {
49 counter =
static_cast<uint32_t
>(cnt);
59 bool check(
const uint8_t* iv,
size_t size) {
65 }
else if (
random != rand) {
static bool generate(uint8_t *output, size_t count)
AES-GCM Initialization Vector generator and checker.
Definition: iv.hpp:18
bool check(const uint8_t *iv, size_t size)
Check received IV.
Definition: iv.hpp:59
std::integral_constant< size_t, 12 > IvLen
IV length.
Definition: iv.hpp:21
bool write(uint8_t room[12])
Write IV to room .
Definition: iv.hpp:33
uint64_t random
Definition: iv.hpp:77
std::integral_constant< size_t, 16 > BlockSize
AES-GCM block size.
Definition: iv.hpp:24
bool randomize()
Randomize the random number portion.
Definition: iv.hpp:27
bool advance(size_t size)
Advance the counter portion.
Definition: iv.hpp:43
uint32_t counter
Definition: iv.hpp:78
static void writeValue(uint8_t *room, T n)
static T readValue(const uint8_t *input)
std::enable_if< std::is_integral< I >::value, I >::type divCeil(const I &a, const I &b)
Compute ceil( a / b ).
Definition: operators.hpp:25