Electroneum
Loading...
Searching...
No Matches
hw::trezor::protocol::crypto::chacha Namespace Reference

Functions

void decrypt (const void *ciphertext, size_t length, const uint8_t *key, const uint8_t *iv, char *plaintext, size_t *plaintext_len)

Variables

const unsigned IV_SIZE = 12
const unsigned TAG_SIZE = 16

Function Documentation

◆ decrypt()

void hw::trezor::protocol::crypto::chacha::decrypt ( const void * ciphertext,
size_t length,
const uint8_t * key,
const uint8_t * iv,
char * plaintext,
size_t * plaintext_len = nullptr )

Chacha20Poly1305 decryption with tag verification. RFC 7539.

Definition at line 120 of file protocol.cpp.

120 {
121 CHECK_AND_ASSERT_THROW_MES(length >= TAG_SIZE, "Ciphertext length too small");
122 CHECK_AND_ASSERT_THROW_MES(!plaintext_len || *plaintext_len >= (length - TAG_SIZE), "Plaintext length too small");
123
124 unsigned long long int res_len = plaintext_len ? *plaintext_len : length;
125 auto r = crypto_aead_chacha20poly1305_ietf_decrypt(
126 reinterpret_cast<unsigned char *>(plaintext), &res_len, nullptr,
127 static_cast<const unsigned char *>(ciphertext), length, nullptr, 0, iv, key);
128
129 if (r != 0){
131 }
132
133 if (plaintext_len){
134 *plaintext_len = (size_t) res_len;
135 }
136 }
const char * key
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Here is the caller graph for this function:

Variable Documentation

◆ IV_SIZE

const unsigned hw::trezor::protocol::crypto::chacha::IV_SIZE = 12

Definition at line 96 of file protocol.hpp.

◆ TAG_SIZE

const unsigned hw::trezor::protocol::crypto::chacha::TAG_SIZE = 16

Definition at line 97 of file protocol.hpp.