mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-21 14:00:51 +03:00
openssl: initialise the digest context before calling EVP_DigestInit()
When using the OpenSSL libraries in FIPS mode, the function call EVP_DigestInit() is actually #defined to FIPS_digestinit(). Unfortunately wheres EVP_DigestInit() initialises the context and then calls EVP_DigestInit_ex(), this function assumes that the context has been pre-initialised and crashes when it isn't. Bug: https://trac.libssh2.org/ticket/279 Fixes #279
This commit is contained in:
committed by
Kamil Dudka
parent
d808080daf
commit
61df22c460
@@ -507,23 +507,39 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
||||
}
|
||||
#endif /* LIBSSH_DSA */
|
||||
|
||||
int
|
||||
libssh2_sha1_init(libssh2_sha1_ctx *ctx)
|
||||
{
|
||||
EVP_MD_CTX_init(ctx);
|
||||
return EVP_DigestInit(ctx, EVP_get_digestbyname("sha1"));
|
||||
}
|
||||
|
||||
void
|
||||
libssh2_sha1(const unsigned char *message, unsigned long len,
|
||||
unsigned char *out)
|
||||
{
|
||||
EVP_MD_CTX ctx;
|
||||
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
EVP_DigestInit(&ctx, EVP_get_digestbyname("sha1"));
|
||||
EVP_DigestUpdate(&ctx, message, len);
|
||||
EVP_DigestFinal(&ctx, out, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
libssh2_md5_init(libssh2_md5_ctx *ctx)
|
||||
{
|
||||
EVP_MD_CTX_init(ctx);
|
||||
return EVP_DigestInit(ctx, EVP_get_digestbyname("md5"));
|
||||
}
|
||||
|
||||
void
|
||||
libssh2_md5(const unsigned char *message, unsigned long len,
|
||||
unsigned char *out)
|
||||
{
|
||||
EVP_MD_CTX ctx;
|
||||
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
EVP_DigestInit(&ctx, EVP_get_digestbyname("md5"));
|
||||
EVP_DigestUpdate(&ctx, message, len);
|
||||
EVP_DigestFinal(&ctx, out, NULL);
|
||||
|
||||
Reference in New Issue
Block a user