|
StormByte C++ Library: Crypto module 0.0.9999
StormByte-Crypto is a StormByte library module for handling cryptographic operations
|
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
The Crypto module provides a wide range of cryptographic utilities, including hashing, encryption, signing, compression, and key exchange. Below is a detailed breakdown of the functionality provided.
The examples below show concise, copy-pastable usage patterns used by the unit tests in test/.
Common patterns used in the examples and tests:
std::span<const std::byte> or Buffer::ReadOnly and write into Buffer::WriteOnly (return bool success).Buffer::Consumer and return a Buffer::Consumer for output (producer/consumer handoff).KeyPair::Create(...)) or call the concrete type generators directly (e.g. KeyPair::ECC::Generate(...), KeyPair::RSA::Generate(...)).Code snippets below are intentionally short; see test/ for full, real-world examples.
Compressors are created via the StormByte::Crypto::Compressor::Create factory and follow a Buffer-centric API.
Buffer::Consumer to Compress and receive a Buffer::Consumer with compressed output.The implementation uses libbzip2 for Bzip2 and Crypto++ filters for Zlib/Gzip where available.
Symmetric encryption utilities live under StormByte::Crypto::Crypter. Use the Crypter::Create factory for symmetric types and provide a password/key. The returned object follows the buffer-centric API (block + streaming).
Examples (AES-CBC / AES-GCM):
Streaming encryption mirrors compressors: pass a Buffer::Consumer to Encrypt and read from the returned Buffer::Consumer.
Key pairs live under StormByte::Crypto::KeyPair and can be created via the per-type Generate(...) static methods (recommended) or via the generic factory KeyPair::Create(Type, bits).
The asymmetric crypters are available under StormByte::Crypto::Crypter (asymmetric variants) and can be created by passing a KeyPair pointer to the asymmetric Create overload.
Examples (RSA):
Examples (ECC / ECDH note):
Hashers are provided via StormByte::Crypto::Hasher::Create (see headers) and operate on Buffer types or spans.
Examples:
Signers are created with StormByte::Crypto::Signer::Create (factory overloads accept a KeyPair pointer or reference). APIs are Buffer-oriented.
The StormByte::Crypto::Secret namespace provides key-agreement helpers (ECDH, X25519). Construct a secret helper with a KeyPair pointer (factory Secret::Create exists) or call a concrete secret class if available.
Example (ECDH):
Example (X25519):
For streaming examples, inspect test/compressors/*_test.cxx, test/aes_test.cxx, test/ecdsa_test.cxx, and friends — they demonstrate both convenience and streaming workflows used above.
The public API is organized into small logical namespaces (e.g. Hasher, Compressor, Crypter, KeyPair, Signer, Secret) and uses factory functions and buffer-oriented interfaces. Refer to the lib/public/StormByte/crypto headers for the authoritative API.
StormByte::Crypto::Hasher::Create(Type) -> returns a Hasher::Generic::PointerType (smart pointer).StormByte::Crypto::Compressor::Create(Type, level) -> returns a Compressor::Generic::PointerType.StormByte::Crypto::KeyPair::Create(Type, bits) -> returns a KeyPair::Generic::PointerType.StormByte::Crypto::Signer::Create(Type, keypair) -> returns a Signer::Generic::PointerType.std::span<const std::byte> or Buffer::ReadOnly and write output into a Buffer::WriteOnly. They return bool to indicate success.Buffer::Consumer and return a Buffer::Consumer for the produced output. The streaming stages run in detached threads and use Producer/Consumer for handoff.Compressor (create + compress a buffer):
Streaming compressor:
cpp StormByte::Buffer::Producer p; auto input = p.Consumer(); auto outConsumer = c->Compress(input); // write to p and close; read from outConsumer
Sign/Hash/Encrypt on spans or pass Consumers for streaming.See the headers in lib/public/StormByte/crypto and the tests in test/ for concrete usage patterns.
Contributions are welcome! Please follow the guidelines in the CONTRIBUTING.md file.
This project is licensed under the MIT License. See the LICENSE file for details.