Move the crypto lib specific print of a EC key in dpp_debug_print_key to crypto.h. Signed-off-by: Cedric Izoard <cedric.izoard@xxxxxxxxxxxx> --- src/common/dpp.h | 2 -- src/common/dpp_crypto.c | 67 +------------------------------------ src/common/dpp_i.h | 2 -- src/crypto/crypto.h | 9 +++++ src/crypto/crypto_openssl.c | 27 +++++++++++++++ 5 files changed, 37 insertions(+), 70 deletions(-) diff --git a/src/common/dpp.h b/src/common/dpp.h index 40e950a96..f353e5c3e 100644 --- a/src/common/dpp.h +++ b/src/common/dpp.h @@ -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" diff --git a/src/common/dpp_crypto.c b/src/common/dpp_crypto.c index e1510e72f..4b387f6b0 100644 --- a/src/common/dpp_crypto.c +++ b/src/common/dpp_crypto.c @@ -78,75 +78,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) { @@ -158,7 +94,6 @@ void dpp_debug_print_key(const char *title, struct crypto_ec_key *key) } } - EC_KEY_free(eckey); wpabuf_clear_free(der); } diff --git a/src/common/dpp_i.h b/src/common/dpp_i.h index 26bcad0b9..1b71efc2e 100644 --- a/src/common/dpp_i.h +++ b/src/common/dpp_i.h @@ -83,8 +83,6 @@ int dpp_hmac_vector(size_t hash_len, const u8 *key, size_t key_len, size_t num_elem, const u8 *addr[], const size_t *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, diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index d76ca9cd4..78e7045ca 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -1160,4 +1160,13 @@ 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 + * @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 */ diff --git a/src/crypto/crypto_openssl.c b/src/crypto/crypto_openssl.c index 282df1089..26705ff50 100644 --- a/src/crypto/crypto_openssl.c +++ b/src/crypto/crypto_openssl.c @@ -2802,4 +2802,31 @@ int crypto_ec_key_cmp(struct crypto_ec_key *key1, struct crypto_ec_key *key2) return -1; return 0; } + + +void crypto_ec_key_debug_print(const struct crypto_ec_key *key, + const char *title) +{ + BIO *out; + size_t rlen; + char *txt; + + 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) { + int 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 */ -- 2.17.0 _______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap