3.7 KiB
3.7 KiB
Crypto Hardening, Signing, MAC/KDF & Optional Async Hash Adapter
Task ID: M-CRYPTO-01..05 Phase: P2 (Wave 6B) Status: APPROVED Contracts: C-02, C-03, C-07, C-13
1. Context and baseline
Void::Crypto preserves all 1.x APIs (Hasher, Digest, HashAlgorithm, hash, hashFile, sha1/sha256/sha512, sha*File, verifyEd25519 exact-byte false-vs-error semantics) while hardening Hasher state poisoning (Ready -> Updating -> Finalized | Failed), adding per-context OpenSSL 3 ProviderOptions (no process-wide provider mutation), typed Ed25519 wrappers (Ed25519PublicKey, Ed25519Signature, Ed25519Seed, move-only Ed25519PrivateKey), sign_ed25519, hmac_sha256/hmac_sha256_into, hkdf_sha256, constant_time_equal, backend fault injection, and a separate optional CryptoAsync module (hash_stream, AsyncFileHasher) so Crypto remains runtime-free.
2. Deliverables
src/Crypto/module.cmake(INTERNAL_DEPS Functional,EXTERNAL_DEPS OpenSSL::Crypto,EXCLUDE_HEADERS Void/Crypto/AsyncHash.hpp) &src/CryptoAsync/module.cmake(INTERNAL_DEPS Crypto IO Async Time Functional,EXTRA_HEADERS Void/Crypto/AsyncHash.hpp).include/Void/Crypto/Types.hpp:kCryptoErrorDomain = 18,CryptoErrorCode,make_crypto_error,HasherState,ProviderOptions,CryptoLimits(kMaxOneShotMessageBytes = 16 MiB,kMaxHkdfOutputBytes = 4 KiB,kStreamChunkBytes = 64 KiB,kDefaultMaxConcurrentFileHashes = 8,kDefaultMaxWaitingFileHashes = 32,kDefaultAsyncBufferBudgetBytes = 8 MiB),Ed25519PublicKey,Ed25519Signature,Ed25519Seed(with explicit wipe).include/Void/Crypto/Crypto.hpp&src/Crypto/Crypto.cpp: OpenSSL 3 non-deprecated EVP APIs (EVP_MD_fetch,EVP_MAC_fetch,EVP_KDF_fetch,EVP_PKEY_new_raw_*_ex,EVP_DigestSignInit_ex,EVP_DigestVerifyInit_ex,CRYPTO_memcmp,OPENSSL_cleanse), poisonedHasher+state(),Ed25519PrivateKey(generate,from_raw_seed,public_key,export_raw_seed),sign_ed25519, typedverify_ed25519,hmac_sha256,hmac_sha256_into,hkdf_sha256(4 KiB cap, overlap rejection, wipe-on-error),constant_time_equal, and thread-local/scoped backend fault hook.include/Void/Crypto/AsyncHash.hpp&src/CryptoAsync/AsyncHash.cpp:hash_stream(64 KiBBufferLeasechunks, stop/deadline checks between chunks, clean-EOF-only finalize) andAsyncFileHasher(8 concurrent / 32 waiters / 8 MiB buffer budget,close_and_join).tests/standalone/Crypto/CryptoHardening.cpp,tests/standalone/CryptoAsync/CryptoAsync.cpp,tests/package/{CryptoOnly,CryptoAsyncOnly}/*, registered intests/package/InstalledComponents.cmake.
3. Edge cases
- Invalid key/signature sizes return
invalid_argumentbefore touching OpenSSL; well-formed invalid Ed25519 signatures returntrue/false(not error). - One-shot
sign_ed25519/verify_ed25519enforce16 MiBlimit;hkdf_sha256rejects zero/oversized (> 4 KiB) output and overlapping input/salt/context/output spans, wiping output on failure. - Backend error during
Hasher::update/finalizetransitions state toFailed, rejecting furtherupdate/finalizecalls. hash_streamnever returns a digest on partial read + error or stop/EOF cancellation race;AsyncFileHasher::close_and_joinstops admission and drains in-flight work before returning.
4. Verification commands
dev cpp-gcc -p openssl -c bash -lc 'cmake -S . -B /tmp/void-w6b-crypto -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOID_ENABLED_MODULES="Crypto;CryptoAsync;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w6b-crypto && /tmp/void-w6b-crypto/tests/VoidTests --filter "Crypto*|crypto_*" && ctest --test-dir /tmp/void-w6b-crypto --output-on-failure --timeout 120'