libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
cryptoutils.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
2// SPDX-License-Identifier: LGPL-2.0-or-later
3
4#pragma once
5
6#include "e2ee_common.h"
7#include <expected>
8
9namespace Quotient {
10
11// Common remark: OpenSSL is a private dependency of libQuotient, meaning that
12// headers of libQuotient can't include OpenSSL headers. Instead, alias
13// the value or type along with a comment (see SslErrorCode e.g.) and add
14// static_assert in the .cpp file to check it against the OpenSSL definition.
15
16constexpr auto Aes256KeySize = 32u;
17constexpr auto AesBlockSize = 16u; // AES_BLOCK_SIZE
18constexpr auto HmacKeySize = 32u;
19
20// NOLINTNEXTLINE(google-runtime-int): the type is copied from OpenSSL
21using SslErrorCode = unsigned long; // decltype(ERR_get_error())
22
24 SslErrorUserOffset = 128, // ERR_LIB_USER; never use this bare
27};
28
29template <typename T>
31
32inline QByteArray zeroedByteArray(QByteArray::size_type n = 32) { return { n, '\0' }; }
33
34// NOLINTNEXTLINE(google-runtime-int): the type is copied from OpenSSL
35using SslErrorCode = unsigned long; // decltype(ERR_get_error())
36
37//! Obtain a std::span<byte_t, N> looking into the passed buffer
38template <size_t N = std::dynamic_extent>
39inline auto asWritableCBytes(auto& buf)
40{
41 return _impl::spanFromBytes<byte_span_t<N>>(buf);
42}
43
44//! \brief Decrypt data using AES-CTR-256
45//!
46//! key and iv have a length of 32 bytes
50
51} // namespace Quotient
auto asWritableCBytes(auto &buf)
Obtain a std::span<byte_t, N> looking into the passed buffer.
Definition cryptoutils.h:39
@ SslPayloadTooLong
Definition cryptoutils.h:26
@ WrongDerivedKeyLength
Definition cryptoutils.h:25
@ SslErrorUserOffset
Definition cryptoutils.h:24
constexpr auto AesBlockSize
Definition cryptoutils.h:17
constexpr auto HmacKeySize
Definition cryptoutils.h:18
QByteArray zeroedByteArray(QByteArray::size_type n=32)
Definition cryptoutils.h:32
constexpr auto Aes256KeySize
Definition cryptoutils.h:16
#define QUOTIENT_API