aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcryptobox
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-06-12 11:52:00 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-06-12 11:52:17 +0100
commit6facd3641c1fb9ba2947a45e20fe70bd9564c61c (patch)
tree9316971bfe75a75a65367a73083f1f62f24c2687 /src/libcryptobox
parent587dfcfb079573648ff70d7d37cb51f5e895d388 (diff)
downloadrspamd-6facd3641c1fb9ba2947a45e20fe70bd9564c61c.tar.gz
rspamd-6facd3641c1fb9ba2947a45e20fe70bd9564c61c.zip
[Minor] Try to fix build with (broken) OpenSSL API
Diffstat (limited to 'src/libcryptobox')
-rw-r--r--src/libcryptobox/cryptobox.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c
index 3caf364e6..87c50797a 100644
--- a/src/libcryptobox/cryptobox.c
+++ b/src/libcryptobox/cryptobox.c
@@ -340,9 +340,9 @@ rspamd_cryptobox_keypair (rspamd_pk_t pk, rspamd_sk_t sk,
#else
EC_KEY *ec_sec;
const BIGNUM *bn_sec;
- BIGNUM *bn_pub;
+
const EC_POINT *ec_pub;
- gint len;
+ gsize len;
ec_sec = EC_KEY_new_by_curve_name (CRYPTOBOX_CURVE_NID);
g_assert (ec_sec != NULL);
@@ -352,16 +352,27 @@ rspamd_cryptobox_keypair (rspamd_pk_t pk, rspamd_sk_t sk,
g_assert (bn_sec != NULL);
ec_pub = EC_KEY_get0_public_key (ec_sec);
g_assert (ec_pub != NULL);
+#if OPENSSL_VERSION_MAJOR >= 3
+ unsigned char *buf = NULL; /* Thanks openssl for this API (no) */
+ len = EC_POINT_point2buf (EC_KEY_get0_group (ec_sec), ec_pub,
+ POINT_CONVERSION_UNCOMPRESSED, &buf, NULL);
+ g_assert (len <= (gint)rspamd_cryptobox_pk_bytes (mode));
+ memcpy (pk, buf, len);
+ OPENSSL_free (buf);
+#else
+ BIGNUM *bn_pub;
bn_pub = EC_POINT_point2bn (EC_KEY_get0_group (ec_sec),
ec_pub, POINT_CONVERSION_UNCOMPRESSED, NULL, NULL);
-
- len = BN_num_bytes (bn_sec);
- g_assert (len <= (gint)sizeof (rspamd_sk_t));
- BN_bn2bin (bn_sec, sk);
len = BN_num_bytes (bn_pub);
g_assert (len <= (gint)rspamd_cryptobox_pk_bytes (mode));
BN_bn2bin (bn_pub, pk);
BN_free (bn_pub);
+#endif
+
+ len = BN_num_bytes (bn_sec);
+ g_assert (len <= (gint)sizeof (rspamd_sk_t));
+ BN_bn2bin (bn_sec, sk);
+
EC_KEY_free (ec_sec);
#endif
}