]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
DPP: Move debug print of EC key to crypto.h
authorCedric Izoard <cedric.izoard@ceva-dsp.com>
Mon, 28 Jun 2021 16:25:36 +0000 (18:25 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 27 Oct 2021 20:50:23 +0000 (23:50 +0300)
Move the crypto lib specific print of an EC key in dpp_debug_print_key()
to crypto.h.

Signed-off-by: Cedric Izoard <cedric.izoard@ceva-dsp.com>
src/common/dpp.c
src/common/dpp.h
src/common/dpp_crypto.c
src/common/dpp_i.h
src/crypto/crypto.h
src/crypto/crypto_openssl.c

index 02ed0dd91551f366b07b4fe7019c9ff2df0645c0..9a87c2b7309210ebd93d415daf82aaf2ddff3b8a 100644 (file)
@@ -8,6 +8,8 @@
  */
 
 #include "utils/includes.h"
+#include <openssl/evp.h>
+#include <openssl/x509.h>
 
 #include "utils/common.h"
 #include "utils/base64.h"
index bb351e38776129de367de20ba7d3e53580720709..e8863c636fb671c79352df908545a947164ba543 100644 (file)
@@ -11,8 +11,6 @@
 #define DPP_H
 
 #ifdef CONFIG_DPP
-#include <openssl/x509.h>
-
 #include "utils/list.h"
 #include "common/wpa_common.h"
 #include "crypto/sha256.h"
index d110446a146650b427808435fb98b44675a0e8ed..d9a9594473268878a42d8fe987179768043f35ad 100644 (file)
@@ -80,75 +80,11 @@ const struct dpp_curve_params * dpp_get_curve_ike_group(u16 group)
 }
 
 
-void dpp_debug_print_point(const char *title, const EC_GROUP *group,
-                          const EC_POINT *point)
-{
-       BIGNUM *x, *y;
-       BN_CTX *ctx;
-       char *x_str = NULL, *y_str = NULL;
-
-       if (!wpa_debug_show_keys)
-               return;
-
-       ctx = BN_CTX_new();
-       x = BN_new();
-       y = BN_new();
-       if (!ctx || !x || !y ||
-           EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx) != 1)
-               goto fail;
-
-       x_str = BN_bn2hex(x);
-       y_str = BN_bn2hex(y);
-       if (!x_str || !y_str)
-               goto fail;
-
-       wpa_printf(MSG_DEBUG, "%s (%s,%s)", title, x_str, y_str);
-
-fail:
-       OPENSSL_free(x_str);
-       OPENSSL_free(y_str);
-       BN_free(x);
-       BN_free(y);
-       BN_CTX_free(ctx);
-}
-
-
 void dpp_debug_print_key(const char *title, struct crypto_ec_key *key)
 {
-       EC_KEY *eckey;
-       BIO *out;
-       size_t rlen;
-       char *txt;
-       int res;
        struct wpabuf *der = NULL;
-       const EC_GROUP *group;
-       const EC_POINT *point;
-
-       out = BIO_new(BIO_s_mem());
-       if (!out)
-               return;
 
-       EVP_PKEY_print_private(out, (EVP_PKEY *) key, 0, NULL);
-       rlen = BIO_ctrl_pending(out);
-       txt = os_malloc(rlen + 1);
-       if (txt) {
-               res = BIO_read(out, txt, rlen);
-               if (res > 0) {
-                       txt[res] = '\0';
-                       wpa_printf(MSG_DEBUG, "%s: %s", title, txt);
-               }
-               os_free(txt);
-       }
-       BIO_free(out);
-
-       eckey = EVP_PKEY_get1_EC_KEY((EVP_PKEY *) key);
-       if (!eckey)
-               return;
-
-       group = EC_KEY_get0_group(eckey);
-       point = EC_KEY_get0_public_key(eckey);
-       if (group && point)
-               dpp_debug_print_point(title, group, point);
+       crypto_ec_key_debug_print(key, title);
 
        der = crypto_ec_key_get_ecprivate_key(key, true);
        if (der) {
@@ -159,7 +95,6 @@ void dpp_debug_print_key(const char *title, struct crypto_ec_key *key)
                        wpa_hexdump_buf_key(MSG_DEBUG, "DPP: EC_PUBKEY", der);
        }
 
-       EC_KEY_free(eckey);
        wpabuf_clear_free(der);
 }
 
@@ -397,7 +332,6 @@ static struct wpabuf * dpp_bootstrap_key_der(struct crypto_ec_key *key)
        point = EC_KEY_get0_public_key(eckey);
        if (!group || !point)
                goto fail;
-       dpp_debug_print_point("DPP: bootstrap public key", group, point);
        nid = EC_GROUP_get_curve_name(group);
 
        bootstrap = DPP_BOOTSTRAPPING_KEY_new();
index b5b4fca8f53b73fde2787158cfa422e81359473e..087878a508cbe09830889deadc65681c6a08b180 100644 (file)
@@ -86,8 +86,6 @@ int dpp_hmac_vector(size_t hash_len, const u8 *key, size_t key_len,
                    u8 *mac);
 int dpp_ecdh(struct crypto_ec_key *own, struct crypto_ec_key *peer,
             u8 *secret, size_t *secret_len);
-void dpp_debug_print_point(const char *title, const EC_GROUP *group,
-                          const EC_POINT *point);
 void dpp_debug_print_key(const char *title, struct crypto_ec_key *key);
 int dpp_pbkdf2(size_t hash_len, const u8 *password, size_t password_len,
               const u8 *salt, size_t salt_len, unsigned int iterations,
index e19037b6043b7245ff3d6b685b6cb7ea0a411cdf..556e206480ee9aac5d160d14e092a32c8501423f 100644 (file)
@@ -1158,4 +1158,12 @@ int crypto_ec_key_group(struct crypto_ec_key *key);
  */
 int crypto_ec_key_cmp(struct crypto_ec_key *key1, struct crypto_ec_key *key2);
 
+/**
+ * crypto_ec_key_debug_print - Dump EC key to debug log
+ * @key:  EC key from crypto_ec_key_parse/set_pub/priv() or crypto_ec_key_gen()
+ * @title: Name of the EC point in the trace
+ */
+void crypto_ec_key_debug_print(const struct crypto_ec_key *key,
+                              const char *title);
+
 #endif /* CRYPTO_H */
index f7c52ffbce76733ff80acb3428a31c9251b598be..949cf1a5c92f9f7323c914d9adba56acca2c88a4 100644 (file)
@@ -2778,4 +2778,31 @@ int crypto_ec_key_cmp(struct crypto_ec_key *key1, struct crypto_ec_key *key2)
        return 0;
 }
 
+
+void crypto_ec_key_debug_print(const struct crypto_ec_key *key,
+                              const char *title)
+{
+       BIO *out;
+       size_t rlen;
+       char *txt;
+       int res;
+
+       out = BIO_new(BIO_s_mem());
+       if (!out)
+               return;
+
+       EVP_PKEY_print_private(out, (EVP_PKEY *) key, 0, NULL);
+       rlen = BIO_ctrl_pending(out);
+       txt = os_malloc(rlen + 1);
+       if (txt) {
+               res = BIO_read(out, txt, rlen);
+               if (res > 0) {
+                       txt[res] = '\0';
+                       wpa_printf(MSG_DEBUG, "%s: %s", title, txt);
+               }
+               os_free(txt);
+       }
+       BIO_free(out);
+}
+
 #endif /* CONFIG_ECC */