Skip to content

Commit

Permalink
Merge pull request #240 from botovq/hash
Browse files Browse the repository at this point in the history
Don't rely on libcrypto returning static buffers
  • Loading branch information
wtoorop authored May 31, 2024
2 parents 2c7d392 + 86629fe commit 4137510
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dnssec_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ ldns_rdf *
ldns_sign_public_dsa(ldns_buffer *to_sign, DSA *key)
{
#ifdef USE_DSA
unsigned char md[EVP_MAX_MD_SIZE];
unsigned char *sha1_hash;
ldns_rdf *sigdata_rdf;
ldns_buffer *b64sig;
Expand All @@ -347,7 +348,7 @@ ldns_sign_public_dsa(ldns_buffer *to_sign, DSA *key)
}

sha1_hash = SHA1((unsigned char*)ldns_buffer_begin(to_sign),
ldns_buffer_position(to_sign), NULL);
ldns_buffer_position(to_sign), md);
if (!sha1_hash) {
ldns_buffer_free(b64sig);
return NULL;
Expand Down Expand Up @@ -571,6 +572,7 @@ ldns_sign_public_evp(ldns_buffer *to_sign,
ldns_rdf *
ldns_sign_public_rsasha1(ldns_buffer *to_sign, RSA *key)
{
unsigned char md[EVP_MAX_MD_SIZE];
unsigned char *sha1_hash;
unsigned int siglen;
ldns_rdf *sigdata_rdf;
Expand All @@ -584,7 +586,7 @@ ldns_sign_public_rsasha1(ldns_buffer *to_sign, RSA *key)
}

sha1_hash = SHA1((unsigned char*)ldns_buffer_begin(to_sign),
ldns_buffer_position(to_sign), NULL);
ldns_buffer_position(to_sign), md);
if (!sha1_hash) {
ldns_buffer_free(b64sig);
return NULL;
Expand All @@ -607,6 +609,7 @@ ldns_sign_public_rsasha1(ldns_buffer *to_sign, RSA *key)
ldns_rdf *
ldns_sign_public_rsamd5(ldns_buffer *to_sign, RSA *key)
{
unsigned char md[EVP_MAX_MD_SIZE];
unsigned char *md5_hash;
unsigned int siglen;
ldns_rdf *sigdata_rdf;
Expand All @@ -618,7 +621,7 @@ ldns_sign_public_rsamd5(ldns_buffer *to_sign, RSA *key)
}

md5_hash = MD5((unsigned char*)ldns_buffer_begin(to_sign),
ldns_buffer_position(to_sign), NULL);
ldns_buffer_position(to_sign), md);
if (!md5_hash) {
ldns_buffer_free(b64sig);
return NULL;
Expand Down

0 comments on commit 4137510

Please sign in to comment.