aboutsummaryrefslogtreecommitdiff
path: root/src/libcrypto.c
diff options
context:
space:
mode:
authorDirkjan Bussink <d.bussink@gmail.com>2020-12-12 17:10:37 +0100
committerJakub Jelen <jjelen@redhat.com>2021-01-11 10:45:22 +0100
commitba88e0fba5fcb73db395193e958402ffe4cad88a (patch)
treef439f4e1611fe018d2b29b4e14ba995089a85065 /src/libcrypto.c
parent6f934cc488b9fb2162ea701e6e829e5d5a8d5fb1 (diff)
downloadlibssh-ba88e0fba5fcb73db395193e958402ffe4cad88a.tar.gz
libssh-ba88e0fba5fcb73db395193e958402ffe4cad88a.tar.xz
libssh-ba88e0fba5fcb73db395193e958402ffe4cad88a.zip
Use current OpenSSL API as the example
EVP_MD_CTX_new / EVP_MD_CTX_free is the current recommended / documented API. The other names are defined as aliases for backwards compatibility. The other part here is that EVP_MD_CTX_init is not needed for a context allocated with EVP_MD_CTX_new. Only for the compatibility path for older OpenSSL is the init needed if the structure is allocated directly. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'src/libcrypto.c')
-rw-r--r--src/libcrypto.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/libcrypto.c b/src/libcrypto.c
index edfd799b..0dc103c3 100644
--- a/src/libcrypto.c
+++ b/src/libcrypto.c
@@ -118,14 +118,13 @@ int ssh_get_random(void *where, int len, int strong)
SHACTX sha1_init(void)
{
int rc;
- SHACTX c = EVP_MD_CTX_create();
+ SHACTX c = EVP_MD_CTX_new();
if (c == NULL) {
return NULL;
}
- EVP_MD_CTX_init(c);
rc = EVP_DigestInit_ex(c, EVP_sha1(), NULL);
if (rc == 0) {
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
c = NULL;
}
return c;
@@ -141,7 +140,7 @@ void sha1_final(unsigned char *md, SHACTX c)
unsigned int mdlen = 0;
EVP_DigestFinal(c, md, &mdlen);
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
}
void sha1(const unsigned char *digest, int len, unsigned char *hash)
@@ -210,14 +209,13 @@ void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen)
SHA256CTX sha256_init(void)
{
int rc;
- SHA256CTX c = EVP_MD_CTX_create();
+ SHA256CTX c = EVP_MD_CTX_new();
if (c == NULL) {
return NULL;
}
- EVP_MD_CTX_init(c);
rc = EVP_DigestInit_ex(c, EVP_sha256(), NULL);
if (rc == 0) {
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
c = NULL;
}
return c;
@@ -233,7 +231,7 @@ void sha256_final(unsigned char *md, SHA256CTX c)
unsigned int mdlen = 0;
EVP_DigestFinal(c, md, &mdlen);
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
}
void sha256(const unsigned char *digest, int len, unsigned char *hash)
@@ -248,14 +246,13 @@ void sha256(const unsigned char *digest, int len, unsigned char *hash)
SHA384CTX sha384_init(void)
{
int rc;
- SHA384CTX c = EVP_MD_CTX_create();
+ SHA384CTX c = EVP_MD_CTX_new();
if (c == NULL) {
return NULL;
}
- EVP_MD_CTX_init(c);
rc = EVP_DigestInit_ex(c, EVP_sha384(), NULL);
if (rc == 0) {
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
c = NULL;
}
return c;
@@ -271,7 +268,7 @@ void sha384_final(unsigned char *md, SHA384CTX c)
unsigned int mdlen = 0;
EVP_DigestFinal(c, md, &mdlen);
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
}
void sha384(const unsigned char *digest, int len, unsigned char *hash)
@@ -286,14 +283,13 @@ void sha384(const unsigned char *digest, int len, unsigned char *hash)
SHA512CTX sha512_init(void)
{
int rc = 0;
- SHA512CTX c = EVP_MD_CTX_create();
+ SHA512CTX c = EVP_MD_CTX_new();
if (c == NULL) {
return NULL;
}
- EVP_MD_CTX_init(c);
rc = EVP_DigestInit_ex(c, EVP_sha512(), NULL);
if (rc == 0) {
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
c = NULL;
}
return c;
@@ -309,7 +305,7 @@ void sha512_final(unsigned char *md, SHA512CTX c)
unsigned int mdlen = 0;
EVP_DigestFinal(c, md, &mdlen);
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
}
void sha512(const unsigned char *digest, int len, unsigned char *hash)
@@ -324,14 +320,13 @@ void sha512(const unsigned char *digest, int len, unsigned char *hash)
MD5CTX md5_init(void)
{
int rc;
- MD5CTX c = EVP_MD_CTX_create();
+ MD5CTX c = EVP_MD_CTX_new();
if (c == NULL) {
return NULL;
}
- EVP_MD_CTX_init(c);
rc = EVP_DigestInit_ex(c, EVP_md5(), NULL);
if(rc == 0) {
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
c = NULL;
}
return c;
@@ -347,7 +342,7 @@ void md5_final(unsigned char *md, MD5CTX c)
unsigned int mdlen = 0;
EVP_DigestFinal(c, md, &mdlen);
- EVP_MD_CTX_destroy(c);
+ EVP_MD_CTX_free(c);
}
#ifdef HAVE_OPENSSL_EVP_KDF_CTX_NEW_ID