// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® module; #ifdef NOSTRO_OPENSSL_ENABLED #include #include #endif export module Nostro:Crypto; #ifdef NOSTRO_OPENSSL_ENABLED import std; export namespace Nostro::Crypto { std::int64_t ThrowOnOpenssl(std::int64_t status); template T* ThrowOnOpenssl(T* pointer) { if(pointer == nullptr) { ERR_print_errors_fp(stderr); throw std::runtime_error("openssl error"); } return pointer; } // A key that frees itself; copies share it. using Key = std::shared_ptr; Key OwnKey(EVP_PKEY* key); // RSA PKCS#1 v1.5 over SHA-256, base64: what bunq expects in X-Bunq-Client-Signature. std::string SignBody(EVP_PKEY* privateKey, std::string_view body); // Checks a base64 signature made as SignBody makes one, with the signer's public key. bool VerifyBody(EVP_PKEY* publicKey, std::string_view body, std::string_view signature); // A new 2048-bit RSA key pair and its public half in PEM. std::tuple CreateKey(); EVP_PKEY* LoadKeyFromPem(std::string_view pem); EVP_PKEY* LoadPublicKeyFromPem(std::string_view pem); std::string PrivateKeyToPem(EVP_PKEY* key); std::string PublicKeyToPem(EVP_PKEY* key); // `bytes` random bytes from the system's CSPRNG, as lower-case hex. std::string RandomHex(std::size_t bytes); }; #endif