Conversation
|
Looking forward to this |
|
Brad bro is busy currently. hope he will review this soon. |
boorad
left a comment
There was a problem hiding this comment.
- Left some comments.
- There are conflicts to resolve
- There's only one commit that should be in this PR. Remove the other docs-related commits.
Code Review: DH and ECDH Support (PR #862)Commit: OverviewThis PR adds Diffie-Hellman (DH) and Elliptic Curve Diffie-Hellman (ECDH) cryptographic support to react-native-quick-crypto. The implementation includes C++ native modules using OpenSSL, TypeScript API wrappers, tests, and benchmarks. Stats: ~12,300 lines added across 144 files Summary
Critical Issues1. Use of Deprecated OpenSSL APIsFiles: Both files suppress deprecation warnings: #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"The code uses deprecated low-level APIs ( Recommendation: Migrate to modern EVP-based parameter/key generation using 2. Inconsistent Memory ManagementFile: Raw pointer management with manual EVP_PKEY* _pkey = nullptr; // Raw pointer as member
// Manual cleanup scattered throughout
if (_pkey) {
EVP_PKEY_free(_pkey);
_pkey = nullptr;
}File: Mixed approach - uses std::unique_ptr<EVP_PKEY_CTX, decltype(&EVP_PKEY_CTX_free)> ctx(...); // Good
EVP_PKEY* _pkey = nullptr; // Raw pointer member - inconsistentRecommendation: Use smart pointers consistently for all OpenSSL resources. Consider a wrapper type or alias: using EVP_PKEY_ptr = std::unique_ptr<EVP_PKEY, decltype(&EVP_PKEY_free)>;3. Missing Input ValidationFile: No validation on prime length: void HybridDiffieHellman::initWithSize(double primeLength, double generator) {
// No minimum size check - allows weak parameters
if (EVP_PKEY_CTX_set_dh_paramgen_prime_len(pctx, (int)primeLength) <= 0)Recommendation: Enforce minimum key sizes (e.g., 2048 bits for DH) per security guidelines. 4. Potential Memory Leak in Error PathFile: DH_set0_pqg(peer_dh, peer_p, nullptr, peer_g);
DH_set0_key(peer_dh, peer_pub_key, nullptr);
EVP_PKEY* peer_pkey = EVP_PKEY_new();
EVP_PKEY_assign_DH(peer_pkey, peer_dh);If Recommendation: Add error checking and use RAII patterns: if (!peer_pkey) {
DH_free(peer_dh);
throw std::runtime_error("Failed to create peer EVP_PKEY");
}Medium Issues5. Double Conversion Through StringFiles: return ToNativeArrayBuffer(std::string(secret.begin(), secret.end()));Creating an intermediate Recommendation: Create a 6. Type Coercion from DoubleFile: void HybridDiffieHellman::initWithSize(double primeLength, double generator)Using if (primeLength < 0 || primeLength > INT_MAX)
throw std::runtime_error("Invalid prime length");7. Commented-Out CodeFile: // Use cached group
// std::unique_ptr<EC_GROUP, decltype(&EC_GROUP_free)> group(EC_GROUP_new_by_curve_name(_curveNid), EC_GROUP_free);
// if (!group)
// throw std::runtime_error("Failed to create group");Recommendation: Remove commented code; use git history for reference. 8. Missing
|
| Priority | Action |
|---|---|
| 🔴 High | Migrate from deprecated OpenSSL APIs to EVP + OSSL_PARAM |
| 🔴 High | Add minimum key size validation (2048-bit DH minimum) |
| 🟡 Medium | Use smart pointers consistently for all OpenSSL resources |
| 🟡 Medium | Fix potential memory leaks in error paths |
| 🟡 Medium | Remove string intermediate in ArrayBuffer conversion |
| 🟢 Low | Remove commented-out code |
| 🟢 Low | Add const to getter methods |
| 🟢 Low | Standardize error messages |
Files Reviewed
cpp/dh/HybridDiffieHellman.cpp(293 lines)cpp/dh/HybridDiffieHellman.hpp(42 lines)cpp/ecdh/HybridECDH.cpp(222 lines)cpp/ecdh/HybridECDH.hpp(49 lines)src/diffie-hellman.ts(191 lines)example/src/tests/dh/dh_tests.ts(76 lines)example/src/tests/ecdh/ecdh_tests.ts(75 lines)example/src/benchmarks/dh/dh.ts(59 lines)example/src/benchmarks/ecdh/ecdh.ts(55 lines)- Build configuration files (podspec, CMakeLists.txt)
|
Also, I don't see the following from
|
|
Hey! I’m a bit busy at the moment, but I’ll take a look when I have some free time. Thanks for the review. |
|
Re: QuickCrypto.podspec header paths - The cpp/dh and cpp/ecdh paths follow the same pattern as cpp/utils and cpp/hkdf that were already in the list. These paths are needed because QuickCryptoAutolinking.mm includes the headers with bare names (e.g., |
feat: Add DH and ECDH support with benchmarks
Description
This PR implements full support for Diffie-Hellman (DH) and Elliptic Curve Diffie-Hellman (ECDH) key exchanges in react-native-quick-crypto, complete with C++ native implementations, benchmarks, and comprehensive tests.
Changes
Core Implementation
Diffie-Hellman (DH):
DiffieHellmanclass mirroring the Node.js API (createDiffieHellman,getDiffieHellman).EVP_PKEYfor key generation and shared secret derivation.Elliptic Curve Diffie-Hellman (ECDH):
ECDHclass mirroring the Node.js API (createECDH).EC_KEYandEVP_PKEY.secp256k1,prime256v1, and others.Benchmarks & Tests
Benchmarks:
crypto-browserify(where applicable) and native baselines.Tests:
Added comprehensive test coverage validating:
Verification
Checklist
cryptoAPI.main(synced with release1.0.6).