spank-olm

WIP Do not look
git clone git://archive.git.mtrnord.blog/MTRNord/spank-olm.git
Log | Files | Refs | README | LICENSE

commit 4c21dbc122311d3524920ae9c0575ab1b51c9019
parent 5784c16682a9b9283ee6ebb95de681ff6e30911f
Author: MTRNord <mtrnord1@gmail.com>
Date:   Mon, 14 Apr 2025 19:22:04 +0200

Fix fuzzer not compiling

Diffstat:
M.clusterfuzzlite/build.sh | 12+++++-------
Minclude/account.hpp | 58+++++++++++++++++++---------------------------------------
Mmeson.build | 2+-
Msrc/account.cpp | 13++++++++++++-
4 files changed, 37 insertions(+), 48 deletions(-)

diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh @@ -2,25 +2,23 @@ export PKG_CONFIG="pkg-config --static" export PKG_CONFIG_PATH="$WORK/lib/pkgconfig" +export CPPFLAGS="-I$WORK/include" +export LDFLAGS="-L$WORK/lib" # Run as many parallel jobs as there are available CPU cores export MAKEFLAGS="-j$(nproc)" # botan pushd ../botan -./configure.py --prefix="${WORK}" --with-sanitizers -make +./configure.py --prefix="${WORK}" --without-documentation --enable-sanitizers="${SANITIZER}" --build-targets=static,shared +make -j$(nproc) all make install cp build/botan-3.pc "${PKG_CONFIG_PATH}" popd -export CPPFLAGS="-I$WORK/include" -export LDFLAGS="-L$WORK/lib" - # spank-olm meson setup build --prefix="${WORK}" --libdir=lib --prefer-static --default-library=static --buildtype=debugoptimized \ - -Dfuzzing_engine=oss-fuzz -Dfuzzer_ldflags="$LIB_FUZZING_ENGINE" -Db_lto=false -Db_thinlto_cache=false -Dbuild_tests=false \ - -Dcpp_link_args="$LDFLAGS -Wl,-rpath=\$ORIGIN" + -Dfuzzing_engine=oss-fuzz -Dfuzzer_ldflags="$LIB_FUZZING_ENGINE" -Db_lto=false -Db_thinlto_cache=false -Dbuild_tests=false meson install -C build --tag devel # Copy fuzz executables to $OUT diff --git a/include/account.hpp b/include/account.hpp @@ -1,9 +1,9 @@ #pragma once -#include <numeric> -#include <botan/x25519.h> -#include <botan/ed25519.h> #include <botan/base64.h> +#include <botan/ed25519.h> +#include <botan/x25519.h> +#include <numeric> #include "list.hpp" @@ -27,7 +27,8 @@ namespace spank_olm Botan::Ed25519_PrivateKey ed25519_key; ///< The Ed25519 key pair for signing. The public key can be obtained using the public_key() method. Botan::X25519_PrivateKey curve25519_key; - ///< The Curve25519 key pair for encryption and key exchange. The public key can be obtained using the public_key() method. + ///< The Curve25519 key pair for encryption and key exchange. The public key can be obtained using the + ///< public_key() method. }; /** @@ -46,11 +47,9 @@ namespace spank_olm struct Account { - Account() : next_one_time_key_id(0) - { - } + Account() : next_one_time_key_id(0) {} - Account(Account const& other) = default; + Account(Account const &other) = default; std::optional<IdentityKeys> identity_keys; ///< The identity keys for the account. FixedSizeArray<OneTimeKey, MAX_ONE_TIME_KEYS> one_time_keys; ///< The one-time keys for the account. @@ -65,7 +64,7 @@ namespace spank_olm * \return The result of the operation. * \throws SpankOlmErrorKeyGeneration if the key generation fails. */ - void new_account(Botan::RandomNumberGenerator& rng); + void new_account(Botan::RandomNumberGenerator &rng); /** * \brief Output the identity keys for this account as JSON. @@ -81,17 +80,7 @@ namespace spank_olm * * \return The JSON representation of the identity keys. */ - [[nodiscard]] EMSCRIPTEN_CONSTEXPR std::string get_identity_json() const - { - auto curve25519_key = identity_keys->curve25519_key.public_key()->raw_public_key_bits(); - auto ed25519_key = identity_keys->ed25519_key.public_key()->raw_public_key_bits(); - - const auto curve25519_base64 = Botan::base64_encode(curve25519_key); - const auto ed25519_base64 = Botan::base64_encode(ed25519_key); - - return R"({"curve25519": ")" + curve25519_base64 + - R"(", "ed25519": ")" + ed25519_base64 + "\"}"; - } + [[nodiscard]] std::string get_identity_json() const; /** * \brief Signs a message using the Ed25519 key. @@ -100,7 +89,7 @@ namespace spank_olm * \param message The message to sign. * \return The signature of the message. */ - [[nodiscard]] std::vector<uint8_t> sign(Botan::RandomNumberGenerator& rng, std::string_view message) const; + [[nodiscard]] std::vector<uint8_t> sign(Botan::RandomNumberGenerator &rng, std::string_view message) const; /** @@ -124,7 +113,7 @@ namespace spank_olm { std::vector<std::string> stringified_keys; - for (const auto& key : one_time_keys) + for (const auto &key : one_time_keys) { if (!key->published) { @@ -135,10 +124,7 @@ namespace spank_olm const std::string keys_json = std::accumulate( stringified_keys.begin(), stringified_keys.end(), std::string(), - [](const std::string& acc, const std::string& key) - { - return acc.empty() ? key : acc + ", " + key; - }); + [](const std::string &acc, const std::string &key) { return acc.empty() ? key : acc + ", " + key; }); return R"({"curve25519": {)" + keys_json + "}}"; } @@ -162,10 +148,7 @@ namespace spank_olm * * \return The maximum number of one-time keys. */ - [[nodiscard]] static constexpr std::size_t max_number_of_one_time_keys() - { - return MAX_ONE_TIME_KEYS; - } + [[nodiscard]] static constexpr std::size_t max_number_of_one_time_keys() { return MAX_ONE_TIME_KEYS; } /** * \brief Generates a number of new one-time keys. @@ -174,12 +157,12 @@ namespace spank_olm * stored by this account exceeds max_number_of_one_time_keys() then the * old keys are discarded. */ - void generate_one_time_keys(Botan::RandomNumberGenerator& rng, std::size_t number_of_keys); + void generate_one_time_keys(Botan::RandomNumberGenerator &rng, std::size_t number_of_keys); /** * \brief Generates a new fallback key. */ - void generate_fallback_key(Botan::RandomNumberGenerator& rng); + void generate_fallback_key(Botan::RandomNumberGenerator &rng); /** * \brief Output the currentöy unpublished fallback key as JSON. @@ -215,18 +198,15 @@ namespace spank_olm /** * \brief Lookup a one time key with the given public key */ - [[nodiscard]] std::optional<OneTimeKey const*> lookup_key(Botan::Public_Key const& key) const; + [[nodiscard]] std::optional<OneTimeKey const *> lookup_key(Botan::Public_Key const &key) const; /** * \brief Remove a one time key with the given public key */ - void remove_key(Botan::Public_Key const& key); + void remove_key(Botan::Public_Key const &key); [[nodiscard]] std::vector<uint8_t> pickle() const; - static Account unpickle(std::vector<uint8_t> const& data); + static Account unpickle(std::vector<uint8_t> const &data); }; -} - - - +} // namespace spank_olm diff --git a/meson.build b/meson.build @@ -2,7 +2,7 @@ project('spank-olm', 'c', 'cpp', version : '1.0.0', default_options : [ 'c_std=c11', - 'cpp_std=c++23', + 'cpp_std=c++20', 'b_lto=true', 'b_thinlto_cache=true', 'warning_level=3', diff --git a/src/account.cpp b/src/account.cpp @@ -7,7 +7,6 @@ namespace spank_olm { - void Account::new_account(Botan::RandomNumberGenerator &rng) { identity_keys = IdentityKeys{Botan::Ed25519_PrivateKey(rng), Botan::X25519_PrivateKey(rng)}; @@ -21,6 +20,18 @@ namespace spank_olm } } + + [[nodiscard]] std::string Account::get_identity_json() const + { + auto curve25519_key = identity_keys->curve25519_key.public_key()->raw_public_key_bits(); + auto ed25519_key = identity_keys->ed25519_key.public_key()->raw_public_key_bits(); + + const auto curve25519_base64 = Botan::base64_encode(curve25519_key); + const auto ed25519_base64 = Botan::base64_encode(ed25519_key); + + return R"({"curve25519": ")" + curve25519_base64 + R"(", "ed25519": ")" + ed25519_base64 + "\"}"; + } + std::vector<uint8_t> Account::sign(Botan::RandomNumberGenerator &rng, const std::string_view message) const { // According to https://botan.randombit.net/handbook/api_ref/pubkey.html#ed25519-ed448-variants