Skip to content

Commit 518e678

Browse files
committed
src: use const for EVP_PKEY legacy function calls
This commit add const to EC_KEY, DSA, RSA pointer to avoid compilation errors when linking against OpenSSL 3.0. Refs: openssl/openssl@7bc0fdd
1 parent 865c1a9 commit 518e678

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/crypto/crypto_dsa.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Maybe<bool> GetDsaKeyDetail(
138138
int type = EVP_PKEY_id(m_pkey.get());
139139
CHECK(type == EVP_PKEY_DSA);
140140

141-
DSA* dsa = EVP_PKEY_get0_DSA(m_pkey.get());
141+
const DSA* dsa = EVP_PKEY_get0_DSA(m_pkey.get());
142142
CHECK_NOT_NULL(dsa);
143143

144144
DSA_get0_pqg(dsa, &p, &q, nullptr);

src/crypto/crypto_ec.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ WebCryptoKeyExportStatus EC_Raw_Export(
614614
CHECK(m_pkey);
615615
Mutex::ScopedLock lock(*m_pkey.mutex());
616616

617-
EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(m_pkey.get());
617+
const EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(m_pkey.get());
618618

619619
unsigned char* data;
620620
size_t len = 0;
@@ -703,7 +703,7 @@ Maybe<bool> ExportJWKEcKey(
703703
Mutex::ScopedLock lock(*m_pkey.mutex());
704704
CHECK_EQ(EVP_PKEY_id(m_pkey.get()), EVP_PKEY_EC);
705705

706-
EC_KEY* ec = EVP_PKEY_get0_EC_KEY(m_pkey.get());
706+
const EC_KEY* ec = EVP_PKEY_get0_EC_KEY(m_pkey.get());
707707
CHECK_NOT_NULL(ec);
708708

709709
const EC_POINT* pub = EC_KEY_get0_public_key(ec);
@@ -910,7 +910,7 @@ Maybe<bool> GetEcKeyDetail(
910910
Mutex::ScopedLock lock(*m_pkey.mutex());
911911
CHECK_EQ(EVP_PKEY_id(m_pkey.get()), EVP_PKEY_EC);
912912

913-
EC_KEY* ec = EVP_PKEY_get0_EC_KEY(m_pkey.get());
913+
const EC_KEY* ec = EVP_PKEY_get0_EC_KEY(m_pkey.get());
914914
CHECK_NOT_NULL(ec);
915915

916916
const EC_GROUP* group = EC_KEY_get0_group(ec);

src/crypto/crypto_rsa.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,11 @@ Maybe<bool> ExportJWKRsaKey(
371371

372372
// TODO(tniessen): Remove the "else" branch once we drop support for OpenSSL
373373
// versions older than 1.1.1e via FIPS / dynamic linking.
374-
RSA* rsa;
374+
const RSA* rsa;
375375
if (OpenSSL_version_num() >= 0x1010105fL) {
376376
rsa = EVP_PKEY_get0_RSA(m_pkey.get());
377377
} else {
378-
rsa = static_cast<RSA*>(EVP_PKEY_get0(m_pkey.get()));
378+
rsa = static_cast<const RSA*>(EVP_PKEY_get0(m_pkey.get()));
379379
}
380380
CHECK_NOT_NULL(rsa);
381381

@@ -520,11 +520,11 @@ Maybe<bool> GetRsaKeyDetail(
520520

521521
// TODO(tniessen): Remove the "else" branch once we drop support for OpenSSL
522522
// versions older than 1.1.1e via FIPS / dynamic linking.
523-
RSA* rsa;
523+
const RSA* rsa;
524524
if (OpenSSL_version_num() >= 0x1010105fL) {
525525
rsa = EVP_PKEY_get0_RSA(m_pkey.get());
526526
} else {
527-
rsa = static_cast<RSA*>(EVP_PKEY_get0(m_pkey.get()));
527+
rsa = static_cast<const RSA*>(EVP_PKEY_get0(m_pkey.get()));
528528
}
529529
CHECK_NOT_NULL(rsa);
530530

src/crypto/crypto_sig.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool ValidateDSAParameters(EVP_PKEY* key) {
3434
#else
3535
if (FIPS_mode() && EVP_PKEY_DSA == EVP_PKEY_base_id(key)) {
3636
#endif
37-
DSA* dsa = EVP_PKEY_get0_DSA(key);
37+
const DSA* dsa = EVP_PKEY_get0_DSA(key);
3838
const BIGNUM* p;
3939
DSA_get0_pqg(dsa, &p, nullptr, nullptr);
4040
size_t L = BN_num_bits(p);
@@ -108,11 +108,11 @@ unsigned int GetBytesOfRS(const ManagedEVPPKey& pkey) {
108108
int bits, base_id = EVP_PKEY_base_id(pkey.get());
109109

110110
if (base_id == EVP_PKEY_DSA) {
111-
DSA* dsa_key = EVP_PKEY_get0_DSA(pkey.get());
111+
const DSA* dsa_key = EVP_PKEY_get0_DSA(pkey.get());
112112
// Both r and s are computed mod q, so their width is limited by that of q.
113113
bits = BN_num_bits(DSA_get0_q(dsa_key));
114114
} else if (base_id == EVP_PKEY_EC) {
115-
EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(pkey.get());
115+
const EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(pkey.get());
116116
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
117117
bits = EC_GROUP_order_bits(ec_group);
118118
} else {

0 commit comments

Comments
 (0)