130 lines
4.5 KiB
Diff
130 lines
4.5 KiB
Diff
From cd6316777395bef8997324cd7152f383534779d3 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Micha=C5=82=20Trojnara?= <Michal.Trojnara@stunnel.org>
|
|
Date: Wed, 29 Aug 2018 22:38:54 +0200
|
|
Subject: [PATCH 08/23] ex_data coding style unification
|
|
|
|
---
|
|
src/libp11-int.h | 2 +-
|
|
src/p11_ec.c | 31 ++++++++++++++++---------------
|
|
src/p11_rsa.c | 6 +++---
|
|
3 files changed, 20 insertions(+), 19 deletions(-)
|
|
|
|
diff --git a/src/libp11-int.h b/src/libp11-int.h
|
|
index 411f2b0..3c4792b 100644
|
|
--- a/src/libp11-int.h
|
|
+++ b/src/libp11-int.h
|
|
@@ -367,7 +367,7 @@ extern int pkcs11_private_decrypt(
|
|
unsigned char *to, PKCS11_KEY * key, int padding);
|
|
|
|
/* Retrieve PKCS11_KEY from an RSA key */
|
|
-extern PKCS11_KEY *pkcs11_get_ex_data_rsa(RSA *rsa);
|
|
+extern PKCS11_KEY *pkcs11_get_ex_data_rsa(const RSA *rsa);
|
|
|
|
#endif
|
|
|
|
diff --git a/src/p11_ec.c b/src/p11_ec.c
|
|
index 8d458dc..eb0cbb2 100644
|
|
--- a/src/p11_ec.c
|
|
+++ b/src/p11_ec.c
|
|
@@ -260,7 +260,16 @@ static EC_KEY *pkcs11_get_ec(PKCS11_KEY *key)
|
|
return ec;
|
|
}
|
|
|
|
-static void pkcs11_set_ex_data_ec(EC_KEY* ec, PKCS11_KEY* key)
|
|
+static PKCS11_KEY *pkcs11_get_ex_data_ec(const EC_KEY *ec)
|
|
+{
|
|
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
|
+ return EC_KEY_get_ex_data(ec, ec_ex_index);
|
|
+#else
|
|
+ return ECDSA_get_ex_data((EC_KEY *)ec, ec_ex_index);
|
|
+#endif
|
|
+}
|
|
+
|
|
+static void pkcs11_set_ex_data_ec(EC_KEY *ec, PKCS11_KEY *key)
|
|
{
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
|
EC_KEY_set_ex_data(ec, ec_ex_index, key);
|
|
@@ -269,10 +278,10 @@ static void pkcs11_set_ex_data_ec(EC_KEY* ec, PKCS11_KEY* key)
|
|
#endif
|
|
}
|
|
|
|
-static void pkcs11_update_ex_data_ec(PKCS11_KEY* key)
|
|
+static void pkcs11_update_ex_data_ec(PKCS11_KEY *key)
|
|
{
|
|
- EVP_PKEY* evp = key->evp_key;
|
|
- EC_KEY* ec;
|
|
+ EVP_PKEY *evp = key->evp_key;
|
|
+ EC_KEY *ec;
|
|
if (evp == NULL)
|
|
return;
|
|
if (EVP_PKEY_base_id(evp) != EVP_PKEY_EC)
|
|
@@ -384,11 +393,7 @@ static ECDSA_SIG *pkcs11_ecdsa_sign_sig(const unsigned char *dgst, int dlen,
|
|
(void)kinv; /* Precomputed values are not used for PKCS#11 */
|
|
(void)rp; /* Precomputed values are not used for PKCS#11 */
|
|
|
|
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
|
- key = (PKCS11_KEY *)EC_KEY_get_ex_data(ec, ec_ex_index);
|
|
-#else
|
|
- key = (PKCS11_KEY *)ECDSA_get_ex_data(ec, ec_ex_index);
|
|
-#endif
|
|
+ key = pkcs11_get_ex_data_ec(ec);
|
|
if (key == NULL) {
|
|
sign_sig_fn orig_sign_sig;
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
|
@@ -574,7 +579,7 @@ static int pkcs11_ec_ckey(unsigned char **out, size_t *outlen,
|
|
size_t buflen;
|
|
int rv;
|
|
|
|
- key = (PKCS11_KEY *)EC_KEY_get_ex_data(ecdh, ec_ex_index);
|
|
+ key = pkcs11_get_ex_data_ec(ecdh);
|
|
if (key == NULL) /* The private key is not handled by PKCS#11 */
|
|
return ossl_ecdh_compute_key(out, outlen, peer_point, ecdh);
|
|
/* TODO: Add an atfork check */
|
|
@@ -616,11 +621,7 @@ static int pkcs11_ec_ckey(void *out, size_t outlen,
|
|
size_t buflen;
|
|
int rv;
|
|
|
|
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
|
- key = (PKCS11_KEY *)EC_KEY_get_ex_data(ecdh, ec_ex_index);
|
|
-#else
|
|
- key = (PKCS11_KEY *)ECDSA_get_ex_data((EC_KEY *)ecdh, ec_ex_index);
|
|
-#endif
|
|
+ key = pkcs11_get_ex_data_ec(ecdh);
|
|
if (key == NULL) /* The private key is not handled by PKCS#11 */
|
|
return ossl_ecdh_compute_key(out, outlen, peer_point, ecdh, KDF);
|
|
/* TODO: Add an atfork check */
|
|
diff --git a/src/p11_rsa.c b/src/p11_rsa.c
|
|
index 97cd5a2..f69a8a6 100644
|
|
--- a/src/p11_rsa.c
|
|
+++ b/src/p11_rsa.c
|
|
@@ -233,7 +233,7 @@ success:
|
|
}
|
|
|
|
|
|
-PKCS11_KEY *pkcs11_get_ex_data_rsa(RSA *rsa)
|
|
+PKCS11_KEY *pkcs11_get_ex_data_rsa(const RSA *rsa)
|
|
{
|
|
return RSA_get_ex_data(rsa, rsa_ex_index);
|
|
}
|
|
@@ -352,7 +352,7 @@ int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
|
|
static int pkcs11_rsa_priv_dec_method(int flen, const unsigned char *from,
|
|
unsigned char *to, RSA *rsa, int padding)
|
|
{
|
|
- PKCS11_KEY *key = RSA_get_ex_data(rsa, rsa_ex_index);
|
|
+ PKCS11_KEY *key = pkcs11_get_ex_data_rsa(rsa);
|
|
int (*priv_dec) (int flen, const unsigned char *from,
|
|
unsigned char *to, RSA *rsa, int padding);
|
|
if (key == NULL) {
|
|
@@ -365,7 +365,7 @@ static int pkcs11_rsa_priv_dec_method(int flen, const unsigned char *from,
|
|
static int pkcs11_rsa_priv_enc_method(int flen, const unsigned char *from,
|
|
unsigned char *to, RSA *rsa, int padding)
|
|
{
|
|
- PKCS11_KEY *key = RSA_get_ex_data(rsa, rsa_ex_index);
|
|
+ PKCS11_KEY *key = pkcs11_get_ex_data_rsa(rsa);
|
|
int (*priv_enc) (int flen, const unsigned char *from,
|
|
unsigned char *to, RSA *rsa, int padding);
|
|
if (key == NULL) {
|
|
--
|
|
2.17.1
|
|
|