7 #include "../expected.h"
9 #include "../quotient_export.h"
11 #include <QtCore/QByteArray>
12 #include <QtCore/QString>
21 constexpr auto DefaultPbkdf2KeyLength = 32u;
22 constexpr auto Aes256KeySize = 32u;
23 constexpr auto AesBlockSize = 16u;
24 constexpr auto HmacKeySize = 32u;
27 :
public FixedBuffer<Aes256KeySize + HmacKeySize> {
29 auto aes()
const {
return asCBytes(*
this).first<Aes256KeySize>(); }
31 auto mac()
const {
return asCBytes(*
this).last<HmacKeySize>(); }
35 QByteArray ciphertext;
41 using SslErrorCode =
unsigned long;
43 template <size_t Size = DefaultPbkdf2KeyLength>
44 using key_material_t = std::array<byte_t, Size>;
45 using key_view_t = byte_view_t<DefaultPbkdf2KeyLength>;
47 enum SslErrorCodes : SslErrorCode {
48 SslErrorUserOffset = 128,
49 WrongDerivedKeyLength = SslErrorUserOffset + 1,
50 SslPayloadTooLong = SslErrorUserOffset + 2
55 using SslExpected = Expected<T, SslErrorCode>;
60 inline QByteArray zeroedByteArray(QByteArray::size_type n = 32) {
return { n,
'\0' }; }
62 template <size_t N,
typename T = uint8_t> consteval std::array<T, N> zeroes() {
return {}; }
65 QUOTIENT_API SslErrorCode pbkdf2HmacSha512(
const QByteArray& passphrase,
const QByteArray& salt,
66 int iterations, byte_span_t<> output);
70 template <size_t Size = DefaultPbkdf2KeyLength>
71 QUOTIENT_API inline SslExpected<key_material_t<Size>> pbkdf2HmacSha512(
const QByteArray& passphrase,
72 const QByteArray& salt,
75 key_material_t<Size> result;
76 if (
auto code = _impl::pbkdf2HmacSha512(passphrase, salt, iterations, result); code != 0)
84 QUOTIENT_API SslExpected<HkdfKeys> hkdfSha256(key_view_t key, byte_view_t<32> salt,
89 byte_view_t<HmacKeySize> hmacKey,
90 const QByteArray& data);
95 QByteArray ciphertext,
const QByteArray& privateKey,
96 const QByteArray& ephemeral,
const QByteArray& mac);
100 QUOTIENT_API QOlmExpected<Curve25519Encrypted> curve25519AesSha2Encrypt(
101 const QByteArray& plaintext,
const QByteArray& publicKey);
107 const QByteArray& plaintext, byte_view_t<Aes256KeySize> key,
108 byte_view_t<AesBlockSize> iv);
114 const QByteArray& ciphertext, byte_view_t<Aes256KeySize> key,
115 byte_view_t<AesBlockSize> iv);
117 QUOTIENT_API std::vector<byte_t> base58Decode(
const QByteArray& encoded);
119 QUOTIENT_API QByteArray sign(
const QByteArray &key,
const QByteArray &data);