38 std::string salt = std::string{
"bitcoin_v2_shared_secret"} + std::string(std::begin(message_header), std::end(message_header));
44 bool side = (initiator != self_decrypt);
46 std::array<std::byte, 32> hkdf_32_okm;
73void BIP324Cipher::Encrypt(std::span<const std::byte> contents, std::span<const std::byte> aad,
bool ignore, std::span<std::byte> output)
noexcept
79 len[0] = std::byte{(uint8_t)(contents.size() & 0xFF)};
80 len[1] = std::byte{(uint8_t)((contents.size() >> 8) & 0xFF)};
81 len[2] = std::byte{(uint8_t)((contents.size() >> 16) & 0xFF)};
97 return uint32_t(buf[0]) + (uint32_t(buf[1]) << 8) + (uint32_t(buf[2]) << 16);
100bool BIP324Cipher::Decrypt(std::span<const std::byte> input, std::span<const std::byte> aad,
bool& ignore, std::span<std::byte> contents)
noexcept
105 if (!
m_recv_p_cipher->Decrypt(input, aad, header, contents))
return false;
const CChainParams & Params()
Return the currently selected parameters.
static constexpr unsigned REKEY_INTERVAL
bool Decrypt(std::span< const std::byte > input, std::span< const std::byte > aad, bool &ignore, std::span< std::byte > contents) noexcept
Decrypt a packet.
static constexpr unsigned GARBAGE_TERMINATOR_LEN
static constexpr unsigned HEADER_LEN
unsigned DecryptLength(std::span< const std::byte > input) noexcept
Decrypt the length of a packet.
EllSwiftPubKey m_our_pubkey
static constexpr std::byte IGNORE_BIT
BIP324Cipher()=delete
No default constructor; keys must be provided to create a BIP324Cipher.
std::optional< FSChaCha20Poly1305 > m_recv_p_cipher
std::array< std::byte, GARBAGE_TERMINATOR_LEN > m_recv_garbage_terminator
std::array< std::byte, SESSION_ID_LEN > m_session_id
std::array< std::byte, GARBAGE_TERMINATOR_LEN > m_send_garbage_terminator
std::optional< FSChaCha20 > m_recv_l_cipher
static constexpr unsigned LENGTH_LEN
static constexpr unsigned EXPANSION
void Initialize(const EllSwiftPubKey &their_pubkey, bool initiator, bool self_decrypt=false) noexcept
Initialize when the other side's public key is received.
std::optional< FSChaCha20Poly1305 > m_send_p_cipher
std::optional< FSChaCha20 > m_send_l_cipher
void Encrypt(std::span< const std::byte > contents, std::span< const std::byte > aad, bool ignore, std::span< std::byte > output) noexcept
Encrypt a packet.
const MessageStartChars & MessageStart() const
A rfc5869 HKDF implementation with HMAC_SHA256 and fixed key output length of 32 bytes (L=32).
void Expand32(const std::string &info, unsigned char hash[OUTPUT_SIZE])
An encapsulated private key.
void memory_cleanse(void *ptr, size_t len)
Secure overwrite a buffer (possibly containing secret data) with zero-bytes.
std::array< std::byte, ECDH_SECRET_SIZE > ECDHSecret
unsigned char * UCharCast(char *c)
An ElligatorSwift-encoded public key.