Reputation: 73
I would like to find the implementation of SHA1_Init in openssl source code.
http://osxr.org:8080/openssl/source/crypto/sha/sha1.c#0108
0108 SHA1_Init(&c);
but only definition found in http://osxr.org:8080/openssl/source/crypto/sha/sha.h#0122
Where is it? Thanks,
=SG=
Upvotes: 4
Views: 1788
Reputation: 1327784
Note: starting with Git 2.42 (Q3 2023), you would no longer find SHA1_Init(&c)
used: Git 2.42 adjusts to OpenSSL 3+, which deprecates its SHA-1 functions based on its traditional API, by using its EVP API instead.
See "What does OpenSSL's EVP (Envelope Cryptography) mean?", and "Encrypting/Decrypting a file using OpenSSL EVP" by Amit Kulkarni.
See commit bda9c12, commit 3e440ea (01 Aug 2023) by Eric Wong (ele828
).
(Merged by Junio C Hamano -- gitster
-- in commit 889c94d, 09 Aug 2023)
bda9c12073
:avoid SHA-1 functions deprecated in OpenSSL 3+Signed-off-by: Eric Wong
OpenSSL 3+ deprecates the
SHA1_Init,
SHA1_Update,
andSHA1_Final
functions, leading to errors when building with `DEVELOPER=1'.Use the newer
EVP_*
API with OpenSSL 3+ (only) despite being more error-prone and less efficient due to heap allocations.
For instance, you would now have, instead of using directly SHA1_Init(&c)
:
static inline void openssl_SHA1_Init(struct openssl_SHA1_CTX *ctx)
{
const EVP_MD *type = EVP_sha1();
ctx->ectx = EVP_MD_CTX_new();
if (!ctx->ectx)
die("EVP_MD_CTX_new: out of memory");
EVP_DigestInit_ex(ctx->ectx, type, NULL);
}
With EVP_DigestInit_ex()
being defined in openssl/openssl
crypto/evp/digest.c
Upvotes: 0
Reputation: 8065
So SHA1_Init
is defined in the header of sha_locl.h
as HASH_INIT
. sha1dgst.c
includes sha_locl.h
which includes ../md32_common.h
which does the expansion of HASH_UPDATE
, HASH_TRANFORM
, and HASH_FINAL
which is defined as SHA1_Init
in sha.h
. I believe the actual implementation though of SHA1_Init
is ultimately here: http://osxr.org:8080/openssl/source/crypto/sha/sha_locl.h#0125 or here on github: https://github.com/openssl/openssl/blob/master/crypto/sha/sha_locl.h#L101.
Upvotes: 1