]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Fix unused variables for ED448 (there is now similar code as for ED25519, placeholder...
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Tue, 30 May 2017 11:48:34 +0000 (13:48 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Tue, 30 May 2017 11:48:34 +0000 (13:48 +0200)
host2str.c
keys.c

index 0725cabe77dc8a0de019f76e95843f3a74c4c02e..c14025775b10818f333877c5e098f32ce70c642b 100644 (file)
@@ -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<len; i++) {
+               int x = (d[i]&0xf0)>>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 85d7923a5cba54305863c18c952f51d15f49b151..4eed0f4f8065d2b211ea0110f1069247009dae85 100644 (file)
--- 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<len; i++) {
+               int x = (d[i]&0xf0)>>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<len; i++) {
-               int x = (d[i]&0xf0)>>4;
-               int y = (d[i]&0x0f);
-               printf("%c%c", hex[x], hex[y]);
-       }
-       printf("\n");
-}
-#endif
-
 ldns_rr *
 ldns_key2rr(const ldns_key *k)
 {