react-native-quick-crypto 1.0.0-beta.8 → 1.0.0
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 +145 -6
- package/README.md +14 -27
- package/android/CMakeLists.txt +62 -7
- package/android/build.gradle +12 -2
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +0 -2
- 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/GCMCipher.cpp +68 -0
- package/cpp/cipher/GCMCipher.hpp +14 -0
- package/cpp/cipher/HybridCipher.cpp +322 -0
- package/cpp/cipher/HybridCipher.hpp +68 -0
- package/cpp/cipher/HybridCipherFactory.hpp +105 -0
- package/cpp/cipher/HybridRsaCipher.cpp +348 -0
- package/cpp/cipher/HybridRsaCipher.hpp +29 -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 +228 -98
- package/cpp/ed25519/HybridEdKeyPair.hpp +42 -56
- 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 +749 -0
- package/cpp/keys/HybridKeyObjectHandle.hpp +51 -0
- package/cpp/keys/KeyObjectData.cpp +268 -0
- package/cpp/keys/KeyObjectData.hpp +71 -0
- package/cpp/keys/node.h +5 -0
- package/cpp/pbkdf2/HybridPbkdf2.cpp +34 -55
- package/cpp/pbkdf2/HybridPbkdf2.hpp +5 -16
- package/cpp/random/HybridRandom.cpp +6 -17
- package/cpp/random/HybridRandom.hpp +5 -6
- package/cpp/rsa/HybridRsaKeyPair.cpp +154 -0
- package/cpp/rsa/HybridRsaKeyPair.hpp +43 -0
- package/cpp/sign/HybridSignHandle.cpp +191 -0
- package/cpp/sign/HybridSignHandle.hpp +36 -0
- package/cpp/sign/HybridVerifyHandle.cpp +158 -0
- package/cpp/sign/HybridVerifyHandle.hpp +36 -0
- package/cpp/sign/SignUtils.hpp +108 -0
- package/cpp/utils/Macros.hpp +68 -0
- package/cpp/utils/Utils.hpp +43 -2
- package/cpp/utils/base64.h +309 -0
- 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 +5 -1
- 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/constants.js +32 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/ec.js +480 -0
- package/lib/commonjs/ec.js.map +1 -0
- package/lib/commonjs/ed.js +214 -2
- package/lib/commonjs/ed.js.map +1 -1
- 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 +102 -24
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +109 -52
- package/lib/commonjs/keys/classes.js.map +1 -1
- package/lib/commonjs/keys/generateKeyPair.js +141 -144
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -1
- package/lib/commonjs/keys/index.js +229 -0
- package/lib/commonjs/keys/index.js.map +1 -1
- package/lib/commonjs/keys/publicCipher.js +152 -0
- package/lib/commonjs/keys/publicCipher.js.map +1 -0
- package/lib/commonjs/keys/signVerify.js +178 -39
- package/lib/commonjs/keys/signVerify.js.map +1 -1
- package/lib/commonjs/keys/utils.js +18 -13
- package/lib/commonjs/keys/utils.js.map +1 -1
- package/lib/commonjs/pbkdf2.js.map +1 -1
- package/lib/commonjs/random.js +6 -0
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/rsa.js +202 -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/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/rsaCipher.nitro.js +6 -0
- package/lib/commonjs/specs/rsaCipher.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/specs/sign.nitro.js +6 -0
- package/lib/commonjs/specs/sign.nitro.js.map +1 -0
- package/lib/commonjs/subtle.js +987 -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 +44 -5
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/hashnames.js +2 -1
- package/lib/commonjs/utils/hashnames.js.map +1 -1
- package/lib/commonjs/utils/index.js +11 -0
- 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 +32 -17
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/commonjs/utils/validation.js +74 -1
- package/lib/commonjs/utils/validation.js.map +1 -1
- 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/constants.js +28 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/ec.js +470 -0
- package/lib/module/ec.js.map +1 -0
- package/lib/module/ed.js +212 -3
- package/lib/module/ed.js.map +1 -1
- 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 +21 -21
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +106 -49
- package/lib/module/keys/classes.js.map +1 -1
- package/lib/module/keys/generateKeyPair.js +134 -143
- package/lib/module/keys/generateKeyPair.js.map +1 -1
- package/lib/module/keys/index.js +161 -22
- package/lib/module/keys/index.js.map +1 -1
- package/lib/module/keys/publicCipher.js +145 -0
- package/lib/module/keys/publicCipher.js.map +1 -0
- package/lib/module/keys/signVerify.js +170 -39
- package/lib/module/keys/signVerify.js.map +1 -1
- package/lib/module/keys/utils.js +16 -12
- package/lib/module/keys/utils.js.map +1 -1
- package/lib/module/pbkdf2.js.map +1 -1
- package/lib/module/random.js +6 -0
- package/lib/module/random.js.map +1 -1
- package/lib/module/rsa.js +194 -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/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/rsaCipher.nitro.js +4 -0
- package/lib/module/specs/rsaCipher.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/specs/sign.nitro.js +4 -0
- package/lib/module/specs/sign.nitro.js.map +1 -0
- package/lib/module/subtle.js +982 -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 +26 -5
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/hashnames.js +2 -1
- package/lib/module/utils/hashnames.js.map +1 -1
- package/lib/module/utils/index.js +1 -0
- 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 +32 -17
- package/lib/module/utils/types.js.map +1 -1
- package/lib/module/utils/validation.js +69 -1
- package/lib/module/utils/validation.js.map +1 -1
- 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/constants.d.ts +21 -0
- package/lib/typescript/constants.d.ts.map +1 -0
- package/lib/typescript/ec.d.ts +22 -0
- package/lib/typescript/ec.d.ts.map +1 -0
- package/lib/typescript/ed.d.ts +28 -1
- package/lib/typescript/ed.d.ts.map +1 -1
- 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 +102 -10
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +50 -8
- package/lib/typescript/keys/classes.d.ts.map +1 -1
- package/lib/typescript/keys/generateKeyPair.d.ts +5 -0
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -1
- package/lib/typescript/keys/index.d.ts +22 -2
- package/lib/typescript/keys/index.d.ts.map +1 -1
- package/lib/typescript/keys/publicCipher.d.ts +20 -0
- package/lib/typescript/keys/publicCipher.d.ts.map +1 -0
- package/lib/typescript/keys/signVerify.d.ts +28 -0
- package/lib/typescript/keys/signVerify.d.ts.map +1 -1
- package/lib/typescript/keys/utils.d.ts +3 -1
- package/lib/typescript/keys/utils.d.ts.map +1 -1
- package/lib/typescript/pbkdf2.d.ts +1 -1
- package/lib/typescript/pbkdf2.d.ts.map +1 -1
- package/lib/typescript/random.d.ts +6 -0
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/rsa.d.ts +19 -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 +1 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -1
- 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 +1 -1
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/rsaCipher.nitro.d.ts +44 -0
- package/lib/typescript/specs/rsaCipher.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/specs/sign.nitro.d.ts +19 -0
- package/lib/typescript/specs/sign.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 +1 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/hashnames.d.ts +3 -1
- package/lib/typescript/utils/hashnames.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +1 -0
- 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 +125 -23
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/utils/validation.d.ts +5 -0
- package/lib/typescript/utils/validation.d.ts.map +1 -1
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +30 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +1 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +115 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +35 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +3 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +3 -3
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +111 -1
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +1 -1
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +104 -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 +2 -1
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +5 -4
- 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 +1 -1
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +8 -8
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +72 -0
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +77 -0
- package/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/JWK.hpp +17 -18
- package/nitrogen/generated/shared/c++/JWKkty.hpp +12 -14
- package/nitrogen/generated/shared/c++/JWKuse.hpp +8 -10
- package/nitrogen/generated/shared/c++/KFormatType.hpp +14 -16
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +6 -7
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +15 -17
- package/nitrogen/generated/shared/c++/KeyObject.hpp +67 -0
- package/nitrogen/generated/shared/c++/KeyType.hpp +11 -13
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +38 -24
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +10 -12
- package/package.json +28 -23
- package/src/blake3.ts +123 -0
- package/src/cipher.ts +335 -0
- package/src/constants.ts +32 -0
- package/src/ec.ts +657 -0
- package/src/ed.ts +297 -13
- 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 +20 -20
- package/src/keys/classes.ts +148 -55
- package/src/keys/generateKeyPair.ts +177 -134
- package/src/keys/index.ts +226 -14
- package/src/keys/publicCipher.ts +229 -0
- package/src/keys/signVerify.ts +239 -39
- package/src/keys/utils.ts +24 -18
- package/src/pbkdf2.ts +1 -1
- package/src/random.ts +7 -0
- package/src/rsa.ts +310 -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 +2 -0
- package/src/specs/hash.nitro.ts +10 -0
- package/src/specs/hmac.nitro.ts +7 -0
- package/src/specs/keyObjectHandle.nitro.ts +1 -1
- package/src/specs/rsaCipher.nitro.ts +65 -0
- package/src/specs/rsaKeyPair.nitro.ts +33 -0
- package/src/specs/sign.nitro.ts +31 -0
- package/src/subtle.ts +1436 -0
- package/src/utils/cipher.ts +60 -0
- package/src/utils/conversion.ts +33 -4
- package/src/utils/hashnames.ts +4 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/noble.ts +85 -0
- package/src/utils/types.ts +209 -29
- package/src/utils/validation.ts +96 -1
- package/lib/module/package.json +0 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.kt +0 -1
- package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +0 -86
|
@@ -1,49 +1,102 @@
|
|
|
1
|
-
#include
|
|
2
|
-
|
|
1
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
3
2
|
#include <memory>
|
|
3
|
+
#include <openssl/bio.h>
|
|
4
|
+
#include <openssl/evp.h>
|
|
5
|
+
#include <openssl/pem.h>
|
|
4
6
|
#include <string>
|
|
5
7
|
|
|
8
|
+
#include "HybridEdKeyPair.hpp"
|
|
9
|
+
|
|
6
10
|
namespace margelo::nitro::crypto {
|
|
7
11
|
|
|
8
|
-
std::shared_ptr<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
12
|
+
std::shared_ptr<ArrayBuffer> HybridEdKeyPair::diffieHellman(const std::shared_ptr<ArrayBuffer>& privateKey,
|
|
13
|
+
const std::shared_ptr<ArrayBuffer>& publicKey) {
|
|
14
|
+
using EVP_PKEY_ptr = std::unique_ptr<EVP_PKEY, decltype(&EVP_PKEY_free)>;
|
|
15
|
+
using EVP_PKEY_CTX_ptr = std::unique_ptr<EVP_PKEY_CTX, decltype(&EVP_PKEY_CTX_free)>;
|
|
16
|
+
|
|
17
|
+
// 1. Create EVP_PKEY for private key (our key)
|
|
18
|
+
EVP_PKEY_ptr pkey_priv(EVP_PKEY_new_raw_private_key(EVP_PKEY_X25519, NULL, privateKey->data(), privateKey->size()), EVP_PKEY_free);
|
|
19
|
+
if (!pkey_priv) {
|
|
20
|
+
throw std::runtime_error("Failed to create private key: " + getOpenSSLError());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 2. Create EVP_PKEY for public key (peer's key)
|
|
24
|
+
EVP_PKEY_ptr pkey_pub(EVP_PKEY_new_raw_public_key(EVP_PKEY_X25519, NULL, publicKey->data(), publicKey->size()), EVP_PKEY_free);
|
|
25
|
+
if (!pkey_pub) {
|
|
26
|
+
throw std::runtime_error("Failed to create public key: " + getOpenSSLError());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 3. Create the context for the key exchange
|
|
30
|
+
EVP_PKEY_CTX_ptr ctx(EVP_PKEY_CTX_new_from_pkey(NULL, pkey_priv.get(), NULL), EVP_PKEY_CTX_free);
|
|
31
|
+
if (!ctx) {
|
|
32
|
+
throw std::runtime_error("Failed to create key exchange context: " + getOpenSSLError());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 4. Initialize the context
|
|
36
|
+
if (EVP_PKEY_derive_init(ctx.get()) <= 0) {
|
|
37
|
+
throw std::runtime_error("Failed to initialize key exchange: " + getOpenSSLError());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 5. Provide the peer's public key
|
|
41
|
+
if (EVP_PKEY_derive_set_peer(ctx.get(), pkey_pub.get()) <= 0) {
|
|
42
|
+
throw std::runtime_error("Failed to set peer key: " + getOpenSSLError());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 6. Determine the size of the shared secret
|
|
46
|
+
size_t shared_secret_len;
|
|
47
|
+
if (EVP_PKEY_derive(ctx.get(), NULL, &shared_secret_len) <= 0) {
|
|
48
|
+
throw std::runtime_error("Failed to determine shared secret length: " + getOpenSSLError());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 7. Allocate memory for the shared secret
|
|
52
|
+
auto shared_secret = new uint8_t[shared_secret_len];
|
|
53
|
+
|
|
54
|
+
// 8. Derive the shared secret
|
|
55
|
+
if (EVP_PKEY_derive(ctx.get(), shared_secret, &shared_secret_len) <= 0) {
|
|
56
|
+
delete[] shared_secret;
|
|
57
|
+
throw std::runtime_error("Failed to derive shared secret: " + getOpenSSLError());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 9. Return a newly-created ArrayBuffer from the raw buffer w/ cleanup
|
|
61
|
+
return std::make_shared<NativeArrayBuffer>(shared_secret, shared_secret_len, [=]() { delete[] shared_secret; });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
std::shared_ptr<Promise<void>> HybridEdKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat,
|
|
65
|
+
double privateType, const std::optional<std::string>& cipher,
|
|
66
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase) {
|
|
17
67
|
// get owned NativeArrayBuffers before passing to sync function
|
|
18
68
|
std::optional<std::shared_ptr<ArrayBuffer>> nativePassphrase = std::nullopt;
|
|
19
69
|
if (passphrase.has_value()) {
|
|
20
70
|
nativePassphrase = ToNativeArrayBuffer(passphrase.value());
|
|
21
71
|
}
|
|
22
72
|
|
|
23
|
-
return Promise<void>::async(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this->generateKeyPairSync(
|
|
27
|
-
publicFormat,
|
|
28
|
-
publicType,
|
|
29
|
-
privateFormat,
|
|
30
|
-
privateType,
|
|
31
|
-
cipher,
|
|
32
|
-
nativePassphrase
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
);
|
|
73
|
+
return Promise<void>::async([this, publicFormat, publicType, privateFormat, privateType, cipher, nativePassphrase]() {
|
|
74
|
+
this->generateKeyPairSync(publicFormat, publicType, privateFormat, privateType, cipher, nativePassphrase);
|
|
75
|
+
});
|
|
36
76
|
}
|
|
37
77
|
|
|
38
|
-
void
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
78
|
+
void HybridEdKeyPair::generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType,
|
|
79
|
+
const std::optional<std::string>& cipher,
|
|
80
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase) {
|
|
81
|
+
// Clear any previous OpenSSL errors to prevent pollution
|
|
82
|
+
clearOpenSSLErrors();
|
|
83
|
+
|
|
84
|
+
if (this->curve.empty()) {
|
|
85
|
+
throw std::runtime_error("EC curve not set. Call setCurve() first.");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Store encoding configuration for later use in getPublicKey/getPrivateKey
|
|
89
|
+
this->publicFormat_ = static_cast<int>(publicFormat);
|
|
90
|
+
this->publicType_ = static_cast<int>(publicType);
|
|
91
|
+
this->privateFormat_ = static_cast<int>(privateFormat);
|
|
92
|
+
this->privateType_ = static_cast<int>(privateType);
|
|
93
|
+
|
|
94
|
+
// Clean up existing key if any
|
|
95
|
+
if (this->pkey != nullptr) {
|
|
96
|
+
EVP_PKEY_free(this->pkey);
|
|
97
|
+
this->pkey = nullptr;
|
|
98
|
+
}
|
|
99
|
+
|
|
47
100
|
EVP_PKEY_CTX* pctx;
|
|
48
101
|
|
|
49
102
|
// key context
|
|
@@ -69,12 +122,8 @@ HybridEdKeyPair::generateKeyPairSync(
|
|
|
69
122
|
EVP_PKEY_CTX_free(pctx);
|
|
70
123
|
}
|
|
71
124
|
|
|
72
|
-
|
|
73
|
-
std::
|
|
74
|
-
HybridEdKeyPair::sign(
|
|
75
|
-
const std::shared_ptr<ArrayBuffer>& message,
|
|
76
|
-
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
77
|
-
) {
|
|
125
|
+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> HybridEdKeyPair::sign(const std::shared_ptr<ArrayBuffer>& message,
|
|
126
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key) {
|
|
78
127
|
// get owned NativeArrayBuffer before passing to sync function
|
|
79
128
|
auto nativeMessage = ToNativeArrayBuffer(message);
|
|
80
129
|
std::optional<std::shared_ptr<ArrayBuffer>> nativeKey = std::nullopt;
|
|
@@ -82,17 +131,14 @@ HybridEdKeyPair::sign(
|
|
|
82
131
|
nativeKey = ToNativeArrayBuffer(key.value());
|
|
83
132
|
}
|
|
84
133
|
|
|
85
|
-
return Promise<std::shared_ptr<ArrayBuffer>>::async(
|
|
86
|
-
return this->signSync(nativeMessage, nativeKey);
|
|
87
|
-
}
|
|
88
|
-
);
|
|
134
|
+
return Promise<std::shared_ptr<ArrayBuffer>>::async(
|
|
135
|
+
[this, nativeMessage, nativeKey]() { return this->signSync(nativeMessage, nativeKey); });
|
|
89
136
|
}
|
|
90
137
|
|
|
91
|
-
std::shared_ptr<ArrayBuffer>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
) {
|
|
138
|
+
std::shared_ptr<ArrayBuffer> HybridEdKeyPair::signSync(const std::shared_ptr<ArrayBuffer>& message,
|
|
139
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key) {
|
|
140
|
+
// Clear any previous OpenSSL errors to prevent pollution
|
|
141
|
+
clearOpenSSLErrors();
|
|
96
142
|
|
|
97
143
|
size_t sig_len = 0;
|
|
98
144
|
uint8_t* sig = NULL;
|
|
@@ -105,18 +151,18 @@ HybridEdKeyPair::signSync(
|
|
|
105
151
|
// key context
|
|
106
152
|
md_ctx = EVP_MD_CTX_new();
|
|
107
153
|
if (md_ctx == nullptr) {
|
|
108
|
-
EVP_MD_CTX_free(md_ctx);
|
|
109
154
|
throw std::runtime_error("Error creating signing context");
|
|
110
155
|
}
|
|
111
156
|
|
|
112
157
|
pkey_ctx = EVP_PKEY_CTX_new_from_name(nullptr, this->curve.c_str(), nullptr);
|
|
113
158
|
if (pkey_ctx == nullptr) {
|
|
114
|
-
|
|
159
|
+
EVP_MD_CTX_free(md_ctx);
|
|
115
160
|
throw std::runtime_error("Error creating signing context: " + this->curve);
|
|
116
161
|
}
|
|
117
162
|
|
|
118
163
|
if (EVP_DigestSignInit(md_ctx, &pkey_ctx, NULL, NULL, pkey) <= 0) {
|
|
119
164
|
EVP_MD_CTX_free(md_ctx);
|
|
165
|
+
EVP_PKEY_CTX_free(pkey_ctx);
|
|
120
166
|
char* err = ERR_error_string(ERR_get_error(), NULL);
|
|
121
167
|
throw std::runtime_error("Failed to initialize signing: " + std::string(err));
|
|
122
168
|
}
|
|
@@ -131,28 +177,23 @@ HybridEdKeyPair::signSync(
|
|
|
131
177
|
// Actually calculate the signature
|
|
132
178
|
if (EVP_DigestSign(md_ctx, sig, &sig_len, message.get()->data(), message.get()->size()) <= 0) {
|
|
133
179
|
EVP_MD_CTX_free(md_ctx);
|
|
180
|
+
delete[] sig;
|
|
134
181
|
throw std::runtime_error("Failed to calculate signature");
|
|
135
182
|
}
|
|
136
183
|
|
|
137
184
|
// return value for JS
|
|
138
|
-
std::shared_ptr<ArrayBuffer> signature = std::make_shared<NativeArrayBuffer>(
|
|
139
|
-
sig,
|
|
140
|
-
sig_len,
|
|
141
|
-
[=]() { delete[] sig; }
|
|
142
|
-
);
|
|
185
|
+
std::shared_ptr<ArrayBuffer> signature = std::make_shared<NativeArrayBuffer>(sig, sig_len, [=]() { delete[] sig; });
|
|
143
186
|
|
|
144
187
|
// Clean up
|
|
145
188
|
EVP_MD_CTX_free(md_ctx);
|
|
189
|
+
// Note: pkey_ctx is freed automatically by EVP_MD_CTX_free when using EVP_DigestSignInit
|
|
146
190
|
|
|
147
191
|
return signature;
|
|
148
192
|
}
|
|
149
193
|
|
|
150
|
-
std::shared_ptr<Promise<bool>>
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const std::shared_ptr<ArrayBuffer>& message,
|
|
154
|
-
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
155
|
-
) {
|
|
194
|
+
std::shared_ptr<Promise<bool>> HybridEdKeyPair::verify(const std::shared_ptr<ArrayBuffer>& signature,
|
|
195
|
+
const std::shared_ptr<ArrayBuffer>& message,
|
|
196
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key) {
|
|
156
197
|
// get owned NativeArrayBuffers before passing to sync function
|
|
157
198
|
auto nativeSignature = ToNativeArrayBuffer(signature);
|
|
158
199
|
auto nativeMessage = ToNativeArrayBuffer(message);
|
|
@@ -161,20 +202,17 @@ HybridEdKeyPair::verify(
|
|
|
161
202
|
nativeKey = ToNativeArrayBuffer(key.value());
|
|
162
203
|
}
|
|
163
204
|
|
|
164
|
-
return Promise<bool>::async(
|
|
165
|
-
return this->verifySync(nativeSignature, nativeMessage, nativeKey);
|
|
166
|
-
}
|
|
167
|
-
);
|
|
205
|
+
return Promise<bool>::async(
|
|
206
|
+
[this, nativeSignature, nativeMessage, nativeKey]() { return this->verifySync(nativeSignature, nativeMessage, nativeKey); });
|
|
168
207
|
}
|
|
169
208
|
|
|
170
|
-
bool
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
) {
|
|
209
|
+
bool HybridEdKeyPair::verifySync(const std::shared_ptr<ArrayBuffer>& signature, const std::shared_ptr<ArrayBuffer>& message,
|
|
210
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key) {
|
|
211
|
+
// Clear any previous OpenSSL errors to prevent pollution
|
|
212
|
+
clearOpenSSLErrors();
|
|
213
|
+
|
|
176
214
|
// get key to use for verifying
|
|
177
|
-
EVP_PKEY* pkey = this->
|
|
215
|
+
EVP_PKEY* pkey = this->importPublicKey(key);
|
|
178
216
|
|
|
179
217
|
EVP_MD_CTX* md_ctx = nullptr;
|
|
180
218
|
EVP_PKEY_CTX* pkey_ctx = nullptr;
|
|
@@ -182,30 +220,26 @@ HybridEdKeyPair::verifySync(
|
|
|
182
220
|
// key context
|
|
183
221
|
md_ctx = EVP_MD_CTX_new();
|
|
184
222
|
if (md_ctx == nullptr) {
|
|
185
|
-
EVP_MD_CTX_free(md_ctx);
|
|
186
223
|
throw std::runtime_error("Error creating verify context");
|
|
187
224
|
}
|
|
188
225
|
|
|
189
226
|
pkey_ctx = EVP_PKEY_CTX_new_from_name(nullptr, this->curve.c_str(), nullptr);
|
|
190
227
|
if (pkey_ctx == nullptr) {
|
|
191
|
-
|
|
228
|
+
EVP_MD_CTX_free(md_ctx);
|
|
192
229
|
throw std::runtime_error("Error creating verify context: " + this->curve);
|
|
193
230
|
}
|
|
194
231
|
|
|
195
232
|
if (EVP_DigestVerifyInit(md_ctx, &pkey_ctx, NULL, NULL, pkey) <= 0) {
|
|
196
233
|
EVP_MD_CTX_free(md_ctx);
|
|
234
|
+
EVP_PKEY_CTX_free(pkey_ctx);
|
|
197
235
|
char* err = ERR_error_string(ERR_get_error(), NULL);
|
|
198
236
|
throw std::runtime_error("Failed to initialize verify: " + std::string(err));
|
|
199
237
|
}
|
|
200
238
|
|
|
201
239
|
// verify
|
|
202
|
-
auto res = EVP_DigestVerify(
|
|
203
|
-
md_ctx,
|
|
204
|
-
signature.get()->data(), signature.get()->size(),
|
|
205
|
-
message.get()->data(), message.get()->size()
|
|
206
|
-
);
|
|
240
|
+
auto res = EVP_DigestVerify(md_ctx, signature.get()->data(), signature.get()->size(), message.get()->data(), message.get()->size());
|
|
207
241
|
|
|
208
|
-
//return value for JS
|
|
242
|
+
// return value for JS
|
|
209
243
|
if (res < 0) {
|
|
210
244
|
EVP_MD_CTX_free(md_ctx);
|
|
211
245
|
throw std::runtime_error("Failed to verify");
|
|
@@ -213,48 +247,144 @@ HybridEdKeyPair::verifySync(
|
|
|
213
247
|
return res == 1; // true if 1, false if 0
|
|
214
248
|
}
|
|
215
249
|
|
|
216
|
-
std::shared_ptr<ArrayBuffer>
|
|
217
|
-
HybridEdKeyPair::getPublicKey() {
|
|
250
|
+
std::shared_ptr<ArrayBuffer> HybridEdKeyPair::getPublicKey() {
|
|
218
251
|
this->checkKeyPair();
|
|
219
|
-
|
|
252
|
+
|
|
253
|
+
// If format is DER (0) or PEM (1), export in SPKI format
|
|
254
|
+
if (publicFormat_ == 0 || publicFormat_ == 1) {
|
|
255
|
+
BIO* bio = BIO_new(BIO_s_mem());
|
|
256
|
+
if (!bio) {
|
|
257
|
+
throw std::runtime_error("Failed to create BIO for public key export");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
int result;
|
|
261
|
+
if (publicFormat_ == 1) {
|
|
262
|
+
// PEM format
|
|
263
|
+
result = PEM_write_bio_PUBKEY(bio, this->pkey);
|
|
264
|
+
} else {
|
|
265
|
+
// DER format
|
|
266
|
+
result = i2d_PUBKEY_bio(bio, this->pkey);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (result != 1) {
|
|
270
|
+
BIO_free(bio);
|
|
271
|
+
throw std::runtime_error("Failed to export public key");
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
BUF_MEM* bptr;
|
|
275
|
+
BIO_get_mem_ptr(bio, &bptr);
|
|
276
|
+
|
|
277
|
+
uint8_t* data = new uint8_t[bptr->length];
|
|
278
|
+
memcpy(data, bptr->data, bptr->length);
|
|
279
|
+
size_t len = bptr->length;
|
|
280
|
+
|
|
281
|
+
BIO_free(bio);
|
|
282
|
+
|
|
283
|
+
return std::make_shared<NativeArrayBuffer>(data, len, [=]() { delete[] data; });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Default: raw format
|
|
287
|
+
size_t len = 0;
|
|
288
|
+
EVP_PKEY_get_raw_public_key(this->pkey, nullptr, &len);
|
|
220
289
|
uint8_t* publ = new uint8_t[len];
|
|
221
290
|
EVP_PKEY_get_raw_public_key(this->pkey, publ, &len);
|
|
222
291
|
|
|
223
292
|
return std::make_shared<NativeArrayBuffer>(publ, len, [=]() { delete[] publ; });
|
|
224
293
|
}
|
|
225
294
|
|
|
226
|
-
std::shared_ptr<ArrayBuffer>
|
|
227
|
-
HybridEdKeyPair::getPrivateKey() {
|
|
295
|
+
std::shared_ptr<ArrayBuffer> HybridEdKeyPair::getPrivateKey() {
|
|
228
296
|
this->checkKeyPair();
|
|
229
|
-
|
|
297
|
+
|
|
298
|
+
// If format is DER (0) or PEM (1), export in PKCS8 format
|
|
299
|
+
if (privateFormat_ == 0 || privateFormat_ == 1) {
|
|
300
|
+
BIO* bio = BIO_new(BIO_s_mem());
|
|
301
|
+
if (!bio) {
|
|
302
|
+
throw std::runtime_error("Failed to create BIO for private key export");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
int result;
|
|
306
|
+
if (privateFormat_ == 1) {
|
|
307
|
+
// PEM format (PKCS8)
|
|
308
|
+
result = PEM_write_bio_PrivateKey(bio, this->pkey, nullptr, nullptr, 0, nullptr, nullptr);
|
|
309
|
+
} else {
|
|
310
|
+
// DER format (PKCS8)
|
|
311
|
+
result = i2d_PrivateKey_bio(bio, this->pkey);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (result != 1) {
|
|
315
|
+
BIO_free(bio);
|
|
316
|
+
throw std::runtime_error("Failed to export private key");
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
BUF_MEM* bptr;
|
|
320
|
+
BIO_get_mem_ptr(bio, &bptr);
|
|
321
|
+
|
|
322
|
+
uint8_t* data = new uint8_t[bptr->length];
|
|
323
|
+
memcpy(data, bptr->data, bptr->length);
|
|
324
|
+
size_t len = bptr->length;
|
|
325
|
+
|
|
326
|
+
BIO_free(bio);
|
|
327
|
+
|
|
328
|
+
return std::make_shared<NativeArrayBuffer>(data, len, [=]() { delete[] data; });
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Default: raw format
|
|
332
|
+
size_t len = 0;
|
|
333
|
+
EVP_PKEY_get_raw_private_key(this->pkey, nullptr, &len);
|
|
230
334
|
uint8_t* priv = new uint8_t[len];
|
|
231
335
|
EVP_PKEY_get_raw_private_key(this->pkey, priv, &len);
|
|
232
336
|
|
|
233
337
|
return std::make_shared<NativeArrayBuffer>(priv, len, [=]() { delete[] priv; });
|
|
234
338
|
}
|
|
235
339
|
|
|
236
|
-
void
|
|
237
|
-
HybridEdKeyPair::checkKeyPair() {
|
|
340
|
+
void HybridEdKeyPair::checkKeyPair() {
|
|
238
341
|
if (this->pkey == nullptr) {
|
|
239
342
|
throw std::runtime_error("Keypair not initialized");
|
|
240
343
|
}
|
|
241
344
|
}
|
|
242
345
|
|
|
243
|
-
void
|
|
244
|
-
HybridEdKeyPair::setCurve(const std::string& curve) {
|
|
346
|
+
void HybridEdKeyPair::setCurve(const std::string& curve) {
|
|
245
347
|
this->curve = curve;
|
|
246
348
|
}
|
|
247
349
|
|
|
248
|
-
EVP_PKEY*
|
|
249
|
-
|
|
350
|
+
EVP_PKEY* HybridEdKeyPair::importPublicKey(const std::optional<std::shared_ptr<ArrayBuffer>>& key) {
|
|
351
|
+
EVP_PKEY* pkey = nullptr;
|
|
352
|
+
if (key.has_value()) {
|
|
353
|
+
// Determine key type from curve name
|
|
354
|
+
int keyType = EVP_PKEY_ED25519;
|
|
355
|
+
if (this->curve == "ed448" || this->curve == "Ed448") {
|
|
356
|
+
keyType = EVP_PKEY_ED448;
|
|
357
|
+
} else if (this->curve == "x25519" || this->curve == "X25519") {
|
|
358
|
+
keyType = EVP_PKEY_X25519;
|
|
359
|
+
} else if (this->curve == "x448" || this->curve == "X448") {
|
|
360
|
+
keyType = EVP_PKEY_X448;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
pkey = EVP_PKEY_new_raw_public_key(keyType, NULL, key.value()->data(), key.value()->size());
|
|
364
|
+
if (pkey == nullptr) {
|
|
365
|
+
throw std::runtime_error("Failed to read public key");
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
this->checkKeyPair();
|
|
369
|
+
pkey = this->pkey;
|
|
370
|
+
}
|
|
371
|
+
return pkey;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
EVP_PKEY* HybridEdKeyPair::importPrivateKey(const std::optional<std::shared_ptr<ArrayBuffer>>& key) {
|
|
250
375
|
EVP_PKEY* pkey = nullptr;
|
|
251
376
|
if (key.has_value()) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
377
|
+
// Determine key type from curve name
|
|
378
|
+
int keyType = EVP_PKEY_ED25519;
|
|
379
|
+
if (this->curve == "ed448" || this->curve == "Ed448") {
|
|
380
|
+
keyType = EVP_PKEY_ED448;
|
|
381
|
+
} else if (this->curve == "x25519" || this->curve == "X25519") {
|
|
382
|
+
keyType = EVP_PKEY_X25519;
|
|
383
|
+
} else if (this->curve == "x448" || this->curve == "X448") {
|
|
384
|
+
keyType = EVP_PKEY_X448;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
pkey = EVP_PKEY_new_raw_private_key(keyType, NULL, key.value()->data(), key.value()->size());
|
|
258
388
|
if (pkey == nullptr) {
|
|
259
389
|
throw std::runtime_error("Failed to read private key");
|
|
260
390
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#include <openssl/evp.h>
|
|
2
|
-
#include <openssl/err.h>
|
|
3
1
|
#include <memory>
|
|
2
|
+
#include <openssl/err.h>
|
|
3
|
+
#include <openssl/evp.h>
|
|
4
4
|
#include <string>
|
|
5
5
|
|
|
6
6
|
#include "HybridEdKeyPairSpec.hpp"
|
|
@@ -8,66 +8,45 @@
|
|
|
8
8
|
|
|
9
9
|
namespace margelo::nitro::crypto {
|
|
10
10
|
|
|
11
|
-
using namespace facebook;
|
|
12
|
-
|
|
13
11
|
class HybridEdKeyPair : public HybridEdKeyPairSpec {
|
|
14
12
|
public:
|
|
15
13
|
HybridEdKeyPair() : HybridObject(TAG) {}
|
|
14
|
+
~HybridEdKeyPair() {
|
|
15
|
+
if (pkey != nullptr) {
|
|
16
|
+
EVP_PKEY_free(pkey);
|
|
17
|
+
pkey = nullptr;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
16
20
|
|
|
17
21
|
public:
|
|
18
22
|
// Methods
|
|
19
|
-
std::shared_ptr<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
std::shared_ptr<
|
|
40
|
-
|
|
41
|
-
const std::shared_ptr<ArrayBuffer>& message,
|
|
42
|
-
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
43
|
-
) override;
|
|
44
|
-
|
|
45
|
-
std::shared_ptr<ArrayBuffer>
|
|
46
|
-
signSync(
|
|
47
|
-
const std::shared_ptr<ArrayBuffer>& message,
|
|
48
|
-
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
49
|
-
) override;
|
|
50
|
-
|
|
51
|
-
std::shared_ptr<Promise<bool>>
|
|
52
|
-
verify(
|
|
53
|
-
const std::shared_ptr<ArrayBuffer>& signature,
|
|
54
|
-
const std::shared_ptr<ArrayBuffer>& message,
|
|
55
|
-
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
56
|
-
) override;
|
|
57
|
-
|
|
58
|
-
bool
|
|
59
|
-
verifySync(
|
|
60
|
-
const std::shared_ptr<ArrayBuffer>& signature,
|
|
61
|
-
const std::shared_ptr<ArrayBuffer>& message,
|
|
62
|
-
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
63
|
-
) override;
|
|
23
|
+
std::shared_ptr<ArrayBuffer> diffieHellman(const std::shared_ptr<ArrayBuffer>& privateKey,
|
|
24
|
+
const std::shared_ptr<ArrayBuffer>& publicKey) override;
|
|
25
|
+
|
|
26
|
+
std::shared_ptr<Promise<void>> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType,
|
|
27
|
+
const std::optional<std::string>& cipher,
|
|
28
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase) override;
|
|
29
|
+
|
|
30
|
+
void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType,
|
|
31
|
+
const std::optional<std::string>& cipher,
|
|
32
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase) override;
|
|
33
|
+
|
|
34
|
+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> sign(const std::shared_ptr<ArrayBuffer>& message,
|
|
35
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key) override;
|
|
36
|
+
|
|
37
|
+
std::shared_ptr<ArrayBuffer> signSync(const std::shared_ptr<ArrayBuffer>& message,
|
|
38
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key) override;
|
|
39
|
+
|
|
40
|
+
std::shared_ptr<Promise<bool>> verify(const std::shared_ptr<ArrayBuffer>& signature, const std::shared_ptr<ArrayBuffer>& message,
|
|
41
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key) override;
|
|
42
|
+
|
|
43
|
+
bool verifySync(const std::shared_ptr<ArrayBuffer>& signature, const std::shared_ptr<ArrayBuffer>& message,
|
|
44
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key) override;
|
|
64
45
|
|
|
65
46
|
protected:
|
|
66
|
-
std::shared_ptr<ArrayBuffer>
|
|
67
|
-
getPublicKey() override;
|
|
47
|
+
std::shared_ptr<ArrayBuffer> getPublicKey() override;
|
|
68
48
|
|
|
69
|
-
std::shared_ptr<ArrayBuffer>
|
|
70
|
-
getPrivateKey() override;
|
|
49
|
+
std::shared_ptr<ArrayBuffer> getPrivateKey() override;
|
|
71
50
|
|
|
72
51
|
void checkKeyPair();
|
|
73
52
|
|
|
@@ -77,9 +56,16 @@ class HybridEdKeyPair : public HybridEdKeyPairSpec {
|
|
|
77
56
|
std::string curve;
|
|
78
57
|
EVP_PKEY* pkey = nullptr;
|
|
79
58
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
59
|
+
// Encoding configuration for key export
|
|
60
|
+
// Format: -1 = default (raw), 0 = DER, 1 = PEM
|
|
61
|
+
// Type: 0 = PKCS1, 1 = PKCS8, 2 = SPKI, 3 = SEC1
|
|
62
|
+
int publicFormat_ = -1;
|
|
63
|
+
int publicType_ = -1;
|
|
64
|
+
int privateFormat_ = -1;
|
|
65
|
+
int privateType_ = -1;
|
|
66
|
+
|
|
67
|
+
EVP_PKEY* importPublicKey(const std::optional<std::shared_ptr<ArrayBuffer>>& key);
|
|
68
|
+
EVP_PKEY* importPrivateKey(const std::optional<std::shared_ptr<ArrayBuffer>>& key);
|
|
83
69
|
};
|
|
84
70
|
|
|
85
71
|
} // namespace margelo::nitro::crypto
|