The BIP324 packet cipher, encapsulating its key derivation, stream cipher, and AEAD.
More...
#include <bip324.h>
|
| BIP324Cipher ()=delete |
| No default constructor; keys must be provided to create a BIP324Cipher. More...
|
|
| BIP324Cipher (const CKey &key, Span< const std::byte > ent32) noexcept |
| Initialize a BIP324 cipher with specified key and encoding entropy (testing only). More...
|
|
| BIP324Cipher (const CKey &key, const EllSwiftPubKey &pubkey) noexcept |
| Initialize a BIP324 cipher with specified key (testing only). More...
|
|
const EllSwiftPubKey & | GetOurPubKey () const noexcept |
| Retrieve our public key. More...
|
|
void | Initialize (const EllSwiftPubKey &their_pubkey, bool initiator, bool self_decrypt=false) noexcept |
| Initialize when the other side's public key is received. More...
|
|
| operator bool () const noexcept |
| Determine whether this cipher is fully initialized. More...
|
|
void | Encrypt (Span< const std::byte > contents, Span< const std::byte > aad, bool ignore, Span< std::byte > output) noexcept |
| Encrypt a packet. More...
|
|
unsigned | DecryptLength (Span< const std::byte > input) noexcept |
| Decrypt the length of a packet. More...
|
|
bool | Decrypt (Span< const std::byte > input, Span< const std::byte > aad, bool &ignore, Span< std::byte > contents) noexcept |
| Decrypt a packet. More...
|
|
Span< const std::byte > | GetSessionID () const noexcept |
| Get the Session ID. More...
|
|
Span< const std::byte > | GetSendGarbageTerminator () const noexcept |
| Get the Garbage Terminator to send. More...
|
|
Span< const std::byte > | GetReceiveGarbageTerminator () const noexcept |
| Get the expected Garbage Terminator to receive. More...
|
|
The BIP324 packet cipher, encapsulating its key derivation, stream cipher, and AEAD.
Definition at line 19 of file bip324.h.
◆ BIP324Cipher() [1/3]
BIP324Cipher::BIP324Cipher |
( |
| ) |
|
|
delete |
No default constructor; keys must be provided to create a BIP324Cipher.
◆ BIP324Cipher() [2/3]
BIP324Cipher::BIP324Cipher |
( |
const CKey & |
key, |
|
|
Span< const std::byte > |
ent32 |
|
) |
| |
|
noexcept |
Initialize a BIP324 cipher with specified key and encoding entropy (testing only).
Definition at line 25 of file bip324.cpp.
◆ BIP324Cipher() [3/3]
Initialize a BIP324 cipher with specified key (testing only).
Definition at line 31 of file bip324.cpp.
◆ Decrypt()
bool BIP324Cipher::Decrypt |
( |
Span< const std::byte > |
input, |
|
|
Span< const std::byte > |
aad, |
|
|
bool & |
ignore, |
|
|
Span< std::byte > |
contents |
|
) |
| |
|
noexcept |
Decrypt a packet.
Only after Initialize().
It must hold that input.size() + LENGTH_LEN == contents.size() + EXPANSION. Contents.size() must equal the length returned by DecryptLength.
Definition at line 100 of file bip324.cpp.
◆ DecryptLength()
uint32_t BIP324Cipher::DecryptLength |
( |
Span< const std::byte > |
input | ) |
|
|
noexcept |
Decrypt the length of a packet.
Only after Initialize().
It must hold that input.size() == LENGTH_LEN.
Definition at line 89 of file bip324.cpp.
◆ Encrypt()
void BIP324Cipher::Encrypt |
( |
Span< const std::byte > |
contents, |
|
|
Span< const std::byte > |
aad, |
|
|
bool |
ignore, |
|
|
Span< std::byte > |
output |
|
) |
| |
|
noexcept |
Encrypt a packet.
Only after Initialize().
It must hold that output.size() == contents.size() + EXPANSION.
Definition at line 73 of file bip324.cpp.
◆ GetOurPubKey()
Retrieve our public key.
Definition at line 54 of file bip324.h.
◆ GetReceiveGarbageTerminator()
Span< const std::byte > BIP324Cipher::GetReceiveGarbageTerminator |
( |
| ) |
const |
|
inlinenoexcept |
Get the expected Garbage Terminator to receive.
Only after Initialize().
Definition at line 93 of file bip324.h.
◆ GetSendGarbageTerminator()
Span< const std::byte > BIP324Cipher::GetSendGarbageTerminator |
( |
| ) |
const |
|
inlinenoexcept |
◆ GetSessionID()
Span< const std::byte > BIP324Cipher::GetSessionID |
( |
| ) |
const |
|
inlinenoexcept |
◆ Initialize()
void BIP324Cipher::Initialize |
( |
const EllSwiftPubKey & |
their_pubkey, |
|
|
bool |
initiator, |
|
|
bool |
self_decrypt = false |
|
) |
| |
|
noexcept |
Initialize when the other side's public key is received.
Can only be called once.
initiator is set to true if we are the initiator establishing the v2 P2P connection. self_decrypt is only for testing, and swaps encryption/decryption keys, so that encryption and decryption can be tested without knowing the other side's private key.
Definition at line 34 of file bip324.cpp.
◆ operator bool()
BIP324Cipher::operator bool |
( |
| ) |
const |
|
inlineexplicitnoexcept |
Determine whether this cipher is fully initialized.
Definition at line 65 of file bip324.h.
◆ EXPANSION
constexpr unsigned BIP324Cipher::EXPANSION = LENGTH_LEN + HEADER_LEN + FSChaCha20Poly1305::EXPANSION |
|
staticconstexpr |
◆ GARBAGE_TERMINATOR_LEN
constexpr unsigned BIP324Cipher::GARBAGE_TERMINATOR_LEN {16} |
|
staticconstexpr |
◆ HEADER_LEN
constexpr unsigned BIP324Cipher::HEADER_LEN {1} |
|
staticconstexpr |
◆ IGNORE_BIT
constexpr std::byte BIP324Cipher::IGNORE_BIT {0x80} |
|
staticconstexpr |
◆ LENGTH_LEN
constexpr unsigned BIP324Cipher::LENGTH_LEN {3} |
|
staticconstexpr |
◆ m_key
◆ m_our_pubkey
◆ m_recv_garbage_terminator
◆ m_recv_l_cipher
std::optional<FSChaCha20> BIP324Cipher::m_recv_l_cipher |
|
private |
◆ m_recv_p_cipher
◆ m_send_garbage_terminator
◆ m_send_l_cipher
std::optional<FSChaCha20> BIP324Cipher::m_send_l_cipher |
|
private |
◆ m_send_p_cipher
◆ m_session_id
◆ REKEY_INTERVAL
constexpr unsigned BIP324Cipher::REKEY_INTERVAL {224} |
|
staticconstexpr |
◆ SESSION_ID_LEN
constexpr unsigned BIP324Cipher::SESSION_ID_LEN {32} |
|
staticconstexpr |
The documentation for this class was generated from the following files: