Merge pull request #2211 from Houkime/openssl-deprecations
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / trixie (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions

Update deprecated openssl functions and remove warning suppression
This commit is contained in:
orignal 2025-07-14 07:45:06 -04:00 committed by GitHub
commit 2c2452cd3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 49 additions and 41 deletions

View file

@ -77,7 +77,6 @@ else # not supported
endif endif
INCFLAGS += -I$(LIB_SRC_DIR) -I$(LIB_CLIENT_SRC_DIR) -I$(LANG_SRC_DIR) INCFLAGS += -I$(LIB_SRC_DIR) -I$(LIB_CLIENT_SRC_DIR) -I$(LANG_SRC_DIR)
DEFINES += -DOPENSSL_SUPPRESS_DEPRECATED
NEEDED_CXXFLAGS += -MMD -MP NEEDED_CXXFLAGS += -MMD -MP
ifeq ($(USE_GIT_VERSION),yes) ifeq ($(USE_GIT_VERSION),yes)

View file

@ -6,10 +6,12 @@
* See full license text in LICENSE file at top of project tree * See full license text in LICENSE file at top of project tree
*/ */
#include <cstdint>
#include <zlib.h> // for crc32 #include <zlib.h> // for crc32
#include <openssl/sha.h> #include <openssl/sha.h>
#include <openssl/hmac.h> #include <openssl/hmac.h>
#include <openssl/ec.h> #include <openssl/ec.h>
#include <openssl/evp.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include "Base.h" #include "Base.h"
#include "Crypto.h" #include "Crypto.h"
@ -65,10 +67,10 @@ namespace data
BIGNUM * x = BN_bin2bn (pub, publicKeyLen/2, NULL); BIGNUM * x = BN_bin2bn (pub, publicKeyLen/2, NULL);
BIGNUM * y = BN_bin2bn (pub + publicKeyLen/2, publicKeyLen/2, NULL); BIGNUM * y = BN_bin2bn (pub + publicKeyLen/2, publicKeyLen/2, NULL);
EC_POINT * p = EC_POINT_new (group); EC_POINT * p = EC_POINT_new (group);
EC_POINT_set_affine_coordinates_GFp (group, p, x, y, NULL); EC_POINT_set_affine_coordinates (group, p, x, y, NULL);
EC_POINT * p1 = BlindPublicKeyECDSA (group, p, seed); EC_POINT * p1 = BlindPublicKeyECDSA (group, p, seed);
EC_POINT_free (p); EC_POINT_free (p);
EC_POINT_get_affine_coordinates_GFp (group, p1, x, y, NULL); EC_POINT_get_affine_coordinates (group, p1, x, y, NULL);
EC_POINT_free (p1); EC_POINT_free (p1);
i2p::crypto::bn2buf (x, blindedPub, publicKeyLen/2); i2p::crypto::bn2buf (x, blindedPub, publicKeyLen/2);
i2p::crypto::bn2buf (y, blindedPub + publicKeyLen/2, publicKeyLen/2); i2p::crypto::bn2buf (y, blindedPub + publicKeyLen/2, publicKeyLen/2);
@ -88,7 +90,7 @@ namespace data
BN_CTX_free (ctx); BN_CTX_free (ctx);
BN_free (a1); BN_free (a1);
BIGNUM * x = BN_new(), * y = BN_new(); BIGNUM * x = BN_new(), * y = BN_new();
EC_POINT_get_affine_coordinates_GFp (group, p, x, y, NULL); EC_POINT_get_affine_coordinates (group, p, x, y, NULL);
EC_POINT_free (p); EC_POINT_free (p);
i2p::crypto::bn2buf (x, blindedPub, publicKeyLen/2); i2p::crypto::bn2buf (x, blindedPub, publicKeyLen/2);
i2p::crypto::bn2buf (y, blindedPub + publicKeyLen/2, publicKeyLen/2); i2p::crypto::bn2buf (y, blindedPub + publicKeyLen/2, publicKeyLen/2);
@ -295,12 +297,14 @@ namespace data
void BlindedPublicKey::H (const std::string& p, const std::vector<std::pair<const uint8_t *, size_t> >& bufs, uint8_t * hash) const void BlindedPublicKey::H (const std::string& p, const std::vector<std::pair<const uint8_t *, size_t> >& bufs, uint8_t * hash) const
{ {
SHA256_CTX ctx; EVP_MD_CTX *ctx = EVP_MD_CTX_new ();
SHA256_Init (&ctx);
SHA256_Update (&ctx, p.c_str (), p.length ()); EVP_DigestInit_ex(ctx, EVP_sha256 (), NULL);
EVP_DigestUpdate (ctx, p.c_str (), p.length ());
for (const auto& it: bufs) for (const auto& it: bufs)
SHA256_Update (&ctx, it.first, it.second); EVP_DigestUpdate (ctx, it.first, it.second);
SHA256_Final (hash, &ctx); EVP_DigestFinal_ex (ctx, (uint8_t * )hash, nullptr);
EVP_MD_CTX_free (ctx);
} }
i2p::data::IdentHash BlindedPublicKey::GetStoreHash (const char * date) const i2p::data::IdentHash BlindedPublicKey::GetStoreHash (const char * date) const
@ -319,11 +323,12 @@ namespace data
if (publicKeyLength) if (publicKeyLength)
{ {
auto stA1 = htobe16 (m_BlindedSigType); auto stA1 = htobe16 (m_BlindedSigType);
SHA256_CTX ctx; EVP_MD_CTX *ctx = EVP_MD_CTX_new ();
SHA256_Init (&ctx); EVP_DigestInit_ex(ctx, EVP_sha256(), NULL);
SHA256_Update (&ctx, (const uint8_t *)&stA1, 2); EVP_DigestUpdate (ctx, (const uint8_t *)&stA1, 2);
SHA256_Update (&ctx, blinded, publicKeyLength); EVP_DigestUpdate (ctx, blinded, publicKeyLength);
SHA256_Final ((uint8_t *)hash, &ctx); EVP_DigestFinal_ex (ctx, (uint8_t * )hash, nullptr);
EVP_MD_CTX_free(ctx);
} }
else else
LogPrint (eLogError, "Blinding: Blinded key type ", (int)m_BlindedSigType, " is not supported"); LogPrint (eLogError, "Blinding: Blinded key type ", (int)m_BlindedSigType, " is not supported");

View file

@ -456,14 +456,14 @@ namespace crypto
auto p = EC_POINT_new (curve); auto p = EC_POINT_new (curve);
EC_POINT_mul (curve, p, k, nullptr, nullptr, ctx); EC_POINT_mul (curve, p, k, nullptr, nullptr, ctx);
BIGNUM * x = BN_CTX_get (ctx), * y = BN_CTX_get (ctx); BIGNUM * x = BN_CTX_get (ctx), * y = BN_CTX_get (ctx);
EC_POINT_get_affine_coordinates_GFp (curve, p, x, y, nullptr); EC_POINT_get_affine_coordinates (curve, p, x, y, nullptr);
encrypted[0] = 0; encrypted[0] = 0;
bn2buf (x, encrypted + 1, len); bn2buf (x, encrypted + 1, len);
bn2buf (y, encrypted + 1 + len, len); bn2buf (y, encrypted + 1 + len, len);
RAND_bytes (encrypted + 1 + 2*len, 256 - 2*len); RAND_bytes (encrypted + 1 + 2*len, 256 - 2*len);
// encryption key and iv // encryption key and iv
EC_POINT_mul (curve, p, nullptr, key, k, ctx); EC_POINT_mul (curve, p, nullptr, key, k, ctx);
EC_POINT_get_affine_coordinates_GFp (curve, p, x, y, nullptr); EC_POINT_get_affine_coordinates (curve, p, x, y, nullptr);
uint8_t keyBuf[64], iv[64], shared[32]; uint8_t keyBuf[64], iv[64], shared[32];
bn2buf (x, keyBuf, len); bn2buf (x, keyBuf, len);
bn2buf (y, iv, len); bn2buf (y, iv, len);
@ -496,11 +496,11 @@ namespace crypto
BN_bin2bn (encrypted + 1, len, x); BN_bin2bn (encrypted + 1, len, x);
BN_bin2bn (encrypted + 1 + len, len, y); BN_bin2bn (encrypted + 1 + len, len, y);
auto p = EC_POINT_new (curve); auto p = EC_POINT_new (curve);
if (EC_POINT_set_affine_coordinates_GFp (curve, p, x, y, nullptr)) if (EC_POINT_set_affine_coordinates (curve, p, x, y, nullptr))
{ {
auto s = EC_POINT_new (curve); auto s = EC_POINT_new (curve);
EC_POINT_mul (curve, s, nullptr, p, key, ctx); EC_POINT_mul (curve, s, nullptr, p, key, ctx);
EC_POINT_get_affine_coordinates_GFp (curve, s, x, y, nullptr); EC_POINT_get_affine_coordinates (curve, s, x, y, nullptr);
EC_POINT_free (s); EC_POINT_free (s);
uint8_t keyBuf[64], iv[64], shared[32]; uint8_t keyBuf[64], iv[64], shared[32];
bn2buf (x, keyBuf, len); bn2buf (x, keyBuf, len);
@ -810,31 +810,35 @@ namespace crypto
{ {
// pub is Bob's public static key, hh = SHA256(h) // pub is Bob's public static key, hh = SHA256(h)
memcpy (m_CK, ck, 32); memcpy (m_CK, ck, 32);
SHA256_CTX ctx;
SHA256_Init (&ctx); EVP_MD_CTX *ctx = EVP_MD_CTX_new ();
SHA256_Update (&ctx, hh, 32); EVP_DigestInit_ex(ctx, EVP_sha256 (), NULL);
SHA256_Update (&ctx, pub, 32); EVP_DigestUpdate (ctx, hh, 32);
SHA256_Final (m_H, &ctx); // h = MixHash(pub) = SHA256(hh || pub) EVP_DigestUpdate (ctx, pub, 32);
EVP_DigestFinal_ex (ctx, m_H, nullptr); // h = MixHash(pub) = SHA256(hh || pub)
EVP_MD_CTX_free (ctx);
m_N = 0; m_N = 0;
} }
void NoiseSymmetricState::MixHash (const uint8_t * buf, size_t len) void NoiseSymmetricState::MixHash (const uint8_t * buf, size_t len)
{ {
SHA256_CTX ctx; EVP_MD_CTX *ctx = EVP_MD_CTX_new ();
SHA256_Init (&ctx); EVP_DigestInit_ex(ctx, EVP_sha256 (), NULL);
SHA256_Update (&ctx, m_H, 32); EVP_DigestUpdate (ctx, m_H, 32);
SHA256_Update (&ctx, buf, len); EVP_DigestUpdate (ctx, buf, len);
SHA256_Final (m_H, &ctx); EVP_DigestFinal_ex (ctx, m_H, nullptr);
EVP_MD_CTX_free (ctx);
} }
void NoiseSymmetricState::MixHash (const std::vector<std::pair<uint8_t *, size_t> >& bufs) void NoiseSymmetricState::MixHash (const std::vector<std::pair<uint8_t *, size_t> >& bufs)
{ {
SHA256_CTX ctx; EVP_MD_CTX *ctx = EVP_MD_CTX_new ();
SHA256_Init (&ctx); EVP_DigestInit_ex(ctx, EVP_sha256 (), NULL);
SHA256_Update (&ctx, m_H, 32); EVP_DigestUpdate (ctx, m_H, 32);
for (const auto& it: bufs) for (const auto& it: bufs)
SHA256_Update (&ctx, it.first, it.second); EVP_DigestUpdate (ctx, it.first, it.second);
SHA256_Final (m_H, &ctx); EVP_DigestFinal_ex (ctx, m_H, nullptr);
EVP_MD_CTX_free (ctx);
} }
void NoiseSymmetricState::MixKey (const uint8_t * sharedSecret) void NoiseSymmetricState::MixKey (const uint8_t * sharedSecret)

View file

@ -41,7 +41,7 @@ namespace crypto
m_PublicKey = EC_POINT_new (m_Curve); m_PublicKey = EC_POINT_new (m_Curve);
BIGNUM * x = BN_bin2bn (pub, 32, nullptr); BIGNUM * x = BN_bin2bn (pub, 32, nullptr);
BIGNUM * y = BN_bin2bn (pub + 32, 32, nullptr); BIGNUM * y = BN_bin2bn (pub + 32, 32, nullptr);
if (!EC_POINT_set_affine_coordinates_GFp (m_Curve, m_PublicKey, x, y, nullptr)) if (!EC_POINT_set_affine_coordinates (m_Curve, m_PublicKey, x, y, nullptr))
LogPrint (eLogError, "ECICS P256 invalid public key"); LogPrint (eLogError, "ECICS P256 invalid public key");
BN_free (x); BN_free (y); BN_free (x); BN_free (y);
} }
@ -87,7 +87,7 @@ namespace crypto
RAND_bytes (priv + 32, 224); RAND_bytes (priv + 32, 224);
BN_free (key); BN_free (key);
BIGNUM * x = BN_new (), * y = BN_new (); BIGNUM * x = BN_new (), * y = BN_new ();
EC_POINT_get_affine_coordinates_GFp (curve, p, x, y, NULL); EC_POINT_get_affine_coordinates (curve, p, x, y, NULL);
bn2buf (x, pub, 32); bn2buf (x, pub, 32);
bn2buf (y, pub + 32, 32); bn2buf (y, pub + 32, 32);
RAND_bytes (pub + 64, 192); RAND_bytes (pub + 64, 192);
@ -102,7 +102,7 @@ namespace crypto
m_PublicKey = EC_POINT_new (curve->GetGroup ()); m_PublicKey = EC_POINT_new (curve->GetGroup ());
BIGNUM * x = BN_bin2bn (pub, 32, nullptr); BIGNUM * x = BN_bin2bn (pub, 32, nullptr);
BIGNUM * y = BN_bin2bn (pub + 32, 32, nullptr); BIGNUM * y = BN_bin2bn (pub + 32, 32, nullptr);
if (!EC_POINT_set_affine_coordinates_GFp (curve->GetGroup (), m_PublicKey, x, y, nullptr)) if (!EC_POINT_set_affine_coordinates (curve->GetGroup (), m_PublicKey, x, y, nullptr))
LogPrint (eLogError, "ECICS GOST R 34.10 invalid public key"); LogPrint (eLogError, "ECICS GOST R 34.10 invalid public key");
BN_free (x); BN_free (y); BN_free (x); BN_free (y);
} }
@ -146,7 +146,7 @@ namespace crypto
RAND_bytes (priv + 32, 224); RAND_bytes (priv + 32, 224);
BN_free (key); BN_free (key);
BIGNUM * x = BN_new (), * y = BN_new (); BIGNUM * x = BN_new (), * y = BN_new ();
EC_POINT_get_affine_coordinates_GFp (curve->GetGroup (), p, x, y, NULL); EC_POINT_get_affine_coordinates (curve->GetGroup (), p, x, y, NULL);
bn2buf (x, pub, 32); bn2buf (x, pub, 32);
bn2buf (y, pub + 32, 32); bn2buf (y, pub + 32, 32);
RAND_bytes (pub + 64, 192); RAND_bytes (pub + 64, 192);

View file

@ -27,7 +27,7 @@ namespace crypto
BN_CTX * ctx = BN_CTX_new (); BN_CTX * ctx = BN_CTX_new ();
m_Group = EC_GROUP_new_curve_GFp (p, a, b, ctx); m_Group = EC_GROUP_new_curve_GFp (p, a, b, ctx);
EC_POINT * P = EC_POINT_new (m_Group); EC_POINT * P = EC_POINT_new (m_Group);
EC_POINT_set_affine_coordinates_GFp (m_Group, P, x, y, ctx); EC_POINT_set_affine_coordinates (m_Group, P, x, y, ctx);
EC_GROUP_set_generator (m_Group, P, q, nullptr); EC_GROUP_set_generator (m_Group, P, q, nullptr);
EC_GROUP_set_curve_name (m_Group, NID_id_GostR3410_2001); EC_GROUP_set_curve_name (m_Group, NID_id_GostR3410_2001);
EC_POINT_free(P); EC_POINT_free(P);
@ -50,13 +50,13 @@ namespace crypto
bool GOSTR3410Curve::GetXY (const EC_POINT * p, BIGNUM * x, BIGNUM * y) const bool GOSTR3410Curve::GetXY (const EC_POINT * p, BIGNUM * x, BIGNUM * y) const
{ {
return EC_POINT_get_affine_coordinates_GFp (m_Group, p, x, y, nullptr); return EC_POINT_get_affine_coordinates (m_Group, p, x, y, nullptr);
} }
EC_POINT * GOSTR3410Curve::CreatePoint (const BIGNUM * x, const BIGNUM * y) const EC_POINT * GOSTR3410Curve::CreatePoint (const BIGNUM * x, const BIGNUM * y) const
{ {
EC_POINT * p = EC_POINT_new (m_Group); EC_POINT * p = EC_POINT_new (m_Group);
EC_POINT_set_affine_coordinates_GFp (m_Group, p, x, y, nullptr); EC_POINT_set_affine_coordinates (m_Group, p, x, y, nullptr);
return p; return p;
} }
@ -112,7 +112,7 @@ namespace crypto
BN_CTX_start (ctx); BN_CTX_start (ctx);
EC_POINT * C = EC_POINT_new (m_Group); // C = k*P = (rx, ry) EC_POINT * C = EC_POINT_new (m_Group); // C = k*P = (rx, ry)
EC_POINT * Q = nullptr; EC_POINT * Q = nullptr;
if (EC_POINT_set_compressed_coordinates_GFp (m_Group, C, r, isNegativeY ? 1 : 0, ctx)) if (EC_POINT_set_compressed_coordinates (m_Group, C, r, isNegativeY ? 1 : 0, ctx))
{ {
EC_POINT * S = EC_POINT_new (m_Group); // S = s*P EC_POINT * S = EC_POINT_new (m_Group); // S = s*P
EC_POINT_mul (m_Group, S, s, nullptr, nullptr, ctx); EC_POINT_mul (m_Group, S, s, nullptr, nullptr, ctx);