38 std::string salt = std::string{
"bitcoin_v2_shared_secret"} + std::string(std::begin(message_header), std::end(message_header));
41 ECDHSecret ecdh_secret = m_key.ComputeBIP324ECDHSecret(their_pubkey, m_our_pubkey, initiator);
44 bool side = (initiator != self_decrypt);
46 std::array<std::byte, 32> hkdf_32_okm;
48 (side ? m_send_l_cipher : m_recv_l_cipher).emplace(hkdf_32_okm, REKEY_INTERVAL);
50 (side ? m_send_p_cipher : m_recv_p_cipher).emplace(hkdf_32_okm, REKEY_INTERVAL);
52 (side ? m_recv_l_cipher : m_send_l_cipher).emplace(hkdf_32_okm, REKEY_INTERVAL);
54 (side ? m_recv_p_cipher : m_send_p_cipher).emplace(hkdf_32_okm, REKEY_INTERVAL);
58 std::copy(std::begin(hkdf_32_okm), std::begin(hkdf_32_okm) + GARBAGE_TERMINATOR_LEN,
59 (initiator ? m_send_garbage_terminator : m_recv_garbage_terminator).begin());
60 std::copy(std::end(hkdf_32_okm) - GARBAGE_TERMINATOR_LEN, std::end(hkdf_32_okm),
61 (initiator ? m_recv_garbage_terminator : m_send_garbage_terminator).begin());
75 assert(output.size() == contents.size() + EXPANSION);
78 std::byte len[LENGTH_LEN];
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)};
82 m_send_l_cipher->Crypt(len, output.first(LENGTH_LEN));
85 std::byte header[HEADER_LEN] = {ignore ? IGNORE_BIT : std::byte{0}};
86 m_send_p_cipher->Encrypt(header, contents, aad, output.subspan(LENGTH_LEN));
void Initialize(const EllSwiftPubKey &their_pubkey, bool initiator, bool self_decrypt=false) noexcept
Initialize when the other side's public key is received.