react-native-quick-crypto 1.0.0-beta.2 → 1.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QuickCrypto.podspec +143 -7
- package/README.md +12 -6
- package/android/CMakeLists.txt +82 -21
- package/android/build.gradle +47 -4
- package/android/src/main/cpp/cpp-adapter.cpp +3 -10
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +13 -10
- package/app.plugin.js +3 -0
- package/cpp/blake3/HybridBlake3.cpp +118 -0
- package/cpp/blake3/HybridBlake3.hpp +35 -0
- package/cpp/cipher/CCMCipher.cpp +199 -0
- package/cpp/cipher/CCMCipher.hpp +26 -0
- package/cpp/cipher/ChaCha20Cipher.cpp +97 -0
- package/cpp/cipher/ChaCha20Cipher.hpp +25 -0
- package/cpp/cipher/ChaCha20Poly1305Cipher.cpp +170 -0
- package/cpp/cipher/ChaCha20Poly1305Cipher.hpp +30 -0
- package/cpp/cipher/HybridCipher.cpp +322 -0
- package/cpp/cipher/HybridCipher.hpp +68 -0
- package/cpp/cipher/HybridCipherFactory.hpp +97 -0
- package/cpp/cipher/OCBCipher.cpp +55 -0
- package/cpp/cipher/OCBCipher.hpp +19 -0
- package/cpp/cipher/XSalsa20Cipher.cpp +61 -0
- package/cpp/cipher/XSalsa20Cipher.hpp +33 -0
- package/cpp/ec/HybridEcKeyPair.cpp +428 -0
- package/cpp/ec/HybridEcKeyPair.hpp +48 -0
- package/cpp/ed25519/HybridEdKeyPair.cpp +300 -0
- package/cpp/ed25519/HybridEdKeyPair.hpp +63 -0
- package/cpp/hash/HybridHash.cpp +185 -0
- package/cpp/hash/HybridHash.hpp +43 -0
- package/cpp/hmac/HybridHmac.cpp +95 -0
- package/cpp/hmac/HybridHmac.hpp +31 -0
- package/cpp/keys/HybridKeyObjectHandle.cpp +243 -0
- package/cpp/keys/HybridKeyObjectHandle.hpp +42 -0
- package/cpp/keys/KeyObjectData.cpp +226 -0
- package/cpp/keys/KeyObjectData.hpp +71 -0
- package/cpp/keys/node.h +5 -0
- package/cpp/pbkdf2/HybridPbkdf2.cpp +51 -0
- package/cpp/pbkdf2/HybridPbkdf2.hpp +24 -0
- package/cpp/random/HybridRandom.cpp +32 -18
- package/cpp/random/HybridRandom.hpp +18 -30
- package/cpp/rsa/HybridRsaKeyPair.cpp +154 -0
- package/cpp/rsa/HybridRsaKeyPair.hpp +43 -0
- package/cpp/utils/Macros.hpp +68 -0
- package/cpp/utils/Utils.hpp +53 -1
- package/deps/blake3/.cargo/config.toml +2 -0
- package/deps/blake3/.git-blame-ignore-revs +2 -0
- package/deps/blake3/.github/workflows/build_b3sum.py +38 -0
- package/deps/blake3/.github/workflows/ci.yml +491 -0
- package/deps/blake3/.github/workflows/tag.yml +43 -0
- package/deps/blake3/.github/workflows/upload_github_release_asset.py +73 -0
- package/deps/blake3/CONTRIBUTING.md +31 -0
- package/deps/blake3/Cargo.toml +135 -0
- package/deps/blake3/LICENSE_A2 +202 -0
- package/deps/blake3/LICENSE_A2LLVM +219 -0
- package/deps/blake3/LICENSE_CC0 +121 -0
- package/deps/blake3/README.md +229 -0
- package/deps/blake3/b3sum/Cargo.lock +513 -0
- package/deps/blake3/b3sum/Cargo.toml +26 -0
- package/deps/blake3/b3sum/README.md +72 -0
- package/deps/blake3/b3sum/src/main.rs +564 -0
- package/deps/blake3/b3sum/src/unit_tests.rs +235 -0
- package/deps/blake3/b3sum/tests/cli_tests.rs +680 -0
- package/deps/blake3/b3sum/what_does_check_do.md +176 -0
- package/deps/blake3/benches/bench.rs +623 -0
- package/deps/blake3/build.rs +389 -0
- package/deps/blake3/c/CMakeLists.txt +383 -0
- package/deps/blake3/c/CMakePresets.json +73 -0
- package/deps/blake3/c/Makefile.testing +82 -0
- package/deps/blake3/c/README.md +403 -0
- package/deps/blake3/c/blake3-config.cmake.in +14 -0
- package/deps/blake3/c/blake3.c +650 -0
- package/deps/blake3/c/blake3.h +86 -0
- package/deps/blake3/c/blake3_avx2.c +326 -0
- package/deps/blake3/c/blake3_avx2_x86-64_unix.S +1815 -0
- package/deps/blake3/c/blake3_avx2_x86-64_windows_gnu.S +1817 -0
- package/deps/blake3/c/blake3_avx2_x86-64_windows_msvc.asm +1828 -0
- package/deps/blake3/c/blake3_avx512.c +1388 -0
- package/deps/blake3/c/blake3_avx512_x86-64_unix.S +4824 -0
- package/deps/blake3/c/blake3_avx512_x86-64_windows_gnu.S +2615 -0
- package/deps/blake3/c/blake3_avx512_x86-64_windows_msvc.asm +2634 -0
- package/deps/blake3/c/blake3_c_rust_bindings/Cargo.toml +32 -0
- package/deps/blake3/c/blake3_c_rust_bindings/README.md +4 -0
- package/deps/blake3/c/blake3_c_rust_bindings/benches/bench.rs +477 -0
- package/deps/blake3/c/blake3_c_rust_bindings/build.rs +253 -0
- package/deps/blake3/c/blake3_c_rust_bindings/cross_test.sh +31 -0
- package/deps/blake3/c/blake3_c_rust_bindings/src/lib.rs +333 -0
- package/deps/blake3/c/blake3_c_rust_bindings/src/test.rs +696 -0
- package/deps/blake3/c/blake3_dispatch.c +332 -0
- package/deps/blake3/c/blake3_impl.h +333 -0
- package/deps/blake3/c/blake3_neon.c +366 -0
- package/deps/blake3/c/blake3_portable.c +160 -0
- package/deps/blake3/c/blake3_sse2.c +566 -0
- package/deps/blake3/c/blake3_sse2_x86-64_unix.S +2291 -0
- package/deps/blake3/c/blake3_sse2_x86-64_windows_gnu.S +2332 -0
- package/deps/blake3/c/blake3_sse2_x86-64_windows_msvc.asm +2350 -0
- package/deps/blake3/c/blake3_sse41.c +560 -0
- package/deps/blake3/c/blake3_sse41_x86-64_unix.S +2028 -0
- package/deps/blake3/c/blake3_sse41_x86-64_windows_gnu.S +2069 -0
- package/deps/blake3/c/blake3_sse41_x86-64_windows_msvc.asm +2089 -0
- package/deps/blake3/c/blake3_tbb.cpp +37 -0
- package/deps/blake3/c/dependencies/CMakeLists.txt +3 -0
- package/deps/blake3/c/dependencies/tbb/CMakeLists.txt +28 -0
- package/deps/blake3/c/example.c +36 -0
- package/deps/blake3/c/example_tbb.c +57 -0
- package/deps/blake3/c/libblake3.pc.in +12 -0
- package/deps/blake3/c/main.c +166 -0
- package/deps/blake3/c/test.py +97 -0
- package/deps/blake3/media/B3.svg +70 -0
- package/deps/blake3/media/BLAKE3.svg +85 -0
- package/deps/blake3/media/speed.svg +1474 -0
- package/deps/blake3/reference_impl/Cargo.toml +8 -0
- package/deps/blake3/reference_impl/README.md +14 -0
- package/deps/blake3/reference_impl/reference_impl.rs +374 -0
- package/deps/blake3/src/ffi_avx2.rs +65 -0
- package/deps/blake3/src/ffi_avx512.rs +169 -0
- package/deps/blake3/src/ffi_neon.rs +82 -0
- package/deps/blake3/src/ffi_sse2.rs +126 -0
- package/deps/blake3/src/ffi_sse41.rs +126 -0
- package/deps/blake3/src/guts.rs +60 -0
- package/deps/blake3/src/hazmat.rs +704 -0
- package/deps/blake3/src/io.rs +64 -0
- package/deps/blake3/src/join.rs +92 -0
- package/deps/blake3/src/lib.rs +1835 -0
- package/deps/blake3/src/platform.rs +587 -0
- package/deps/blake3/src/portable.rs +198 -0
- package/deps/blake3/src/rust_avx2.rs +474 -0
- package/deps/blake3/src/rust_sse2.rs +775 -0
- package/deps/blake3/src/rust_sse41.rs +766 -0
- package/deps/blake3/src/test.rs +1049 -0
- package/deps/blake3/src/traits.rs +227 -0
- package/deps/blake3/src/wasm32_simd.rs +794 -0
- package/deps/blake3/test_vectors/Cargo.toml +19 -0
- package/deps/blake3/test_vectors/cross_test.sh +25 -0
- package/deps/blake3/test_vectors/src/bin/generate.rs +4 -0
- package/deps/blake3/test_vectors/src/lib.rs +350 -0
- package/deps/blake3/test_vectors/test_vectors.json +217 -0
- package/deps/blake3/tools/compiler_version/Cargo.toml +7 -0
- package/deps/blake3/tools/compiler_version/build.rs +6 -0
- package/deps/blake3/tools/compiler_version/src/main.rs +27 -0
- package/deps/blake3/tools/instruction_set_support/Cargo.toml +6 -0
- package/deps/blake3/tools/instruction_set_support/src/main.rs +10 -0
- package/deps/blake3/tools/release.md +16 -0
- package/deps/fastpbkdf2/fastpbkdf2.c +356 -0
- package/deps/fastpbkdf2/fastpbkdf2.h +68 -0
- package/deps/ncrypto/ncrypto.cc +4679 -0
- package/deps/ncrypto/ncrypto.h +1625 -0
- package/lib/commonjs/blake3.js +98 -0
- package/lib/commonjs/blake3.js.map +1 -0
- package/lib/commonjs/cipher.js +180 -0
- package/lib/commonjs/cipher.js.map +1 -0
- package/lib/commonjs/ec.js +344 -0
- package/lib/commonjs/ec.js.map +1 -0
- package/lib/commonjs/ed.js +185 -0
- package/lib/commonjs/ed.js.map +1 -0
- package/lib/commonjs/expo-plugin/@types.js +2 -0
- package/lib/commonjs/expo-plugin/@types.js.map +1 -0
- package/lib/commonjs/expo-plugin/withRNQC.js +25 -0
- package/lib/commonjs/expo-plugin/withRNQC.js.map +1 -0
- package/lib/commonjs/expo-plugin/withSodiumAndroid.js +25 -0
- package/lib/commonjs/expo-plugin/withSodiumAndroid.js.map +1 -0
- package/lib/commonjs/expo-plugin/withSodiumIos.js +26 -0
- package/lib/commonjs/expo-plugin/withSodiumIos.js.map +1 -0
- package/lib/commonjs/expo-plugin/withXCode.js +51 -0
- package/lib/commonjs/expo-plugin/withXCode.js.map +1 -0
- package/lib/commonjs/hash.js +215 -0
- package/lib/commonjs/hash.js.map +1 -0
- package/lib/commonjs/hmac.js +109 -0
- package/lib/commonjs/hmac.js.map +1 -0
- package/lib/commonjs/index.js +152 -32
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +250 -0
- package/lib/commonjs/keys/classes.js.map +1 -0
- package/lib/commonjs/keys/generateKeyPair.js +102 -0
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -0
- package/lib/commonjs/keys/index.js +89 -0
- package/lib/commonjs/keys/index.js.map +1 -0
- package/lib/commonjs/keys/signVerify.js +41 -0
- package/lib/commonjs/keys/signVerify.js.map +1 -0
- package/lib/commonjs/keys/utils.js +123 -0
- package/lib/commonjs/keys/utils.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +89 -0
- package/lib/commonjs/pbkdf2.js.map +1 -0
- package/lib/commonjs/random.js +9 -3
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/rsa.js +129 -0
- package/lib/commonjs/rsa.js.map +1 -0
- package/lib/commonjs/specs/blake3.nitro.js +6 -0
- package/lib/commonjs/specs/blake3.nitro.js.map +1 -0
- package/lib/commonjs/specs/cipher.nitro.js +6 -0
- package/lib/commonjs/specs/cipher.nitro.js.map +1 -0
- package/lib/commonjs/specs/ecKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/ecKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/edKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/edKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/specs/hash.nitro.js +6 -0
- package/lib/commonjs/specs/hash.nitro.js.map +1 -0
- package/lib/commonjs/specs/hmac.nitro.js +6 -0
- package/lib/commonjs/specs/hmac.nitro.js.map +1 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js +6 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js +6 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/commonjs/specs/rsaKeyPair.nitro.js +6 -0
- package/lib/commonjs/specs/rsaKeyPair.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +365 -0
- package/lib/commonjs/subtle.js.map +1 -0
- package/lib/commonjs/utils/cipher.js +64 -0
- package/lib/commonjs/utils/cipher.js.map +1 -0
- package/lib/commonjs/utils/conversion.js +140 -6
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/errors.js +14 -0
- package/lib/commonjs/utils/errors.js.map +1 -0
- package/lib/commonjs/utils/hashnames.js +91 -0
- package/lib/commonjs/utils/hashnames.js.map +1 -0
- package/lib/commonjs/utils/index.js +65 -5
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/noble.js +82 -0
- package/lib/commonjs/utils/noble.js.map +1 -0
- package/lib/commonjs/utils/types.js +52 -0
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/commonjs/utils/validation.js +98 -0
- package/lib/commonjs/utils/validation.js.map +1 -0
- package/lib/module/blake3.js +90 -0
- package/lib/module/blake3.js.map +1 -0
- package/lib/module/cipher.js +173 -0
- package/lib/module/cipher.js.map +1 -0
- package/lib/module/ec.js +336 -0
- package/lib/module/ec.js.map +1 -0
- package/lib/module/ed.js +178 -0
- package/lib/module/ed.js.map +1 -0
- package/lib/module/expo-plugin/@types.js +2 -0
- package/lib/module/expo-plugin/@types.js.map +1 -0
- package/lib/module/expo-plugin/withRNQC.js +21 -0
- package/lib/module/expo-plugin/withRNQC.js.map +1 -0
- package/lib/module/expo-plugin/withSodiumAndroid.js +20 -0
- package/lib/module/expo-plugin/withSodiumAndroid.js.map +1 -0
- package/lib/module/expo-plugin/withSodiumIos.js +20 -0
- package/lib/module/expo-plugin/withSodiumIos.js.map +1 -0
- package/lib/module/expo-plugin/withXCode.js +46 -0
- package/lib/module/expo-plugin/withXCode.js.map +1 -0
- package/lib/module/hash.js +207 -0
- package/lib/module/hash.js.map +1 -0
- package/lib/module/hmac.js +104 -0
- package/lib/module/hmac.js.map +1 -0
- package/lib/module/index.js +33 -29
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +241 -0
- package/lib/module/keys/classes.js.map +1 -0
- package/lib/module/keys/generateKeyPair.js +96 -0
- package/lib/module/keys/generateKeyPair.js.map +1 -0
- package/lib/module/keys/index.js +32 -0
- package/lib/module/keys/index.js.map +1 -0
- package/lib/module/keys/signVerify.js +41 -0
- package/lib/module/keys/signVerify.js.map +1 -0
- package/lib/module/keys/utils.js +114 -0
- package/lib/module/keys/utils.js.map +1 -0
- package/lib/module/pbkdf2.js +83 -0
- package/lib/module/pbkdf2.js.map +1 -0
- package/lib/module/random.js +7 -1
- package/lib/module/random.js.map +1 -1
- package/lib/module/rsa.js +123 -0
- package/lib/module/rsa.js.map +1 -0
- package/lib/module/specs/blake3.nitro.js +4 -0
- package/lib/module/specs/blake3.nitro.js.map +1 -0
- package/lib/module/specs/cipher.nitro.js +4 -0
- package/lib/module/specs/cipher.nitro.js.map +1 -0
- package/lib/module/specs/ecKeyPair.nitro.js +4 -0
- package/lib/module/specs/ecKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/edKeyPair.nitro.js +4 -0
- package/lib/module/specs/edKeyPair.nitro.js.map +1 -0
- package/lib/module/specs/hash.nitro.js +4 -0
- package/lib/module/specs/hash.nitro.js.map +1 -0
- package/lib/module/specs/hmac.nitro.js +4 -0
- package/lib/module/specs/hmac.nitro.js.map +1 -0
- package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
- package/lib/module/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/module/specs/pbkdf2.nitro.js +4 -0
- package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/module/specs/rsaKeyPair.nitro.js +4 -0
- package/lib/module/specs/rsaKeyPair.nitro.js.map +1 -0
- package/lib/module/subtle.js +360 -0
- package/lib/module/subtle.js.map +1 -0
- package/lib/module/utils/cipher.js +56 -0
- package/lib/module/utils/cipher.js.map +1 -0
- package/lib/module/utils/conversion.js +120 -8
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/errors.js +10 -0
- package/lib/module/utils/errors.js.map +1 -0
- package/lib/module/utils/hashnames.js +89 -0
- package/lib/module/utils/hashnames.js.map +1 -0
- package/lib/module/utils/index.js +6 -5
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/noble.js +76 -0
- package/lib/module/utils/noble.js.map +1 -0
- package/lib/module/utils/types.js +53 -0
- package/lib/module/utils/types.js.map +1 -1
- package/lib/module/utils/validation.js +87 -0
- package/lib/module/utils/validation.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/blake3.d.ts +33 -0
- package/lib/typescript/blake3.d.ts.map +1 -0
- package/lib/typescript/cipher.d.ts +60 -0
- package/lib/typescript/cipher.d.ts.map +1 -0
- package/lib/typescript/ec.d.ts +13 -0
- package/lib/typescript/ec.d.ts.map +1 -0
- package/lib/typescript/ed.d.ts +43 -0
- package/lib/typescript/ed.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/@types.d.ts +8 -0
- package/lib/typescript/expo-plugin/@types.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withRNQC.d.ts +4 -0
- package/lib/typescript/expo-plugin/withRNQC.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withSodiumAndroid.d.ts +4 -0
- package/lib/typescript/expo-plugin/withSodiumAndroid.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withSodiumIos.d.ts +4 -0
- package/lib/typescript/expo-plugin/withSodiumIos.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withXCode.d.ts +9 -0
- package/lib/typescript/expo-plugin/withXCode.d.ts.map +1 -0
- package/lib/typescript/hash.d.ts +122 -0
- package/lib/typescript/hash.d.ts.map +1 -0
- package/lib/typescript/hmac.d.ts +66 -0
- package/lib/typescript/hmac.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +110 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +79 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -0
- package/lib/typescript/keys/generateKeyPair.d.ts +6 -0
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -0
- package/lib/typescript/keys/index.d.ts +7 -0
- package/lib/typescript/keys/index.d.ts.map +1 -0
- package/lib/typescript/keys/signVerify.d.ts +1 -0
- package/lib/typescript/keys/signVerify.d.ts.map +1 -0
- package/lib/typescript/keys/utils.d.ts +34 -0
- package/lib/typescript/keys/utils.d.ts.map +1 -0
- package/lib/typescript/pbkdf2.d.ts +12 -0
- package/lib/typescript/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/random.d.ts +11 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/rsa.d.ts +10 -0
- package/lib/typescript/rsa.d.ts.map +1 -0
- package/lib/typescript/specs/blake3.nitro.d.ts +15 -0
- package/lib/typescript/specs/blake3.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/cipher.nitro.d.ts +29 -0
- package/lib/typescript/specs/cipher.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/ecKeyPair.nitro.d.ts +20 -0
- package/lib/typescript/specs/ecKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts +17 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/hash.nitro.d.ts +13 -0
- package/lib/typescript/specs/hash.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/hmac.nitro.d.ts +10 -0
- package/lib/typescript/specs/hmac.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +14 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts +9 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/rsaKeyPair.nitro.d.ts +20 -0
- package/lib/typescript/specs/rsaKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/subtle.d.ts +17 -0
- package/lib/typescript/subtle.d.ts.map +1 -0
- package/lib/typescript/utils/cipher.d.ts +7 -0
- package/lib/typescript/utils/cipher.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +24 -2
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/errors.d.ts +7 -0
- package/lib/typescript/utils/errors.d.ts.map +1 -0
- package/lib/typescript/utils/hashnames.d.ts +13 -0
- package/lib/typescript/utils/hashnames.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -5
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/utils/noble.d.ts +19 -0
- package/lib/typescript/utils/noble.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +252 -2
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/utils/validation.d.ts +13 -0
- package/lib/typescript/utils/validation.d.ts.map +1 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +47 -4
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +4 -3
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +144 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +35 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +11 -8
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +11 -3
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +5 -3
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +16 -7
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +135 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +12 -0
- package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +84 -0
- package/nitrogen/generated/shared/c++/CipherArgs.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp +77 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +30 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +75 -0
- package/nitrogen/generated/shared/c++/HybridHashSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridHashSpec.hpp +75 -0
- package/nitrogen/generated/shared/c++/HybridHmacSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +92 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +2 -3
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +9 -6
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +77 -0
- package/nitrogen/generated/shared/c++/JWK.hpp +161 -0
- package/nitrogen/generated/shared/c++/JWKkty.hpp +84 -0
- package/nitrogen/generated/shared/c++/JWKuse.hpp +76 -0
- package/nitrogen/generated/shared/c++/KFormatType.hpp +63 -0
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +92 -0
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +64 -0
- package/nitrogen/generated/shared/c++/KeyObject.hpp +67 -0
- package/nitrogen/generated/shared/c++/KeyType.hpp +63 -0
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +116 -0
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +80 -0
- package/package.json +66 -39
- package/src/blake3.ts +123 -0
- package/src/cipher.ts +335 -0
- package/src/ec.ts +432 -0
- package/src/ed.ts +256 -0
- package/src/expo-plugin/@types.ts +7 -0
- package/src/expo-plugin/withRNQC.ts +23 -0
- package/src/expo-plugin/withSodiumAndroid.ts +24 -0
- package/src/expo-plugin/withSodiumIos.ts +30 -0
- package/src/expo-plugin/withXCode.ts +55 -0
- package/src/hash.ts +274 -0
- package/src/hmac.ts +135 -0
- package/src/index.ts +32 -29
- package/src/keys/classes.ts +317 -0
- package/src/keys/generateKeyPair.ts +145 -0
- package/src/keys/index.ts +52 -0
- package/src/keys/signVerify.ts +39 -0
- package/src/keys/utils.ts +190 -0
- package/src/pbkdf2.ts +154 -0
- package/src/random.ts +26 -23
- package/src/rsa.ts +176 -0
- package/src/specs/blake3.nitro.ts +12 -0
- package/src/specs/cipher.nitro.ts +25 -0
- package/src/specs/ecKeyPair.nitro.ts +38 -0
- package/src/specs/edKeyPair.nitro.ts +43 -0
- package/src/specs/hash.nitro.ts +10 -0
- package/src/specs/hmac.nitro.ts +7 -0
- package/src/specs/keyObjectHandle.nitro.ts +31 -0
- package/src/specs/pbkdf2.nitro.ts +18 -0
- package/src/specs/random.nitro.ts +2 -2
- package/src/specs/rsaKeyPair.nitro.ts +33 -0
- package/src/subtle.ts +614 -0
- package/src/utils/cipher.ts +60 -0
- package/src/utils/conversion.ts +143 -9
- package/src/utils/errors.ts +15 -0
- package/src/utils/hashnames.ts +98 -0
- package/src/utils/index.ts +6 -6
- package/src/utils/noble.ts +85 -0
- package/src/utils/types.ts +423 -3
- package/src/utils/validation.ts +130 -0
- package/ios/QuickCryptoOnLoad.mm +0 -19
- package/lib/module/package.json +0 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
#include <algorithm> // For std::sort
|
|
2
|
+
#include <cstring> // For std::memcpy
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <stdexcept>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
#include "HybridCipher.hpp"
|
|
9
|
+
#include "Utils.hpp"
|
|
10
|
+
|
|
11
|
+
#include <openssl/err.h>
|
|
12
|
+
#include <openssl/evp.h>
|
|
13
|
+
|
|
14
|
+
namespace margelo::nitro::crypto {
|
|
15
|
+
|
|
16
|
+
HybridCipher::~HybridCipher() {
|
|
17
|
+
if (ctx) {
|
|
18
|
+
EVP_CIPHER_CTX_free(ctx);
|
|
19
|
+
// No need to set ctx = nullptr here, object is being destroyed
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void HybridCipher::checkCtx() const {
|
|
24
|
+
if (!ctx) {
|
|
25
|
+
throw std::runtime_error("Cipher context is not initialized or has been disposed.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
bool HybridCipher::maybePassAuthTagToOpenSSL() {
|
|
30
|
+
if (auth_tag_state == kAuthTagKnown) {
|
|
31
|
+
OSSL_PARAM params[] = {OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG, auth_tag, auth_tag_len),
|
|
32
|
+
OSSL_PARAM_construct_end()};
|
|
33
|
+
if (!EVP_CIPHER_CTX_set_params(ctx, params)) {
|
|
34
|
+
unsigned long err = ERR_get_error();
|
|
35
|
+
char err_buf[256];
|
|
36
|
+
ERR_error_string_n(err, err_buf, sizeof(err_buf));
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
auth_tag_state = kAuthTagPassedToOpenSSL;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void HybridCipher::init(const std::shared_ptr<ArrayBuffer> cipher_key, const std::shared_ptr<ArrayBuffer> iv) {
|
|
45
|
+
// Clean up any existing context
|
|
46
|
+
if (ctx) {
|
|
47
|
+
EVP_CIPHER_CTX_free(ctx);
|
|
48
|
+
ctx = nullptr;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 1. Get cipher implementation by name
|
|
52
|
+
const EVP_CIPHER* cipher = EVP_get_cipherbyname(cipher_type.c_str());
|
|
53
|
+
if (!cipher) {
|
|
54
|
+
throw std::runtime_error("Unknown cipher " + cipher_type);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 2. Create a new context
|
|
58
|
+
ctx = EVP_CIPHER_CTX_new();
|
|
59
|
+
if (!ctx) {
|
|
60
|
+
throw std::runtime_error("Failed to create cipher context");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Initialise the encryption/decryption operation with the cipher type.
|
|
64
|
+
// Key and IV will be set later by the derived class if needed.
|
|
65
|
+
if (EVP_CipherInit_ex(ctx, cipher, nullptr, nullptr, nullptr, is_cipher) != 1) {
|
|
66
|
+
unsigned long err = ERR_get_error();
|
|
67
|
+
char err_buf[256];
|
|
68
|
+
ERR_error_string_n(err, err_buf, sizeof(err_buf));
|
|
69
|
+
EVP_CIPHER_CTX_free(ctx);
|
|
70
|
+
ctx = nullptr;
|
|
71
|
+
throw std::runtime_error("HybridCipher: Failed initial CipherInit setup: " + std::string(err_buf));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// For base hybrid cipher, set key and IV immediately.
|
|
75
|
+
// Derived classes like CCM might override init and handle this differently.
|
|
76
|
+
auto native_key = ToNativeArrayBuffer(cipher_key);
|
|
77
|
+
auto native_iv = ToNativeArrayBuffer(iv);
|
|
78
|
+
const unsigned char* key_ptr = reinterpret_cast<const unsigned char*>(native_key->data());
|
|
79
|
+
const unsigned char* iv_ptr = reinterpret_cast<const unsigned char*>(native_iv->data());
|
|
80
|
+
|
|
81
|
+
if (EVP_CipherInit_ex(ctx, nullptr, nullptr, key_ptr, iv_ptr, is_cipher) != 1) {
|
|
82
|
+
unsigned long err = ERR_get_error();
|
|
83
|
+
char err_buf[256];
|
|
84
|
+
ERR_error_string_n(err, err_buf, sizeof(err_buf));
|
|
85
|
+
EVP_CIPHER_CTX_free(ctx);
|
|
86
|
+
ctx = nullptr;
|
|
87
|
+
throw std::runtime_error("HybridCipher: Failed to set key/IV: " + std::string(err_buf));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
std::shared_ptr<ArrayBuffer> HybridCipher::update(const std::shared_ptr<ArrayBuffer>& data) {
|
|
92
|
+
auto native_data = ToNativeArrayBuffer(data);
|
|
93
|
+
checkCtx();
|
|
94
|
+
size_t in_len = native_data->size();
|
|
95
|
+
if (in_len > INT_MAX) {
|
|
96
|
+
throw std::runtime_error("Message too long");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
int out_len = in_len + EVP_CIPHER_CTX_block_size(ctx);
|
|
100
|
+
uint8_t* out = new uint8_t[out_len];
|
|
101
|
+
// Perform the cipher update operation. The real size of the output is
|
|
102
|
+
// returned in out_len
|
|
103
|
+
EVP_CipherUpdate(ctx, out, &out_len, native_data->data(), in_len);
|
|
104
|
+
|
|
105
|
+
// Create and return a new buffer of exact size needed
|
|
106
|
+
return std::make_shared<NativeArrayBuffer>(out, out_len, [=]() { delete[] out; });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
std::shared_ptr<ArrayBuffer> HybridCipher::final() {
|
|
110
|
+
checkCtx();
|
|
111
|
+
// Block size is max output size for final, unless EVP_CIPH_NO_PADDING is set
|
|
112
|
+
int block_size = EVP_CIPHER_CTX_block_size(ctx);
|
|
113
|
+
if (block_size <= 0)
|
|
114
|
+
block_size = 16; // Default if block size is weird (e.g., 0)
|
|
115
|
+
auto out_buf = std::make_unique<uint8_t[]>(block_size);
|
|
116
|
+
int out_len = 0;
|
|
117
|
+
|
|
118
|
+
int ret = EVP_CipherFinal_ex(ctx, out_buf.get(), &out_len);
|
|
119
|
+
if (!ret) {
|
|
120
|
+
unsigned long err = ERR_get_error();
|
|
121
|
+
char err_buf[256];
|
|
122
|
+
ERR_error_string_n(err, err_buf, sizeof(err_buf));
|
|
123
|
+
// Don't free context on error here either, rely on destructor
|
|
124
|
+
throw std::runtime_error("Cipher final failed: " + std::string(err_buf));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Get raw pointer before releasing unique_ptr
|
|
128
|
+
uint8_t* raw_ptr = out_buf.get();
|
|
129
|
+
// Create the specific NativeArrayBuffer first, using full namespace
|
|
130
|
+
auto native_final_chunk = std::make_shared<margelo::nitro::NativeArrayBuffer>(out_buf.release(), static_cast<size_t>(out_len),
|
|
131
|
+
[raw_ptr]() { delete[] raw_ptr; });
|
|
132
|
+
|
|
133
|
+
// Context should NOT be freed here. It might be needed for getAuthTag() for GCM/OCB.
|
|
134
|
+
// The context will be freed by the destructor (~HybridCipher) when the object goes out of scope.
|
|
135
|
+
|
|
136
|
+
// Return the shared_ptr<NativeArrayBuffer> (implicit upcast to shared_ptr<ArrayBuffer>)
|
|
137
|
+
return native_final_chunk;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
bool HybridCipher::setAAD(const std::shared_ptr<ArrayBuffer>& data, std::optional<double> plaintextLength) {
|
|
141
|
+
checkCtx();
|
|
142
|
+
auto native_data = ToNativeArrayBuffer(data);
|
|
143
|
+
|
|
144
|
+
// Set the AAD
|
|
145
|
+
int out_len;
|
|
146
|
+
if (!EVP_CipherUpdate(ctx, nullptr, &out_len, native_data->data(), native_data->size())) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
has_aad = true;
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
bool HybridCipher::setAutoPadding(bool autoPad) {
|
|
155
|
+
checkCtx();
|
|
156
|
+
return EVP_CIPHER_CTX_set_padding(ctx, autoPad) == 1;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
bool HybridCipher::setAuthTag(const std::shared_ptr<ArrayBuffer>& tag) {
|
|
160
|
+
checkCtx();
|
|
161
|
+
|
|
162
|
+
if (is_cipher) {
|
|
163
|
+
throw std::runtime_error("setAuthTag can only be called during decryption.");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
auto native_tag = ToNativeArrayBuffer(tag);
|
|
167
|
+
size_t tag_len = native_tag->size();
|
|
168
|
+
uint8_t* tag_ptr = native_tag->data();
|
|
169
|
+
|
|
170
|
+
int mode = EVP_CIPHER_CTX_mode(ctx);
|
|
171
|
+
|
|
172
|
+
if (mode == EVP_CIPH_GCM_MODE || mode == EVP_CIPH_OCB_MODE) {
|
|
173
|
+
// Use EVP_CTRL_AEAD_SET_TAG for GCM/OCB decryption
|
|
174
|
+
if (tag_len < 1 || tag_len > 16) { // Check tag length bounds for GCM/OCB
|
|
175
|
+
throw std::runtime_error("Invalid auth tag length for GCM/OCB. Must be between 1 and 16 bytes.");
|
|
176
|
+
}
|
|
177
|
+
// Add check for valid cipher in context before setting tag
|
|
178
|
+
// Use the correct OpenSSL 3 function: EVP_CIPHER_CTX_cipher
|
|
179
|
+
if (!EVP_CIPHER_CTX_cipher(ctx)) {
|
|
180
|
+
throw std::runtime_error("Context has no cipher set before setting GCM/OCB tag");
|
|
181
|
+
}
|
|
182
|
+
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, tag_len, tag_ptr) <= 0) {
|
|
183
|
+
unsigned long err = ERR_get_error();
|
|
184
|
+
char err_buf[256];
|
|
185
|
+
ERR_error_string_n(err, err_buf, sizeof(err_buf));
|
|
186
|
+
// Include the error code in the message
|
|
187
|
+
throw std::runtime_error("Failed to set GCM/OCB auth tag: " + std::string(err_buf) + " (code: " + std::to_string(err) + ")");
|
|
188
|
+
}
|
|
189
|
+
auth_tag_state = kAuthTagPassedToOpenSSL; // Mark state
|
|
190
|
+
return true;
|
|
191
|
+
|
|
192
|
+
} else if (mode == EVP_CIPH_CCM_MODE) {
|
|
193
|
+
// Store tag internally for CCM decryption (used in CCMCipher::final)
|
|
194
|
+
if (tag_len < 4 || tag_len > 16) { // Check tag length bounds for CCM
|
|
195
|
+
throw std::runtime_error("Invalid auth tag length for CCM. Must be between 4 and 16 bytes.");
|
|
196
|
+
}
|
|
197
|
+
auth_tag_state = kAuthTagKnown; // Correct state enum value
|
|
198
|
+
auth_tag_len = tag_len;
|
|
199
|
+
// Copy directly into the member buffer (assuming uint8_t auth_tag[16])
|
|
200
|
+
std::memcpy(auth_tag, tag_ptr, tag_len);
|
|
201
|
+
return true;
|
|
202
|
+
|
|
203
|
+
} else {
|
|
204
|
+
// Not an AEAD mode that supports setAuthTag for decryption
|
|
205
|
+
throw std::runtime_error("setAuthTag is not supported for the current cipher mode.");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
std::shared_ptr<ArrayBuffer> HybridCipher::getAuthTag() {
|
|
210
|
+
checkCtx();
|
|
211
|
+
|
|
212
|
+
int mode = EVP_CIPHER_CTX_mode(ctx);
|
|
213
|
+
|
|
214
|
+
if (!is_cipher) {
|
|
215
|
+
throw std::runtime_error("getAuthTag can only be called during encryption.");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (mode == EVP_CIPH_GCM_MODE || mode == EVP_CIPH_OCB_MODE) {
|
|
219
|
+
// Retrieve the tag using EVP_CIPHER_CTX_ctrl for GCM/OCB
|
|
220
|
+
constexpr int max_tag_len = 16; // GCM/OCB tags are typically up to 16 bytes
|
|
221
|
+
auto tag_buf = std::make_unique<uint8_t[]>(max_tag_len);
|
|
222
|
+
|
|
223
|
+
int ret = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, max_tag_len, tag_buf.get());
|
|
224
|
+
|
|
225
|
+
if (ret <= 0) {
|
|
226
|
+
unsigned long err = ERR_get_error();
|
|
227
|
+
char err_buf[256];
|
|
228
|
+
ERR_error_string_n(err, err_buf, sizeof(err_buf));
|
|
229
|
+
throw std::runtime_error("Failed to get GCM/OCB auth tag: " + std::string(err_buf));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
uint8_t* raw_ptr = tag_buf.get();
|
|
233
|
+
auto final_tag_buffer =
|
|
234
|
+
std::make_shared<margelo::nitro::NativeArrayBuffer>(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; });
|
|
235
|
+
return final_tag_buffer;
|
|
236
|
+
|
|
237
|
+
} else if (mode == EVP_CIPH_CCM_MODE) {
|
|
238
|
+
// CCM: allow getAuthTag after encryption/finalization
|
|
239
|
+
if (auth_tag_len > 0 && auth_tag_state == kAuthTagKnown) {
|
|
240
|
+
// Return the stored tag buffer
|
|
241
|
+
auto tag_buf = std::make_unique<uint8_t[]>(auth_tag_len);
|
|
242
|
+
std::memcpy(tag_buf.get(), auth_tag, auth_tag_len);
|
|
243
|
+
uint8_t* raw_ptr = tag_buf.get();
|
|
244
|
+
auto final_tag_buffer =
|
|
245
|
+
std::make_shared<margelo::nitro::NativeArrayBuffer>(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; });
|
|
246
|
+
return final_tag_buffer;
|
|
247
|
+
} else {
|
|
248
|
+
throw std::runtime_error("CCM: Auth tag not available. Ensure encryption is finalized before calling getAuthTag.");
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
// Not an AEAD mode that supports getAuthTag post-encryption
|
|
252
|
+
throw std::runtime_error("getAuthTag is not supported for the current cipher mode.");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
int HybridCipher::getMode() {
|
|
257
|
+
if (!ctx) {
|
|
258
|
+
throw std::runtime_error("Cipher not initialized. Did you call setArgs()?");
|
|
259
|
+
}
|
|
260
|
+
return EVP_CIPHER_CTX_get_mode(ctx);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
void HybridCipher::setArgs(const CipherArgs& args) {
|
|
264
|
+
this->is_cipher = args.isCipher;
|
|
265
|
+
this->cipher_type = args.cipherType;
|
|
266
|
+
|
|
267
|
+
// Reset auth tag state
|
|
268
|
+
auth_tag_state = kAuthTagUnknown;
|
|
269
|
+
std::memset(auth_tag, 0, EVP_GCM_TLS_TAG_LEN);
|
|
270
|
+
|
|
271
|
+
// Set auth tag length from args or use default
|
|
272
|
+
if (args.authTagLen.has_value()) {
|
|
273
|
+
if (!CheckIsUint32(args.authTagLen.value())) {
|
|
274
|
+
throw std::runtime_error("authTagLen must be uint32");
|
|
275
|
+
}
|
|
276
|
+
uint32_t requested_len = static_cast<uint32_t>(args.authTagLen.value());
|
|
277
|
+
if (requested_len > EVP_GCM_TLS_TAG_LEN) {
|
|
278
|
+
throw std::runtime_error("Authentication tag length too large");
|
|
279
|
+
}
|
|
280
|
+
this->auth_tag_len = requested_len;
|
|
281
|
+
} else {
|
|
282
|
+
// Default to 16 bytes for all authenticated modes
|
|
283
|
+
this->auth_tag_len = kDefaultAuthTagLength;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Corrected callback signature for EVP_CIPHER_do_all_provided
|
|
288
|
+
void collect_ciphers(EVP_CIPHER* cipher, void* arg) {
|
|
289
|
+
auto* names = static_cast<std::vector<std::string>*>(arg);
|
|
290
|
+
if (cipher == nullptr)
|
|
291
|
+
return;
|
|
292
|
+
// Note: EVP_CIPHER_get0_name expects const EVP_CIPHER*, but the callback provides EVP_CIPHER*.
|
|
293
|
+
// This implicit const cast should be safe here.
|
|
294
|
+
const char* name = EVP_CIPHER_get0_name(cipher);
|
|
295
|
+
if (name != nullptr) {
|
|
296
|
+
std::string name_str(name);
|
|
297
|
+
if (name_str == "NULL" || name_str.find("CTS") != std::string::npos ||
|
|
298
|
+
name_str.find("SIV") != std::string::npos || // Covers -SIV and -GCM-SIV
|
|
299
|
+
name_str.find("WRAP") != std::string::npos || // Covers -WRAP-INV and -WRAP-PAD-INV
|
|
300
|
+
name_str.find("SM4-") != std::string::npos) {
|
|
301
|
+
return; // Skip adding this cipher
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// If not filtered out, add it to the list
|
|
305
|
+
names->push_back(name_str); // Use name_str here
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
std::vector<std::string> HybridCipher::getSupportedCiphers() {
|
|
310
|
+
std::vector<std::string> cipher_names;
|
|
311
|
+
|
|
312
|
+
// Use the simpler approach with the separate callback
|
|
313
|
+
EVP_CIPHER_do_all_provided(nullptr, // Default library context
|
|
314
|
+
collect_ciphers, &cipher_names);
|
|
315
|
+
|
|
316
|
+
// OpenSSL 3 doesn't guarantee sorted output with _do_all_provided, sort manually
|
|
317
|
+
std::sort(cipher_names.begin(), cipher_names.end());
|
|
318
|
+
|
|
319
|
+
return cipher_names;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <openssl/core_names.h>
|
|
4
|
+
#include <openssl/err.h>
|
|
5
|
+
#include <openssl/evp.h>
|
|
6
|
+
#include <openssl/param_build.h>
|
|
7
|
+
#include <optional>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
#include "HybridCipherSpec.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::crypto {
|
|
14
|
+
|
|
15
|
+
// Default tag length for OCB, SIV, CCM, ChaCha20-Poly1305
|
|
16
|
+
constexpr unsigned kDefaultAuthTagLength = 16;
|
|
17
|
+
|
|
18
|
+
class HybridCipher : public HybridCipherSpec {
|
|
19
|
+
public:
|
|
20
|
+
HybridCipher() : HybridObject(TAG) {}
|
|
21
|
+
~HybridCipher() override;
|
|
22
|
+
|
|
23
|
+
public:
|
|
24
|
+
// Methods
|
|
25
|
+
std::shared_ptr<ArrayBuffer> update(const std::shared_ptr<ArrayBuffer>& data) override;
|
|
26
|
+
|
|
27
|
+
std::shared_ptr<ArrayBuffer> final() override;
|
|
28
|
+
|
|
29
|
+
virtual void init(const std::shared_ptr<ArrayBuffer> cipher_key, const std::shared_ptr<ArrayBuffer> iv);
|
|
30
|
+
|
|
31
|
+
void setArgs(const CipherArgs& args) override;
|
|
32
|
+
|
|
33
|
+
bool setAAD(const std::shared_ptr<ArrayBuffer>& data, std::optional<double> plaintextLength) override;
|
|
34
|
+
|
|
35
|
+
bool setAutoPadding(bool autoPad) override;
|
|
36
|
+
|
|
37
|
+
bool setAuthTag(const std::shared_ptr<ArrayBuffer>& tag) override;
|
|
38
|
+
|
|
39
|
+
std::shared_ptr<ArrayBuffer> getAuthTag() override;
|
|
40
|
+
|
|
41
|
+
std::vector<std::string> getSupportedCiphers() override;
|
|
42
|
+
|
|
43
|
+
protected:
|
|
44
|
+
// Protected enums for state management
|
|
45
|
+
enum CipherKind { kCipher, kDecipher };
|
|
46
|
+
enum UpdateResult { kSuccess, kErrorMessageSize, kErrorState };
|
|
47
|
+
enum AuthTagState { kAuthTagUnknown, kAuthTagKnown, kAuthTagPassedToOpenSSL };
|
|
48
|
+
|
|
49
|
+
protected:
|
|
50
|
+
// Properties
|
|
51
|
+
bool is_cipher = true;
|
|
52
|
+
std::string cipher_type;
|
|
53
|
+
EVP_CIPHER_CTX* ctx = nullptr;
|
|
54
|
+
bool pending_auth_failed = false;
|
|
55
|
+
bool has_aad = false;
|
|
56
|
+
uint8_t auth_tag[EVP_GCM_TLS_TAG_LEN];
|
|
57
|
+
AuthTagState auth_tag_state;
|
|
58
|
+
unsigned int auth_tag_len = 0;
|
|
59
|
+
int max_message_size;
|
|
60
|
+
|
|
61
|
+
protected:
|
|
62
|
+
// Methods
|
|
63
|
+
int getMode();
|
|
64
|
+
void checkCtx() const;
|
|
65
|
+
bool maybePassAuthTagToOpenSSL();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <openssl/evp.h>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
#include "CCMCipher.hpp"
|
|
8
|
+
#include "ChaCha20Cipher.hpp"
|
|
9
|
+
#include "ChaCha20Poly1305Cipher.hpp"
|
|
10
|
+
#include "HybridCipherFactorySpec.hpp"
|
|
11
|
+
#include "OCBCipher.hpp"
|
|
12
|
+
#include "Utils.hpp"
|
|
13
|
+
#include "XSalsa20Cipher.hpp"
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::crypto {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
class HybridCipherFactory : public HybridCipherFactorySpec {
|
|
20
|
+
public:
|
|
21
|
+
HybridCipherFactory() : HybridObject(TAG) {}
|
|
22
|
+
~HybridCipherFactory() = default;
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
// Factory method exposed to JS
|
|
26
|
+
inline std::shared_ptr<HybridCipherSpec> createCipher(const CipherArgs& args) {
|
|
27
|
+
// Create the appropriate cipher instance based on mode
|
|
28
|
+
std::shared_ptr<HybridCipher> cipherInstance;
|
|
29
|
+
|
|
30
|
+
// OpenSSL
|
|
31
|
+
// temporary cipher context to determine the mode
|
|
32
|
+
EVP_CIPHER* cipher = EVP_CIPHER_fetch(nullptr, args.cipherType.c_str(), nullptr);
|
|
33
|
+
if (cipher) {
|
|
34
|
+
int mode = EVP_CIPHER_get_mode(cipher);
|
|
35
|
+
|
|
36
|
+
switch (mode) {
|
|
37
|
+
case EVP_CIPH_OCB_MODE: {
|
|
38
|
+
cipherInstance = std::make_shared<OCBCipher>();
|
|
39
|
+
cipherInstance->setArgs(args);
|
|
40
|
+
// Pass tag length (default 16 if not present)
|
|
41
|
+
size_t tag_len = args.authTagLen.has_value() ? static_cast<size_t>(args.authTagLen.value()) : 16;
|
|
42
|
+
std::static_pointer_cast<OCBCipher>(cipherInstance)->init(args.cipherKey, args.iv, tag_len);
|
|
43
|
+
EVP_CIPHER_free(cipher);
|
|
44
|
+
return cipherInstance;
|
|
45
|
+
}
|
|
46
|
+
case EVP_CIPH_CCM_MODE: {
|
|
47
|
+
cipherInstance = std::make_shared<CCMCipher>();
|
|
48
|
+
cipherInstance->setArgs(args);
|
|
49
|
+
cipherInstance->init(args.cipherKey, args.iv);
|
|
50
|
+
EVP_CIPHER_free(cipher);
|
|
51
|
+
return cipherInstance;
|
|
52
|
+
}
|
|
53
|
+
case EVP_CIPH_STREAM_CIPHER: {
|
|
54
|
+
// Check for ChaCha20 variants specifically
|
|
55
|
+
std::string cipherName = toLower(args.cipherType);
|
|
56
|
+
if (cipherName == "chacha20") {
|
|
57
|
+
cipherInstance = std::make_shared<ChaCha20Cipher>();
|
|
58
|
+
cipherInstance->setArgs(args);
|
|
59
|
+
cipherInstance->init(args.cipherKey, args.iv);
|
|
60
|
+
EVP_CIPHER_free(cipher);
|
|
61
|
+
return cipherInstance;
|
|
62
|
+
}
|
|
63
|
+
if (cipherName == "chacha20-poly1305") {
|
|
64
|
+
cipherInstance = std::make_shared<ChaCha20Poly1305Cipher>();
|
|
65
|
+
cipherInstance->setArgs(args);
|
|
66
|
+
cipherInstance->init(args.cipherKey, args.iv);
|
|
67
|
+
EVP_CIPHER_free(cipher);
|
|
68
|
+
return cipherInstance;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
default: {
|
|
72
|
+
// Default case for other ciphers
|
|
73
|
+
cipherInstance = std::make_shared<HybridCipher>();
|
|
74
|
+
cipherInstance->setArgs(args);
|
|
75
|
+
cipherInstance->init(args.cipherKey, args.iv);
|
|
76
|
+
EVP_CIPHER_free(cipher);
|
|
77
|
+
return cipherInstance;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
EVP_CIPHER_free(cipher);
|
|
82
|
+
|
|
83
|
+
// libsodium
|
|
84
|
+
std::string cipherName = toLower(args.cipherType);
|
|
85
|
+
if (cipherName == "xsalsa20") {
|
|
86
|
+
cipherInstance = std::make_shared<XSalsa20Cipher>();
|
|
87
|
+
cipherInstance->setArgs(args);
|
|
88
|
+
cipherInstance->init(args.cipherKey, args.iv);
|
|
89
|
+
return cipherInstance;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Unsupported cipher type
|
|
93
|
+
throw std::runtime_error("Unsupported or unknown cipher type: " + args.cipherType);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#include "OCBCipher.hpp"
|
|
2
|
+
#include <cstring>
|
|
3
|
+
#include <openssl/err.h>
|
|
4
|
+
#include <openssl/evp.h>
|
|
5
|
+
|
|
6
|
+
#include "Utils.hpp"
|
|
7
|
+
#include <cstdio>
|
|
8
|
+
#include <iomanip>
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::crypto {
|
|
11
|
+
|
|
12
|
+
void OCBCipher::init(const std::shared_ptr<ArrayBuffer>& key, const std::shared_ptr<ArrayBuffer>& iv, size_t tag_len) {
|
|
13
|
+
HybridCipher::init(key, iv);
|
|
14
|
+
auth_tag_len = tag_len;
|
|
15
|
+
|
|
16
|
+
// Set tag length for OCB (must be 12-16 bytes)
|
|
17
|
+
if (auth_tag_len < 12 || auth_tag_len > 16) {
|
|
18
|
+
throw std::runtime_error("OCB tag length must be between 12 and 16 bytes");
|
|
19
|
+
}
|
|
20
|
+
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, auth_tag_len, nullptr) != 1) {
|
|
21
|
+
throw std::runtime_error("Failed to set OCB tag length");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
std::shared_ptr<ArrayBuffer> OCBCipher::getAuthTag() {
|
|
26
|
+
checkCtx();
|
|
27
|
+
if (!is_cipher) {
|
|
28
|
+
throw std::runtime_error("getAuthTag can only be called during encryption.");
|
|
29
|
+
}
|
|
30
|
+
auto tag_buf = std::make_unique<uint8_t[]>(auth_tag_len);
|
|
31
|
+
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, auth_tag_len, tag_buf.get()) != 1) {
|
|
32
|
+
throw std::runtime_error("Failed to get OCB auth tag");
|
|
33
|
+
}
|
|
34
|
+
uint8_t* raw_ptr = tag_buf.get();
|
|
35
|
+
return std::make_shared<NativeArrayBuffer>(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
bool OCBCipher::setAuthTag(const std::shared_ptr<ArrayBuffer>& tag) {
|
|
39
|
+
checkCtx();
|
|
40
|
+
if (is_cipher) {
|
|
41
|
+
throw std::runtime_error("setAuthTag can only be called during decryption.");
|
|
42
|
+
}
|
|
43
|
+
auto native_tag = ToNativeArrayBuffer(tag);
|
|
44
|
+
size_t tag_len = native_tag->size();
|
|
45
|
+
if (tag_len < 12 || tag_len > 16) {
|
|
46
|
+
throw std::runtime_error("Invalid OCB tag length");
|
|
47
|
+
}
|
|
48
|
+
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, tag_len, native_tag->data()) != 1) {
|
|
49
|
+
throw std::runtime_error("Failed to set OCB auth tag");
|
|
50
|
+
}
|
|
51
|
+
auth_tag_len = tag_len;
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "HybridCipher.hpp"
|
|
4
|
+
|
|
5
|
+
namespace margelo::nitro::crypto {
|
|
6
|
+
|
|
7
|
+
class OCBCipher : public HybridCipher {
|
|
8
|
+
public:
|
|
9
|
+
OCBCipher() : HybridObject(TAG) {}
|
|
10
|
+
void init(const std::shared_ptr<ArrayBuffer>& key, const std::shared_ptr<ArrayBuffer>& iv, size_t tag_len = 16);
|
|
11
|
+
|
|
12
|
+
std::shared_ptr<ArrayBuffer> getAuthTag() override;
|
|
13
|
+
bool setAuthTag(const std::shared_ptr<ArrayBuffer>& tag) override;
|
|
14
|
+
|
|
15
|
+
protected:
|
|
16
|
+
size_t auth_tag_len = 16;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#include <cstring> // For std::memcpy
|
|
2
|
+
#include <stdexcept> // For std::runtime_error
|
|
3
|
+
|
|
4
|
+
#include "NitroModules/ArrayBuffer.hpp"
|
|
5
|
+
#include "Utils.hpp"
|
|
6
|
+
#include "XSalsa20Cipher.hpp"
|
|
7
|
+
|
|
8
|
+
namespace margelo::nitro::crypto {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Initialize the cipher with a key and a nonce (using iv argument as nonce)
|
|
12
|
+
*/
|
|
13
|
+
void XSalsa20Cipher::init(const std::shared_ptr<ArrayBuffer> cipher_key, const std::shared_ptr<ArrayBuffer> iv) {
|
|
14
|
+
auto native_key = ToNativeArrayBuffer(cipher_key);
|
|
15
|
+
auto native_iv = ToNativeArrayBuffer(iv);
|
|
16
|
+
|
|
17
|
+
// Validate key size
|
|
18
|
+
if (native_key->size() < crypto_stream_KEYBYTES) {
|
|
19
|
+
throw std::runtime_error("XSalsa20 key too short: expected " + std::to_string(crypto_stream_KEYBYTES) + " bytes, got " +
|
|
20
|
+
std::to_string(native_key->size()) + " bytes.");
|
|
21
|
+
}
|
|
22
|
+
// Validate nonce size
|
|
23
|
+
if (native_iv->size() < crypto_stream_NONCEBYTES) {
|
|
24
|
+
throw std::runtime_error("XSalsa20 nonce too short: expected " + std::to_string(crypto_stream_NONCEBYTES) + " bytes, got " +
|
|
25
|
+
std::to_string(native_iv->size()) + " bytes.");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Copy key and nonce data
|
|
29
|
+
std::memcpy(key, native_key->data(), crypto_stream_KEYBYTES);
|
|
30
|
+
std::memcpy(nonce, native_iv->data(), crypto_stream_NONCEBYTES);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* xsalsa20 call to sodium implementation
|
|
35
|
+
*/
|
|
36
|
+
std::shared_ptr<ArrayBuffer> XSalsa20Cipher::update(const std::shared_ptr<ArrayBuffer>& data) {
|
|
37
|
+
#ifndef BLSALLOC_SODIUM
|
|
38
|
+
throw std::runtime_error("XSalsa20Cipher: libsodium must be enabled to use this cipher (BLSALLOC_SODIUM is not defined).");
|
|
39
|
+
#else
|
|
40
|
+
auto native_data = ToNativeArrayBuffer(data);
|
|
41
|
+
auto output = new uint8_t[native_data->size()];
|
|
42
|
+
int result = crypto_stream_xor(output, native_data->data(), native_data->size(), nonce, key);
|
|
43
|
+
if (result != 0) {
|
|
44
|
+
throw std::runtime_error("XSalsa20Cipher: Failed to update");
|
|
45
|
+
}
|
|
46
|
+
return std::make_shared<NativeArrayBuffer>(output, native_data->size(), [=]() { delete[] output; });
|
|
47
|
+
#endif
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* xsalsa20 does not have a final step, returns empty buffer
|
|
52
|
+
*/
|
|
53
|
+
std::shared_ptr<ArrayBuffer> XSalsa20Cipher::final() {
|
|
54
|
+
#ifndef BLSALLOC_SODIUM
|
|
55
|
+
throw std::runtime_error("XSalsa20Cipher: libsodium must be enabled to use this cipher (BLSALLOC_SODIUM is not defined).");
|
|
56
|
+
#else
|
|
57
|
+
return std::make_shared<NativeArrayBuffer>(nullptr, 0, nullptr);
|
|
58
|
+
#endif
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#if BLSALLOC_SODIUM
|
|
4
|
+
#include "sodium.h"
|
|
5
|
+
#else
|
|
6
|
+
// Define XSalsa20 constants when sodium is disabled (for compilation purposes)
|
|
7
|
+
#define crypto_stream_KEYBYTES 32 // XSalsa20 key size (32 bytes)
|
|
8
|
+
#define crypto_stream_NONCEBYTES 24 // XSalsa20 nonce size (24 bytes)
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
#include "HybridCipher.hpp"
|
|
12
|
+
#include "NitroModules/ArrayBuffer.hpp"
|
|
13
|
+
|
|
14
|
+
namespace margelo::nitro::crypto {
|
|
15
|
+
|
|
16
|
+
class XSalsa20Cipher : public HybridCipher {
|
|
17
|
+
public:
|
|
18
|
+
XSalsa20Cipher() : HybridObject(TAG) {}
|
|
19
|
+
~XSalsa20Cipher() {
|
|
20
|
+
// Let parent destructor free the context
|
|
21
|
+
ctx = nullptr;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void init(const std::shared_ptr<ArrayBuffer> cipher_key, const std::shared_ptr<ArrayBuffer> iv) override;
|
|
25
|
+
std::shared_ptr<ArrayBuffer> update(const std::shared_ptr<ArrayBuffer>& data) override;
|
|
26
|
+
std::shared_ptr<ArrayBuffer> final() override;
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
uint8_t key[crypto_stream_KEYBYTES];
|
|
30
|
+
uint8_t nonce[crypto_stream_NONCEBYTES];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
} // namespace margelo::nitro::crypto
|