SHA1, SHA2 and BASE64 algorithms implemented as C++23 modules.
The project uses tester for testing and C++ Builder (CB.sh) for building. To build and run tests:
./tools/CB.sh testYou can add extra compiler flags using the -X or --extra-flags option:
./tools/CB.sh -X "-march=native -funroll-loops" release build
./tools/CB.sh --extra-flags "-march=native" release testImport the cryptic module and use the algorithms:
Example #1 - SHA1 Base64
import std;
import cryptic;
auto test1 = "The quick brown fox jumps over the lazy dog"s;
std::cout << cryptic::sha1::base64(test1) << std::endl;Example #2 - SHA256 Hexadecimal
import std;
import cryptic;
auto test2 = "The quick brown fox jumps over the lazy dog"s;
std::cout << cryptic::sha256::hexadecimal(test2) << std::endl;Example #3 - Base64 Encode
import std;
import cryptic;
auto test3 = cryptic::base64::encode("Man"s);
std::cout << test3 << std::endl;Example #4 - Base64 Decode
import std;
import cryptic;
auto test4 = cryptic::base64::decode(test3);
std::cout << test4 << std::endl;The project includes a performance benchmark comparing cryptic implementations against OpenSSL's EVP API. The benchmark tests SHA1 and SHA256 algorithms across different message sizes.
Build and run the benchmark in release mode:
./tools/CB.sh release test
./build-darwin-release/bin/benchmarkThe benchmark tests three message sizes (small: 43 bytes, medium: 782 bytes, large: 8294 bytes) with 100,000 iterations per test. Results show:
SHA1 Performance:
- Small messages:
crypticis ~2.5-3.6x faster than OpenSSL - Medium messages: OpenSSL is ~2.3-2.4x faster than
cryptic - Large messages: OpenSSL is ~3.5-3.6x faster than
cryptic
SHA256 Performance:
- Small messages:
crypticis ~1.1-1.5x faster than OpenSSL - Medium messages: OpenSSL is ~5.3-5.4x faster than
cryptic - Large messages: OpenSSL is ~8.0-8.1x faster than
cryptic
- The benchmark uses OpenSSL 3.0's modern EVP API for fair comparison
crypticperforms best on small messages, making it suitable for applications that primarily hash short strings- For large message hashing, OpenSSL's optimized implementations show significant performance advantages
- The benchmark uses realistic, varied test data rather than repetitive patterns
Recent optimizations include:
- Loop unrolling: Extensive unrolling of word loading, expansion, and compression loops
- Compiler hints: Hot function attributes and always-inline hints for critical paths
- Small message optimization: Special-casing for single-chunk messages to avoid loop overhead
- Memory access patterns: Prefetching, restrict pointers, and cache-aligned data structures
- Template-based unrolling: Compile-time unrolling of hexadecimal encoding loops