Use OpenSSL EVP API for hashing#15500
Open
randomizedcoder wants to merge 1 commit intoNixOS:masterfrom
Open
Conversation
Replace deprecated low-level hash functions (MD5_Init, SHA256_Update, etc.) with the EVP digest API (EVP_DigestInit_ex, EVP_DigestUpdate, EVP_DigestFinal_ex). The EVP API is the recommended interface since OpenSSL 1.1.0 and routes through the provider system. Nix already requires OpenSSL >= 1.1.1. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace deprecated low-level OpenSSL hash functions (
MD5_Init/SHA256_Update/SHA512_Final/etc.) with the EVP digest API (EVP_DigestInit_ex,EVP_DigestUpdate,EVP_DigestFinal_ex).MD5_*,SHA1_*,SHA256_*,SHA512_*) are deprecated in OpenSSL 3.xmeson.build)Changes
Single file modified:
src/libutil/hash.ccIncludes
<openssl/md5.h>,<openssl/sha.h><openssl/evp.h>Hash context union
Replaced four algorithm-specific context structs with a single
EVP_MD_CTX *pointer:Added
getEVPAlgo()helper to mapHashAlgorithmenum to EVP algorithm objects.Init / Update / Final
Replaced per-algorithm if/else chains with unified EVP calls:
start():EVP_MD_CTX_new()+EVP_DigestInit_ex()update():EVP_DigestUpdate()finish():EVP_DigestFinal_ex()+EVP_MD_CTX_free()BLAKE3 paths are unchanged (it doesn't use OpenSSL).
HashSink lifetime management
Since
EVP_MD_CTX *is heap-allocated (unlike the old value-type structs):nix::finish()frees itEVP_MD_CTX_copy_ex()to snapshot the digest state (can't memcpy an opaque EVP context)Test plan
Formatting
nix develop -c ./maintainers/format.sh— passes clean (clang-format, meson-format, nixfmt, shellcheck)Build
meson setup build --buildtype=debugoptimized && ninja -C build— 508/508 targets)meson.build,meson.options, orpackage.nix—libcryptoalready provides<openssl/evp.h>Unit tests (22/22 hash tests pass)
BLAKE3HashTest.testKnownBLAKE3Hashes{1,2,3}— BLAKE3 known-vector testshashString.testKnownMD5Hashes{1,2}— MD5 known-vector testshashString.testKnownSHA1Hashes{1,2}— SHA-1 known-vector testshashString.testKnownSHA256Hashes{1,2}— SHA-256 known-vector testshashString.testKnownSHA512Hashes{1,2}— SHA-512 known-vector testshashParseExplicitFormatUnprefixed— parse/format round-trip testshashFormat.testRoundTripPrintParse— hash format serializationHashJSONandBLAKE3HashJSON— JSON serialization round-tripsFunctional tests (125/125 pass, 5 skipped for unrelated reasons)
nix-functional-tests:main / hash-convert—nix hash convertCLInix-functional-tests:main / hash-path—nix hash pathCLInix-functional-tests:main / path-from-hash-part— store path hash resolutionnix-functional-tests:git-hashing / simple-sha1— git SHA-1 hashingnix-functional-tests:git-hashing / simple-sha256— git SHA-256 hashingnix-functional-tests:git-hashing / fixed— fixed-output derivation hashingManual verification
nix hash fileoutput for MD5, SHA-1, SHA-256, SHA-512 matches coreutils (md5sum,sha1sum,sha256sum,sha512sum) byte-for-byte🤖 Generated with Claude Code