v4.0.1
Highlights
Patch release focused on security fixes, memory safety improvements, and binary hardening.
Security Fixes
- Fixed timing side-channel in
validate_totp_in_window: comparison now usesmin(gen_len, user_len)bytes to prevent reading past buffer bounds when lengths differ - Normalized secret key is now zeroed with
cotp_secure_memzerobefore freeing incompute_hmac - Fixed memory leak in OpenSSL backend:
EVP_MACnot freed whencallocfails inwhmac_gethandle - Fixed memory leak in OpenSSL backend:
EVP_MAC_CTXnot freed inwhmac_freehandleand on buffer-too-small error path inwhmac_finalize - Added negative algorithm index validation (
algo < 0) in all three HMAC backends (gcrypt, OpenSSL, MbedTLS)
Hardening
- All public symbols now use explicit
__attribute__((visibility("default"))); library compiled with-fvisibility=hiddento minimize exported symbol surface - Added linker hardening flags: full RELRO (
-Wl,-z,relro,-z,now) and non-executable stack (-Wl,-z,noexecstack) REVERSE_BYTESmacro wrapped indo { ... } while (0)for safe use in all statement contexts- CMake now detects
explicit_bzeroat configure time viacheck_function_exists
Improvements
- Base32 validation (
valid_b32_str) now enforces RFC 4648 padding rules: rejects data characters after padding, validates padding count (0, 1, 3, 4, or 6), and requires padded strings to have length divisible by 8 check_inputmax_lenparameter changed fromint32_ttosize_tfor type correctness
Tests
- Significantly expanded test coverage: OTP edge cases, Base32 decode corner cases, and new TOTP window validation tests
Documentation
- Updated README examples to use
COTP_SHA1/COTP_SHA256/COTP_SHA512constants (renamed in v4.0.0)
sha256: f8c843004d18880eb41417853fcfc3855f6197e7a32dcd87d23a6609cf0a116a