Skip to content

Commit

Permalink
Don't rely on libcrypto returning static buffers
Browse files Browse the repository at this point in the history
ldns is one of very few applications relying on being able to pass
NULL as last argument to the one-step hashing functions. BoringSSL
has removed this functionality in 2017 [1] and LibreSSL 4.0 will do
the same. Applications can pass in a correctly-sized buffer on the
stack.

[1]: https://boringssl-review.googlesource.com/14528
  • Loading branch information
botovq committed May 30, 2024
1 parent 2c7d392 commit 86629fe
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 86629fe

Please sign in to comment.