Skip to content

Commit 2c08d49

Browse files
authored
fix: gcm auth_tag_len bug (#721)
1 parent 9c26e9b commit 2c08d49

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

bun.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"example": {
2424
"name": "react-native-quick-crypto-example",
25-
"version": "1.0.0-beta.17",
25+
"version": "1.0.0-beta.18",
2626
"dependencies": {
2727
"@craftzdog/react-native-buffer": "6.1.0",
2828
"@noble/ciphers": "^1.3.0",
@@ -41,7 +41,7 @@
4141
"react-native-bouncy-checkbox": "4.1.2",
4242
"react-native-nitro-modules": "0.25.2",
4343
"react-native-quick-base64": "2.2.0",
44-
"react-native-quick-crypto": "1.0.0-beta.17",
44+
"react-native-quick-crypto": "workspace:*",
4545
"react-native-safe-area-context": "5.1.0",
4646
"react-native-screens": "3.35.0",
4747
"react-native-vector-icons": "^10.1.0",
@@ -75,7 +75,7 @@
7575
},
7676
"packages/react-native-quick-crypto": {
7777
"name": "react-native-quick-crypto",
78-
"version": "1.0.0-beta.17",
78+
"version": "1.0.0-beta.18",
7979
"dependencies": {
8080
"@craftzdog/react-native-buffer": "6.1.0",
8181
"events": "3.3.0",
-10.7 KB
Loading

docs/test_suite_results_ios.png

5.28 KB
Loading

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"react-native-bouncy-checkbox": "4.1.2",
3838
"react-native-nitro-modules": "0.25.2",
3939
"react-native-quick-base64": "2.2.0",
40-
"react-native-quick-crypto": "1.0.0-beta.18",
40+
"react-native-quick-crypto": "workspace:*",
4141
"react-native-safe-area-context": "5.1.0",
4242
"react-native-screens": "3.35.0",
4343
"react-native-vector-icons": "^10.1.0",

example/src/tests/cipher/cipher_tests.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const SUITE = 'cipher';
1212

1313
// --- Constants and Test Data ---
1414
const key16 = Buffer.from('a8a7d6a5d4a3d2a1a09f9e9d9c8b8a89', 'hex');
15+
const key32 = Buffer.from(
16+
'a8a7d6a5d4a3d2a1a09f9e9d9c8b8a89a8a7d6a5d4a3d2a1a09f9e9d9c8b8a89',
17+
'hex',
18+
);
1519
const iv16 = randomFillSync(new Uint8Array(16));
1620
const iv12 = randomFillSync(new Uint8Array(12)); // Common IV size for GCM/CCM/OCB
1721
const iv = Buffer.from(iv16);
@@ -106,3 +110,13 @@ allCiphers.forEach(cipherName => {
106110
}
107111
});
108112
});
113+
114+
test(SUITE, 'GCM getAuthTag', () => {
115+
const cipher = createCipheriv('aes-256-gcm', key32, iv12);
116+
cipher.setAAD(aad);
117+
cipher.update(plaintextBuffer);
118+
cipher.final();
119+
120+
const tag = cipher.getAuthTag();
121+
expect(tag.length).to.equal(16);
122+
});

packages/react-native-quick-crypto/QuickCrypto.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Pod::Spec.new do |s|
2020
s.source = { :git => "https://github.com/margelo/react-native-quick-crypto.git", :tag => "#{s.version}" }
2121

2222
sodium_enabled = ENV['SODIUM_ENABLED'] == '1'
23-
Pod::UI.puts("[QuickCrypto] Has libsodium #{sodium_enabled ? "enabled" : "disabled"}!")
23+
Pod::UI.puts("[QuickCrypto] 🧂 has libsodium #{sodium_enabled ? "enabled" : "disabled"}!")
2424

2525
if sodium_enabled
2626
# cocoapod for Sodium has not been updated for a while, so we need to build it ourselves

packages/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,9 @@ std::shared_ptr<ArrayBuffer> HybridCipher::getAuthTag() {
229229
throw std::runtime_error("Failed to get GCM/OCB auth tag: " + std::string(err_buf));
230230
}
231231

232-
size_t actual_tag_len = static_cast<size_t>(ret);
233232
uint8_t* raw_ptr = tag_buf.get();
234233
auto final_tag_buffer =
235-
std::make_shared<margelo::nitro::NativeArrayBuffer>(tag_buf.release(), actual_tag_len, [raw_ptr]() { delete[] raw_ptr; });
234+
std::make_shared<margelo::nitro::NativeArrayBuffer>(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; });
236235
return final_tag_buffer;
237236

238237
} else if (mode == EVP_CIPH_CCM_MODE) {

0 commit comments

Comments
 (0)