1
1

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>
Этот коммит содержится в:
Dirkjan Bussink 2020-12-12 17:10:37 +01:00 коммит произвёл Jakub Jelen
родитель 6f934cc488
Коммит ba88e0fba5
2 изменённых файлов: 20 добавлений и 21 удалений

Просмотреть файл

@ -236,7 +236,11 @@ int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
EVP_MD_CTX *EVP_MD_CTX_new(void)
{
return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
EVP_MD_CTX *ctx = OPENSSL_zalloc(sizeof(EVP_MD_CTX));
if (ctx != NULL) {
EVP_MD_CTX_init(ctx);
}
return ctx;
}
static void OPENSSL_clear_free(void *str, size_t num)

Просмотреть файл

@ -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