Skip to content

Commit e30ab28

Browse files
authored
feat: subtle.generateKey for ec (#784)
1 parent cacd165 commit e30ab28

37 files changed

Lines changed: 1167 additions & 146 deletions

.github/ISSUE_TEMPLATE/BUILD_ERROR.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ body:
4141
"react-native": "^0.74.3",
4242
"react-native-quick-crypto": "^0.7.1",
4343
"@craftzdog/react-native-buffer": "^6.0.5",
44-
"react-native-fast-encoder": "^0.1.12",
4544
"react-native-quick-base64": "^2.1.2",
4645
...
4746
},

bun.lock

Lines changed: 5 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/implementation-coverage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ This document attempts to describe the implementation status of Crypto APIs/Inte
342342
### `CryptoKeyPair` algorithms
343343
| Algorithm | Status |
344344
| --------- | :----: |
345-
| `ECDH` | |
346-
| `ECDSA` | |
345+
| `ECDH` | |
346+
| `ECDSA` | |
347347
| `Ed25519` ||
348348
| `Ed448` ||
349349
| `ML-DSA-44` ||

example/ios/Podfile.lock

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,29 +1331,7 @@ PODS:
13311331
- React-RCTFBReactNativeSpec
13321332
- ReactCommon/turbomodule/core
13331333
- ReactNativeDependencies
1334-
- react-native-fast-encoder (0.2.0):
1335-
- hermes-engine
1336-
- RCTRequired
1337-
- RCTTypeSafety
1338-
- React-Core
1339-
- React-Core-prebuilt
1340-
- React-debug
1341-
- React-Fabric
1342-
- React-featureflags
1343-
- React-graphics
1344-
- React-ImageManager
1345-
- React-jsi
1346-
- React-NativeModulesApple
1347-
- React-RCTFabric
1348-
- React-renderercss
1349-
- React-rendererdebug
1350-
- React-utils
1351-
- ReactCodegen
1352-
- ReactCommon/turbomodule/bridging
1353-
- ReactCommon/turbomodule/core
1354-
- ReactNativeDependencies
1355-
- Yoga
1356-
- react-native-quick-base64 (2.2.1):
1334+
- react-native-quick-base64 (2.2.2):
13571335
- React-Core
13581336
- react-native-safe-area-context (5.6.1):
13591337
- hermes-engine
@@ -1884,8 +1862,7 @@ DEPENDENCIES:
18841862
- React-logger (from `../../node_modules/react-native/ReactCommon/logger`)
18851863
- React-Mapbuffer (from `../../node_modules/react-native/ReactCommon`)
18861864
- React-microtasksnativemodule (from `../../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`)
1887-
- react-native-fast-encoder (from `../../node_modules/react-native-fast-encoder`)
1888-
- react-native-quick-base64 (from `../node_modules/react-native-quick-base64`)
1865+
- react-native-quick-base64 (from `../../node_modules/react-native-quick-base64`)
18891866
- react-native-safe-area-context (from `../../node_modules/react-native-safe-area-context`)
18901867
- React-NativeModulesApple (from `../../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
18911868
- React-oscompat (from `../../node_modules/react-native/ReactCommon/oscompat`)
@@ -2002,10 +1979,8 @@ EXTERNAL SOURCES:
20021979
:path: "../../node_modules/react-native/ReactCommon"
20031980
React-microtasksnativemodule:
20041981
:path: "../../node_modules/react-native/ReactCommon/react/nativemodule/microtasks"
2005-
react-native-fast-encoder:
2006-
:path: "../../node_modules/react-native-fast-encoder"
20071982
react-native-quick-base64:
2008-
:path: "../node_modules/react-native-quick-base64"
1983+
:path: "../../node_modules/react-native-quick-base64"
20091984
react-native-safe-area-context:
20101985
:path: "../../node_modules/react-native-safe-area-context"
20111986
React-NativeModulesApple:
@@ -2116,8 +2091,7 @@ SPEC CHECKSUMS:
21162091
React-logger: a1c9c8dfc56711d06a21109b55908e177113e554
21172092
React-Mapbuffer: bc36232966c55d5b1cbef3b84cb97c4317fa4403
21182093
React-microtasksnativemodule: cbabfedcf6c2984e59d07f9ab553f3d277599b1b
2119-
react-native-fast-encoder: f65266038936a5ade3a54d34755fce3c7bd92483
2120-
react-native-quick-base64: 7b7f689c9b7b4d40916bf5d27e211db1040abac5
2094+
react-native-quick-base64: 6568199bb2ac8e72ecdfdc73a230fbc5c1d3aac4
21212095
react-native-safe-area-context: 42a1b4f8774b577d03b53de7326e3d5757fe9513
21222096
React-NativeModulesApple: 055e2d1417c663e7a26fc0847609f503e626e9e1
21232097
React-oscompat: 8f2893713639e12c7558750a9f7de3f08ac255b0

example/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
"react": "19.1.0",
3737
"react-native": "0.81.1",
3838
"react-native-bouncy-checkbox": "4.1.2",
39-
"react-native-fast-encoder": "0.2.0",
4039
"react-native-nitro-modules": "0.29.1",
41-
"react-native-quick-base64": "2.2.1",
40+
"react-native-quick-base64": "2.2.2",
4241
"react-native-quick-crypto": "workspace:*",
4342
"react-native-safe-area-context": "^5.2.2",
4443
"react-native-screens": "4.15.4",

example/src/tests/subtle/encrypt_decrypt.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ import aes_gcm_fixtures from '../../fixtures/aes_gcm';
3030
import { assertThrowsAsync } from '../util';
3131
import { ab2str } from 'react-native-quick-crypto';
3232

33-
import RNFE from 'react-native-fast-encoder';
34-
// @ts-expect-error polyfill types are wonky
35-
globalThis.TextEncoder = () => RNFE;
36-
3733
export type RsaEncryptDecryptTestVector = {
3834
name: string;
3935
publicKey: Buffer | null;

example/src/tests/subtle/sign_verify.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { expect } from 'chai';
55

66
const encoder = new TextEncoder();
77

8+
const SUITE = 'subtle.sign/verify';
9+
810
// // Test Sign/Verify RSASSA-PKCS1-v1_5
911
// {
1012
// async function test(data) {
@@ -53,7 +55,7 @@ const encoder = new TextEncoder();
5355
// test('hello world').then(common.mustCall());
5456
// }
5557

56-
test('subtle.sign_verify', 'ECDSA P-384', async () => {
58+
test(SUITE, 'ECDSA P-384', async () => {
5759
const pair = await subtle.generateKey(
5860
{ name: 'ECDSA', namedCurve: 'P-384' },
5961
true,
@@ -78,7 +80,7 @@ test('subtle.sign_verify', 'ECDSA P-384', async () => {
7880
).to.equal(true);
7981
});
8082

81-
test('subtle.sign_verify', 'ECDSA with HashAlgorithmIdentifier', async () => {
83+
test(SUITE, 'ECDSA with HashAlgorithmIdentifier', async () => {
8284
const pair = await subtle.generateKey(
8385
{ name: 'ECDSA', namedCurve: 'P-256' },
8486
true,

packages/react-native-quick-crypto/android/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_library(
1515
../cpp/cipher/XSalsa20Cipher.cpp
1616
../cpp/cipher/ChaCha20Cipher.cpp
1717
../cpp/cipher/ChaCha20Poly1305Cipher.cpp
18+
../cpp/ec/HybridEcKeyPair.cpp
1819
../cpp/ed25519/HybridEdKeyPair.cpp
1920
../cpp/hash/HybridHash.cpp
2021
../cpp/hmac/HybridHmac.cpp
@@ -33,6 +34,7 @@ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/QuickCrypto+autolinkin
3334
include_directories(
3435
"src/main/cpp"
3536
"../cpp/cipher"
37+
"../cpp/ec"
3638
"../cpp/ed25519"
3739
"../cpp/hash"
3840
"../cpp/hmac"
@@ -42,8 +44,6 @@ include_directories(
4244
"../cpp/utils"
4345
"../deps/fastpbkdf2"
4446
"../deps/ncrypto/include"
45-
"../build/includes" # flattened Nitro Modules headers
46-
"../../../node_modules/react-native/ReactCommon/jsi"
4747
)
4848

4949
# Third party libraries (Prefabs)

packages/react-native-quick-crypto/cpp/cipher/HybridCipherFactory.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ class HybridCipherFactory : public HybridCipherFactorySpec {
4040
// Pass tag length (default 16 if not present)
4141
size_t tag_len = args.authTagLen.has_value() ? static_cast<size_t>(args.authTagLen.value()) : 16;
4242
std::static_pointer_cast<OCBCipher>(cipherInstance)->init(args.cipherKey, args.iv, tag_len);
43+
EVP_CIPHER_free(cipher);
4344
return cipherInstance;
4445
}
4546
case EVP_CIPH_CCM_MODE: {
4647
cipherInstance = std::make_shared<CCMCipher>();
4748
cipherInstance->setArgs(args);
4849
cipherInstance->init(args.cipherKey, args.iv);
50+
EVP_CIPHER_free(cipher);
4951
return cipherInstance;
5052
}
5153
case EVP_CIPH_STREAM_CIPHER: {
@@ -55,12 +57,14 @@ class HybridCipherFactory : public HybridCipherFactorySpec {
5557
cipherInstance = std::make_shared<ChaCha20Cipher>();
5658
cipherInstance->setArgs(args);
5759
cipherInstance->init(args.cipherKey, args.iv);
60+
EVP_CIPHER_free(cipher);
5861
return cipherInstance;
5962
}
6063
if (cipherName == "chacha20-poly1305") {
6164
cipherInstance = std::make_shared<ChaCha20Poly1305Cipher>();
6265
cipherInstance->setArgs(args);
6366
cipherInstance->init(args.cipherKey, args.iv);
67+
EVP_CIPHER_free(cipher);
6468
return cipherInstance;
6569
}
6670
}
@@ -69,6 +73,7 @@ class HybridCipherFactory : public HybridCipherFactorySpec {
6973
cipherInstance = std::make_shared<HybridCipher>();
7074
cipherInstance->setArgs(args);
7175
cipherInstance->init(args.cipherKey, args.iv);
76+
EVP_CIPHER_free(cipher);
7277
return cipherInstance;
7378
}
7479
}

0 commit comments

Comments
 (0)