From eead6006712b551deff70aa65dacfe9fb127f32c Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Tue, 30 May 2017 13:48:34 +0200 Subject: [PATCH] Fix unused variables for ED448 (there is now similar code as for ED25519, placeholder with debug printout (if used)). --- host2str.c | 58 ++++++++++++++++++++++++++++++++++++++++++++---------- keys.c | 36 ++++++++++++++++++--------------- 2 files changed, 68 insertions(+), 26 deletions(-) diff --git a/host2str.c b/host2str.c index 0725cabe..c1402577 100644 --- a/host2str.c +++ b/host2str.c @@ -1957,6 +1957,52 @@ ldns_ed25519_key2buffer_str(ldns_buffer *output, EVP_PKEY *p) } #endif +#if defined(USE_ED448) +/* debug printout routine */ +static void ed448_print_hex(const char* str, uint8_t* d, int len) +{ + const char hex[] = "0123456789abcdef"; + int i; + printf("%s [len=%d]: ", str, len); + for(i=0; i>4; + int y = (d[i]&0x0f); + printf("%c%c", hex[x], hex[y]); + } + printf("\n"); +} +#endif + +#if defined(HAVE_SSL) && defined(USE_ED448) +static ldns_status +ldns_ed448_key2buffer_str(ldns_buffer *output, EVP_PKEY *p) +{ + unsigned char* pp = NULL; + int ret; + ldns_rdf *b64_bignum; + ldns_status status; + + ldns_buffer_printf(output, "PrivateKey: "); + + ret = i2d_PrivateKey(p, &pp); + /* printout hex to find length of ASN */ + ed448_print_hex("ED448 privkey i2d", pp, ret); + /* some-ASN (??) + 56byte key */ + if(ret != 16 + 56) { + OPENSSL_free(pp); + return LDNS_STATUS_ERR; + } + b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, + (size_t)ret-16, pp+16); + status = ldns_rdf2buffer_str(output, b64_bignum); + + ldns_rdf_deep_free(b64_bignum); + OPENSSL_free(pp); + ldns_buffer_printf(output, "\n"); + return status; +} +#endif + /** print one b64 encoded bignum to a line in the keybuffer */ static int ldns_print_bignum_b64_line(ldns_buffer* output, const char* label, const BIGNUM* num) @@ -2198,16 +2244,8 @@ ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k) ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k)); status=ldns_algorithm2buffer_str(output, (ldns_algorithm)ldns_key_algorithm(k)); ldns_buffer_printf(output, ")\n"); - if(k->_key.key) { - EC_KEY* ec = EVP_PKEY_get1_EC_KEY(k->_key.key); - const BIGNUM* b = EC_KEY_get0_private_key(ec); - if(!ldns_print_bignum_b64_line(output, "PrivateKey", b)) - goto error; - /* down reference count in EC_KEY - * its still assigned to the PKEY */ - EC_KEY_free(ec); - } - ldns_buffer_printf(output, "\n"); + status = ldns_ed448_key2buffer_str(output, + k->_key.key); break; #endif /* USE_ED448 */ case LDNS_SIGN_HMACMD5: diff --git a/keys.c b/keys.c index 85d7923a..4eed0f4f 100644 --- a/keys.c +++ b/keys.c @@ -358,6 +358,22 @@ ldns_key_new_frm_fp_ed25519_l(FILE* fp, int* line_nr) } #endif +#if defined(USE_ED448) +/* debug printout routine */ +static void print_hex(const char* str, uint8_t* d, int len) +{ + const char hex[] = "0123456789abcdef"; + int i; + printf("%s [len=%d]: ", str, len); + for(i=0; i>4; + int y = (d[i]&0x0f); + printf("%c%c", hex[x], hex[y]); + } + printf("\n"); +} +#endif + #ifdef USE_ED448 /** turn private key buffer into EC_KEY structure */ static EVP_PKEY* @@ -1790,6 +1806,10 @@ ldns_key_ed4482bin(unsigned char* data, EVP_PKEY* k, uint16_t* size) { int i; unsigned char* pp = NULL; + unsigned len = i2d_PUBKEY(k, &pp); + /* printout ASN format for pubkey */ + print_hex("ed448 pubkey i2d", pp, len); + free(pp); pp = NULL; /* untested, not sure what the lengths are for the prefix */ if(i2d_PUBKEY(k, &pp) != 12 + 56) { /* expect 12 byte(ASN header) and 56 byte(pubkey) */ @@ -1807,22 +1827,6 @@ ldns_key_ed4482bin(unsigned char* data, EVP_PKEY* k, uint16_t* size) #endif /* splint */ #endif /* HAVE_SSL */ -#if defined(USE_ED448) -/* debug printout routine */ -static void print_hex(const char* str, uint8_t* d, int len) -{ - const char hex[] = "0123456789abcdef"; - int i; - printf("%s [len=%d]: ", str, len); - for(i=0; i>4; - int y = (d[i]&0x0f); - printf("%c%c", hex[x], hex[y]); - } - printf("\n"); -} -#endif - ldns_rr * ldns_key2rr(const ldns_key *k) { -- 2.47.3