react-native-quick-crypto 0.7.11 → 1.0.0-beta.10
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 +47 -0
- package/README.md +6 -4
- package/android/CMakeLists.txt +26 -55
- package/android/build.gradle +70 -112
- package/android/gradle.properties +3 -3
- package/android/src/main/cpp/cpp-adapter.cpp +3 -64
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +43 -0
- package/cpp/ed25519/HybridEdKeyPair.cpp +268 -0
- package/cpp/ed25519/HybridEdKeyPair.hpp +85 -0
- package/cpp/pbkdf2/HybridPbkdf2.cpp +72 -0
- package/cpp/pbkdf2/HybridPbkdf2.hpp +35 -0
- package/cpp/random/HybridRandom.cpp +59 -0
- package/cpp/random/HybridRandom.hpp +33 -0
- package/cpp/utils/Utils.hpp +20 -0
- package/lib/commonjs/ed.js +42 -0
- package/lib/commonjs/ed.js.map +1 -0
- package/lib/commonjs/index.js +90 -39
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +191 -0
- package/lib/commonjs/keys/classes.js.map +1 -0
- package/lib/commonjs/keys/generateKeyPair.js +148 -0
- package/lib/commonjs/keys/generateKeyPair.js.map +1 -0
- package/lib/commonjs/keys/index.js +62 -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 +118 -0
- package/lib/commonjs/keys/utils.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +29 -19
- package/lib/commonjs/pbkdf2.js.map +1 -1
- package/lib/commonjs/random.js +27 -11
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/{NativeQuickCrypto/aes.js → specs/edKeyPair.nitro.js} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/edKeyPair.nitro.js.map} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/keygen.js → specs/keyObjectHandle.nitro.js} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/hash.js.map → specs/keyObjectHandle.nitro.js.map} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/pbkdf2.nitro.js} +1 -1
- package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/specs/pbkdf2.nitro.js.map} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/webcrypto.js → specs/random.nitro.js} +1 -1
- package/lib/{module/NativeQuickCrypto/rsa.js.map → commonjs/specs/random.nitro.js.map} +1 -1
- package/lib/commonjs/utils/conversion.js +117 -0
- package/lib/commonjs/utils/conversion.js.map +1 -0
- package/lib/commonjs/utils/errors.js +14 -0
- package/lib/commonjs/utils/errors.js.map +1 -0
- package/lib/commonjs/{Hashnames.js → utils/hashnames.js} +2 -5
- package/lib/commonjs/utils/hashnames.js.map +1 -0
- package/lib/commonjs/utils/index.js +61 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/types.js +40 -0
- package/lib/commonjs/utils/types.js.map +1 -0
- package/lib/commonjs/utils/validation.js +25 -0
- package/lib/commonjs/utils/validation.js.map +1 -0
- package/lib/module/ed.js +37 -0
- package/lib/module/ed.js.map +1 -0
- package/lib/module/index.js +44 -37
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +182 -0
- package/lib/module/keys/classes.js.map +1 -0
- package/lib/module/keys/generateKeyPair.js +148 -0
- package/lib/module/keys/generateKeyPair.js.map +1 -0
- package/lib/module/keys/index.js +29 -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 +110 -0
- package/lib/module/keys/utils.js.map +1 -0
- package/lib/module/pbkdf2.js +17 -7
- package/lib/module/pbkdf2.js.map +1 -1
- package/lib/module/random.js +26 -10
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/edKeyPair.nitro.js +4 -0
- package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/specs/edKeyPair.nitro.js.map} +1 -1
- package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
- package/lib/{commonjs/NativeQuickCrypto/hmac.js.map → module/specs/keyObjectHandle.nitro.js.map} +1 -1
- package/lib/module/specs/pbkdf2.nitro.js +4 -0
- package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/module/specs/random.nitro.js +4 -0
- package/lib/module/specs/random.nitro.js.map +1 -0
- package/lib/module/utils/conversion.js +107 -0
- package/lib/module/utils/conversion.js.map +1 -0
- package/lib/module/utils/errors.js +10 -0
- package/lib/module/utils/errors.js.map +1 -0
- package/lib/module/{Hashnames.js → utils/hashnames.js} +2 -5
- package/lib/module/utils/hashnames.js.map +1 -0
- package/lib/module/utils/index.js +8 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/types.js +42 -0
- package/lib/module/utils/types.js.map +1 -0
- package/lib/module/utils/validation.js +19 -0
- package/lib/module/utils/validation.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/typescript/ed.d.ts +17 -0
- package/lib/typescript/ed.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +74 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/keys/classes.d.ts +38 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -0
- package/lib/typescript/keys/generateKeyPair.d.ts +1 -0
- package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -0
- package/lib/typescript/keys/index.d.ts +4 -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 +32 -0
- package/lib/typescript/keys/utils.d.ts.map +1 -0
- package/lib/typescript/{src/pbkdf2.d.ts → pbkdf2.d.ts} +4 -3
- package/lib/typescript/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/{src/random.d.ts → random.d.ts} +4 -4
- package/lib/typescript/random.d.ts.map +1 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts +16 -0
- package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +15 -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/random.nitro.d.ts +9 -0
- package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +25 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -0
- package/lib/typescript/utils/errors.d.ts +7 -0
- package/lib/typescript/utils/errors.d.ts.map +1 -0
- package/lib/typescript/{src/Hashnames.d.ts → utils/hashnames.d.ts} +3 -3
- package/lib/typescript/utils/hashnames.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +162 -0
- package/lib/typescript/utils/types.d.ts.map +1 -0
- package/lib/typescript/utils/validation.d.ts +8 -0
- package/lib/typescript/utils/validation.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +65 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +27 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +64 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +58 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +27 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +38 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +55 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +12 -0
- package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +93 -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 +22 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/JWK.hpp +162 -0
- package/nitrogen/generated/shared/c++/JWKkty.hpp +86 -0
- package/nitrogen/generated/shared/c++/JWKuse.hpp +78 -0
- package/nitrogen/generated/shared/c++/KFormatType.hpp +65 -0
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +93 -0
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +66 -0
- package/nitrogen/generated/shared/c++/KeyType.hpp +65 -0
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +102 -0
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +82 -0
- package/package.json +57 -51
- package/src/ed.ts +79 -0
- package/src/index.ts +43 -47
- package/src/keys/classes.ts +211 -0
- package/src/keys/generateKeyPair.ts +146 -0
- package/src/keys/index.ts +42 -0
- package/src/keys/signVerify.ts +39 -0
- package/src/keys/utils.ts +184 -0
- package/src/pbkdf2.ts +26 -15
- package/src/random.ts +33 -20
- package/src/specs/edKeyPair.nitro.ts +41 -0
- package/src/specs/keyObjectHandle.nitro.ts +32 -0
- package/src/{NativeQuickCrypto/pbkdf2.ts → specs/pbkdf2.nitro.ts} +8 -6
- package/src/specs/random.nitro.ts +14 -0
- package/src/utils/conversion.ts +123 -0
- package/src/utils/errors.ts +15 -0
- package/src/{Hashnames.ts → utils/hashnames.ts} +4 -7
- package/src/utils/index.ts +5 -0
- package/src/utils/types.ts +275 -0
- package/src/utils/validation.ts +35 -0
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
- package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
- package/cpp/Cipher/MGLCipherHostObject.h +0 -90
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
- package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
- package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
- package/cpp/Cipher/MGLPublicCipher.h +0 -124
- package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
- package/cpp/Cipher/MGLRsa.cpp +0 -573
- package/cpp/Cipher/MGLRsa.h +0 -109
- package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
- package/cpp/HMAC/MGLHmacHostObject.h +0 -39
- package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
- package/cpp/HMAC/MGLHmacInstaller.h +0 -20
- package/cpp/Hash/MGLHashHostObject.cpp +0 -147
- package/cpp/Hash/MGLHashHostObject.h +0 -53
- package/cpp/Hash/MGLHashInstaller.cpp +0 -44
- package/cpp/Hash/MGLHashInstaller.h +0 -20
- package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
- package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
- package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
- package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
- package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
- package/cpp/JSIUtils/MGLTypedArray.cpp +0 -352
- package/cpp/JSIUtils/MGLTypedArray.h +0 -179
- package/cpp/MGLKeys.cpp +0 -1426
- package/cpp/MGLKeys.h +0 -203
- package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
- package/cpp/MGLQuickCryptoHostObject.h +0 -30
- package/cpp/Random/MGLRandomHostObject.cpp +0 -96
- package/cpp/Random/MGLRandomHostObject.h +0 -27
- package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
- package/cpp/Sig/MGLSignHostObjects.h +0 -128
- package/cpp/Sig/MGLSignInstaller.cpp +0 -24
- package/cpp/Sig/MGLSignInstaller.h +0 -29
- package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
- package/cpp/Sig/MGLVerifyInstaller.h +0 -22
- package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
- package/cpp/Utils/MGLDispatchQueue.h +0 -55
- package/cpp/Utils/MGLUtils.cpp +0 -295
- package/cpp/Utils/MGLUtils.h +0 -358
- package/cpp/Utils/base64.h +0 -320
- package/cpp/Utils/logs.h +0 -38
- package/cpp/Utils/node.h +0 -13
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
- package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
- package/cpp/webcrypto/MGLWebCrypto.h +0 -32
- package/cpp/webcrypto/crypto_aes.cpp +0 -516
- package/cpp/webcrypto/crypto_aes.h +0 -79
- package/cpp/webcrypto/crypto_ec.cpp +0 -424
- package/cpp/webcrypto/crypto_ec.h +0 -78
- package/cpp/webcrypto/crypto_keygen.cpp +0 -86
- package/cpp/webcrypto/crypto_keygen.h +0 -38
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
- package/ios/QuickCrypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcuserdata/brad.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/QuickCrypto.xcodeproj/xcuserdata/brad.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/QuickCryptoModule.h +0 -5
- package/ios/QuickCryptoModule.mm +0 -57
- package/lib/commonjs/Algorithms.js +0 -224
- package/lib/commonjs/Algorithms.js.map +0 -1
- package/lib/commonjs/Cipher.js +0 -504
- package/lib/commonjs/Cipher.js.map +0 -1
- package/lib/commonjs/Hash.js +0 -102
- package/lib/commonjs/Hash.js.map +0 -1
- package/lib/commonjs/Hashnames.js.map +0 -1
- package/lib/commonjs/Hmac.js +0 -81
- package/lib/commonjs/Hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -59
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/commonjs/Utils.js +0 -437
- package/lib/commonjs/Utils.js.map +0 -1
- package/lib/commonjs/aes.js +0 -282
- package/lib/commonjs/aes.js.map +0 -1
- package/lib/commonjs/constants.js +0 -85
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/ec.js +0 -275
- package/lib/commonjs/ec.js.map +0 -1
- package/lib/commonjs/keygen.js +0 -58
- package/lib/commonjs/keygen.js.map +0 -1
- package/lib/commonjs/keys.js +0 -497
- package/lib/commonjs/keys.js.map +0 -1
- package/lib/commonjs/rsa.js +0 -248
- package/lib/commonjs/rsa.js.map +0 -1
- package/lib/commonjs/sig.js +0 -128
- package/lib/commonjs/sig.js.map +0 -1
- package/lib/commonjs/subtle.js +0 -450
- package/lib/commonjs/subtle.js.map +0 -1
- package/lib/commonjs/webcrypto.js +0 -14
- package/lib/commonjs/webcrypto.js.map +0 -1
- package/lib/module/Algorithms.js +0 -219
- package/lib/module/Algorithms.js.map +0 -1
- package/lib/module/Cipher.js +0 -493
- package/lib/module/Cipher.js.map +0 -1
- package/lib/module/Hash.js +0 -96
- package/lib/module/Hash.js.map +0 -1
- package/lib/module/Hashnames.js.map +0 -1
- package/lib/module/Hmac.js +0 -76
- package/lib/module/Hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
- package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -56
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/module/NativeQuickCrypto/aes.js +0 -4
- package/lib/module/NativeQuickCrypto/hash.js +0 -2
- package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/module/NativeQuickCrypto/hmac.js +0 -2
- package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/keygen.js +0 -4
- package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/module/NativeQuickCrypto/random.js +0 -2
- package/lib/module/NativeQuickCrypto/random.js.map +0 -1
- package/lib/module/NativeQuickCrypto/rsa.js +0 -4
- package/lib/module/NativeQuickCrypto/sig.js +0 -17
- package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
- package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/module/Utils.js +0 -369
- package/lib/module/Utils.js.map +0 -1
- package/lib/module/aes.js +0 -275
- package/lib/module/aes.js.map +0 -1
- package/lib/module/constants.js +0 -81
- package/lib/module/constants.js.map +0 -1
- package/lib/module/ec.js +0 -266
- package/lib/module/ec.js.map +0 -1
- package/lib/module/keygen.js +0 -51
- package/lib/module/keygen.js.map +0 -1
- package/lib/module/keys.js +0 -482
- package/lib/module/keys.js.map +0 -1
- package/lib/module/rsa.js +0 -242
- package/lib/module/rsa.js.map +0 -1
- package/lib/module/sig.js +0 -123
- package/lib/module/sig.js.map +0 -1
- package/lib/module/subtle.js +0 -445
- package/lib/module/subtle.js.map +0 -1
- package/lib/module/webcrypto.js +0 -10
- package/lib/module/webcrypto.js.map +0 -1
- package/lib/typescript/src/Algorithms.d.ts +0 -4
- package/lib/typescript/src/Algorithms.d.ts.map +0 -1
- package/lib/typescript/src/Cipher.d.ts +0 -85
- package/lib/typescript/src/Cipher.d.ts.map +0 -1
- package/lib/typescript/src/Hash.d.ts +0 -44
- package/lib/typescript/src/Hash.d.ts.map +0 -1
- package/lib/typescript/src/Hashnames.d.ts.map +0 -1
- package/lib/typescript/src/Hmac.d.ts +0 -37
- package/lib/typescript/src/Hmac.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts +0 -44
- package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
- package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/aes.d.ts +0 -5
- package/lib/typescript/src/NativeQuickCrypto/aes.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/hash.d.ts +0 -7
- package/lib/typescript/src/NativeQuickCrypto/hash.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts +0 -6
- package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/keygen.d.ts +0 -4
- package/lib/typescript/src/NativeQuickCrypto/keygen.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts +0 -5
- package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/random.d.ts +0 -5
- package/lib/typescript/src/NativeQuickCrypto/random.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/rsa.d.ts +0 -5
- package/lib/typescript/src/NativeQuickCrypto/rsa.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/sig.d.ts +0 -23
- package/lib/typescript/src/NativeQuickCrypto/sig.d.ts.map +0 -1
- package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts +0 -40
- package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
- package/lib/typescript/src/Utils.d.ts +0 -71
- package/lib/typescript/src/Utils.d.ts.map +0 -1
- package/lib/typescript/src/aes.d.ts +0 -22
- package/lib/typescript/src/aes.d.ts.map +0 -1
- package/lib/typescript/src/constants.d.ts +0 -76
- package/lib/typescript/src/constants.d.ts.map +0 -1
- package/lib/typescript/src/ec.d.ts +0 -7
- package/lib/typescript/src/ec.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -139
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/keygen.d.ts +0 -6
- package/lib/typescript/src/keygen.d.ts.map +0 -1
- package/lib/typescript/src/keys.d.ts +0 -211
- package/lib/typescript/src/keys.d.ts.map +0 -1
- package/lib/typescript/src/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/src/random.d.ts.map +0 -1
- package/lib/typescript/src/rsa.d.ts +0 -12
- package/lib/typescript/src/rsa.d.ts.map +0 -1
- package/lib/typescript/src/sig.d.ts +0 -21
- package/lib/typescript/src/sig.d.ts.map +0 -1
- package/lib/typescript/src/subtle.d.ts +0 -15
- package/lib/typescript/src/subtle.d.ts.map +0 -1
- package/lib/typescript/src/webcrypto.d.ts +0 -9
- package/lib/typescript/src/webcrypto.d.ts.map +0 -1
- package/react-native-quick-crypto.podspec +0 -40
- package/src/Algorithms.ts +0 -247
- package/src/Cipher.ts +0 -890
- package/src/Hash.ts +0 -139
- package/src/Hmac.ts +0 -107
- package/src/NativeQuickCrypto/Cipher.ts +0 -103
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -106
- package/src/NativeQuickCrypto/aes.ts +0 -14
- package/src/NativeQuickCrypto/hash.ts +0 -10
- package/src/NativeQuickCrypto/hmac.ts +0 -9
- package/src/NativeQuickCrypto/keygen.ts +0 -7
- package/src/NativeQuickCrypto/random.ts +0 -12
- package/src/NativeQuickCrypto/rsa.ts +0 -12
- package/src/NativeQuickCrypto/sig.ts +0 -46
- package/src/NativeQuickCrypto/webcrypto.ts +0 -73
- package/src/Utils.ts +0 -628
- package/src/aes.ts +0 -402
- package/src/constants.ts +0 -79
- package/src/ec.ts +0 -374
- package/src/keygen.ts +0 -80
- package/src/keys.ts +0 -797
- package/src/rsa.ts +0 -372
- package/src/sig.ts +0 -163
- package/src/subtle.ts +0 -643
- package/src/webcrypto.ts +0 -8
- /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
- /package/{cpp → deps}/fastpbkdf2/fastpbkdf2.c +0 -0
- /package/{cpp → deps}/fastpbkdf2/fastpbkdf2.h +0 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
#include "HybridEdKeyPair.hpp"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
namespace margelo::nitro::crypto {
|
|
7
|
+
|
|
8
|
+
std::shared_ptr<Promise<void>>
|
|
9
|
+
HybridEdKeyPair::generateKeyPair(
|
|
10
|
+
double publicFormat,
|
|
11
|
+
double publicType,
|
|
12
|
+
double privateFormat,
|
|
13
|
+
double privateType,
|
|
14
|
+
const std::optional<std::string>& cipher,
|
|
15
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase
|
|
16
|
+
) {
|
|
17
|
+
// get owned NativeArrayBuffers before passing to sync function
|
|
18
|
+
std::optional<std::shared_ptr<ArrayBuffer>> nativePassphrase = std::nullopt;
|
|
19
|
+
if (passphrase.has_value()) {
|
|
20
|
+
nativePassphrase = ToNativeArrayBuffer(passphrase.value());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return Promise<void>::async(
|
|
24
|
+
[this, publicFormat, publicType, privateFormat, privateType, cipher,
|
|
25
|
+
nativePassphrase]() {
|
|
26
|
+
this->generateKeyPairSync(
|
|
27
|
+
publicFormat,
|
|
28
|
+
publicType,
|
|
29
|
+
privateFormat,
|
|
30
|
+
privateType,
|
|
31
|
+
cipher,
|
|
32
|
+
nativePassphrase
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void
|
|
39
|
+
HybridEdKeyPair::generateKeyPairSync(
|
|
40
|
+
double publicFormat,
|
|
41
|
+
double publicType,
|
|
42
|
+
double privateFormat,
|
|
43
|
+
double privateType,
|
|
44
|
+
const std::optional<std::string>& cipher,
|
|
45
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase
|
|
46
|
+
) {
|
|
47
|
+
EVP_PKEY_CTX* pctx;
|
|
48
|
+
|
|
49
|
+
// key context
|
|
50
|
+
pctx = EVP_PKEY_CTX_new_from_name(nullptr, this->curve.c_str(), nullptr);
|
|
51
|
+
if (pctx == nullptr) {
|
|
52
|
+
throw std::runtime_error("Invalid curve name: " + this->curve);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// keygen init
|
|
56
|
+
if (EVP_PKEY_keygen_init(pctx) <= 0) {
|
|
57
|
+
EVP_PKEY_CTX_free(pctx);
|
|
58
|
+
throw std::runtime_error("Failed to initialize keygen");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// generate key
|
|
62
|
+
EVP_PKEY_keygen(pctx, &this->pkey);
|
|
63
|
+
if (this->pkey == nullptr) {
|
|
64
|
+
EVP_PKEY_CTX_free(pctx);
|
|
65
|
+
throw std::runtime_error("Failed to generate key");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// cleanup
|
|
69
|
+
EVP_PKEY_CTX_free(pctx);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>
|
|
74
|
+
HybridEdKeyPair::sign(
|
|
75
|
+
const std::shared_ptr<ArrayBuffer>& message,
|
|
76
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
77
|
+
) {
|
|
78
|
+
// get owned NativeArrayBuffer before passing to sync function
|
|
79
|
+
auto nativeMessage = ToNativeArrayBuffer(message);
|
|
80
|
+
std::optional<std::shared_ptr<ArrayBuffer>> nativeKey = std::nullopt;
|
|
81
|
+
if (key.has_value()) {
|
|
82
|
+
nativeKey = ToNativeArrayBuffer(key.value());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return Promise<std::shared_ptr<ArrayBuffer>>::async([this, nativeMessage, nativeKey]() {
|
|
86
|
+
return this->signSync(nativeMessage, nativeKey);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
std::shared_ptr<ArrayBuffer>
|
|
92
|
+
HybridEdKeyPair::signSync(
|
|
93
|
+
const std::shared_ptr<ArrayBuffer>& message,
|
|
94
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
95
|
+
) {
|
|
96
|
+
|
|
97
|
+
size_t sig_len = 0;
|
|
98
|
+
uint8_t* sig = NULL;
|
|
99
|
+
EVP_MD_CTX* md_ctx = nullptr;
|
|
100
|
+
EVP_PKEY_CTX* pkey_ctx = nullptr;
|
|
101
|
+
|
|
102
|
+
// get key to use for signing
|
|
103
|
+
EVP_PKEY* pkey = this->importPrivateKey(key);
|
|
104
|
+
|
|
105
|
+
// key context
|
|
106
|
+
md_ctx = EVP_MD_CTX_new();
|
|
107
|
+
if (md_ctx == nullptr) {
|
|
108
|
+
EVP_MD_CTX_free(md_ctx);
|
|
109
|
+
throw std::runtime_error("Error creating signing context");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
pkey_ctx = EVP_PKEY_CTX_new_from_name(nullptr, this->curve.c_str(), nullptr);
|
|
113
|
+
if (pkey_ctx == nullptr) {
|
|
114
|
+
EVP_PKEY_CTX_free(pkey_ctx);
|
|
115
|
+
throw std::runtime_error("Error creating signing context: " + this->curve);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (EVP_DigestSignInit(md_ctx, &pkey_ctx, NULL, NULL, pkey) <= 0) {
|
|
119
|
+
EVP_MD_CTX_free(md_ctx);
|
|
120
|
+
char* err = ERR_error_string(ERR_get_error(), NULL);
|
|
121
|
+
throw std::runtime_error("Failed to initialize signing: " + std::string(err));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Calculate the required size for the signature by passing a NULL buffer.
|
|
125
|
+
if (EVP_DigestSign(md_ctx, NULL, &sig_len, message.get()->data(), message.get()->size()) <= 0) {
|
|
126
|
+
EVP_MD_CTX_free(md_ctx);
|
|
127
|
+
throw std::runtime_error("Failed to calculate signature size");
|
|
128
|
+
}
|
|
129
|
+
sig = new uint8_t[sig_len];
|
|
130
|
+
|
|
131
|
+
// Actually calculate the signature
|
|
132
|
+
if (EVP_DigestSign(md_ctx, sig, &sig_len, message.get()->data(), message.get()->size()) <= 0) {
|
|
133
|
+
EVP_MD_CTX_free(md_ctx);
|
|
134
|
+
throw std::runtime_error("Failed to calculate signature");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// return value for JS
|
|
138
|
+
std::shared_ptr<ArrayBuffer> signature = std::make_shared<NativeArrayBuffer>(
|
|
139
|
+
sig,
|
|
140
|
+
sig_len,
|
|
141
|
+
[=]() { delete[] sig; }
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// Clean up
|
|
145
|
+
EVP_MD_CTX_free(md_ctx);
|
|
146
|
+
|
|
147
|
+
return signature;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
std::shared_ptr<Promise<bool>>
|
|
151
|
+
HybridEdKeyPair::verify(
|
|
152
|
+
const std::shared_ptr<ArrayBuffer>& signature,
|
|
153
|
+
const std::shared_ptr<ArrayBuffer>& message,
|
|
154
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
155
|
+
) {
|
|
156
|
+
// get owned NativeArrayBuffers before passing to sync function
|
|
157
|
+
auto nativeSignature = ToNativeArrayBuffer(signature);
|
|
158
|
+
auto nativeMessage = ToNativeArrayBuffer(message);
|
|
159
|
+
std::optional<std::shared_ptr<ArrayBuffer>> nativeKey = std::nullopt;
|
|
160
|
+
if (key.has_value()) {
|
|
161
|
+
nativeKey = ToNativeArrayBuffer(key.value());
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return Promise<bool>::async([this, nativeSignature, nativeMessage, nativeKey]() {
|
|
165
|
+
return this->verifySync(nativeSignature, nativeMessage, nativeKey);
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
bool
|
|
171
|
+
HybridEdKeyPair::verifySync(
|
|
172
|
+
const std::shared_ptr<ArrayBuffer>& signature,
|
|
173
|
+
const std::shared_ptr<ArrayBuffer>& message,
|
|
174
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
175
|
+
) {
|
|
176
|
+
// get key to use for verifying
|
|
177
|
+
EVP_PKEY* pkey = this->importPrivateKey(key);
|
|
178
|
+
|
|
179
|
+
EVP_MD_CTX* md_ctx = nullptr;
|
|
180
|
+
EVP_PKEY_CTX* pkey_ctx = nullptr;
|
|
181
|
+
|
|
182
|
+
// key context
|
|
183
|
+
md_ctx = EVP_MD_CTX_new();
|
|
184
|
+
if (md_ctx == nullptr) {
|
|
185
|
+
EVP_MD_CTX_free(md_ctx);
|
|
186
|
+
throw std::runtime_error("Error creating verify context");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
pkey_ctx = EVP_PKEY_CTX_new_from_name(nullptr, this->curve.c_str(), nullptr);
|
|
190
|
+
if (pkey_ctx == nullptr) {
|
|
191
|
+
EVP_PKEY_CTX_free(pkey_ctx);
|
|
192
|
+
throw std::runtime_error("Error creating verify context: " + this->curve);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (EVP_DigestVerifyInit(md_ctx, &pkey_ctx, NULL, NULL, pkey) <= 0) {
|
|
196
|
+
EVP_MD_CTX_free(md_ctx);
|
|
197
|
+
char* err = ERR_error_string(ERR_get_error(), NULL);
|
|
198
|
+
throw std::runtime_error("Failed to initialize verify: " + std::string(err));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// verify
|
|
202
|
+
auto res = EVP_DigestVerify(
|
|
203
|
+
md_ctx,
|
|
204
|
+
signature.get()->data(), signature.get()->size(),
|
|
205
|
+
message.get()->data(), message.get()->size()
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
//return value for JS
|
|
209
|
+
if (res < 0) {
|
|
210
|
+
EVP_MD_CTX_free(md_ctx);
|
|
211
|
+
throw std::runtime_error("Failed to verify");
|
|
212
|
+
}
|
|
213
|
+
return res == 1; // true if 1, false if 0
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
std::shared_ptr<ArrayBuffer>
|
|
217
|
+
HybridEdKeyPair::getPublicKey() {
|
|
218
|
+
this->checkKeyPair();
|
|
219
|
+
size_t len = 32;
|
|
220
|
+
uint8_t* publ = new uint8_t[len];
|
|
221
|
+
EVP_PKEY_get_raw_public_key(this->pkey, publ, &len);
|
|
222
|
+
|
|
223
|
+
return std::make_shared<NativeArrayBuffer>(publ, len, [=]() { delete[] publ; });
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
std::shared_ptr<ArrayBuffer>
|
|
227
|
+
HybridEdKeyPair::getPrivateKey() {
|
|
228
|
+
this->checkKeyPair();
|
|
229
|
+
size_t len = 32;
|
|
230
|
+
uint8_t* priv = new uint8_t[len];
|
|
231
|
+
EVP_PKEY_get_raw_private_key(this->pkey, priv, &len);
|
|
232
|
+
|
|
233
|
+
return std::make_shared<NativeArrayBuffer>(priv, len, [=]() { delete[] priv; });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
void
|
|
237
|
+
HybridEdKeyPair::checkKeyPair() {
|
|
238
|
+
if (this->pkey == nullptr) {
|
|
239
|
+
throw std::runtime_error("Keypair not initialized");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
void
|
|
244
|
+
HybridEdKeyPair::setCurve(const std::string& curve) {
|
|
245
|
+
this->curve = curve;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
EVP_PKEY*
|
|
249
|
+
HybridEdKeyPair::importPrivateKey(const std::optional<std::shared_ptr<ArrayBuffer>>& key) {
|
|
250
|
+
EVP_PKEY* pkey = nullptr;
|
|
251
|
+
if (key.has_value()) {
|
|
252
|
+
pkey = EVP_PKEY_new_raw_private_key(
|
|
253
|
+
EVP_PKEY_ED25519, // TODO: use this->curve somehow
|
|
254
|
+
NULL,
|
|
255
|
+
key.value()->data(),
|
|
256
|
+
32
|
|
257
|
+
);
|
|
258
|
+
if (pkey == nullptr) {
|
|
259
|
+
throw std::runtime_error("Failed to read private key");
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
this->checkKeyPair();
|
|
263
|
+
pkey = this->pkey;
|
|
264
|
+
}
|
|
265
|
+
return pkey;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#include <openssl/evp.h>
|
|
2
|
+
#include <openssl/err.h>
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "HybridEdKeyPairSpec.hpp"
|
|
7
|
+
#include "Utils.hpp"
|
|
8
|
+
|
|
9
|
+
namespace margelo::nitro::crypto {
|
|
10
|
+
|
|
11
|
+
using namespace facebook;
|
|
12
|
+
|
|
13
|
+
class HybridEdKeyPair : public HybridEdKeyPairSpec {
|
|
14
|
+
public:
|
|
15
|
+
HybridEdKeyPair() : HybridObject(TAG) {}
|
|
16
|
+
|
|
17
|
+
public:
|
|
18
|
+
// Methods
|
|
19
|
+
std::shared_ptr<Promise<void>>
|
|
20
|
+
generateKeyPair(
|
|
21
|
+
double publicFormat,
|
|
22
|
+
double publicType,
|
|
23
|
+
double privateFormat,
|
|
24
|
+
double privateType,
|
|
25
|
+
const std::optional<std::string>& cipher,
|
|
26
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase
|
|
27
|
+
) override;
|
|
28
|
+
|
|
29
|
+
void
|
|
30
|
+
generateKeyPairSync(
|
|
31
|
+
double publicFormat,
|
|
32
|
+
double publicType,
|
|
33
|
+
double privateFormat,
|
|
34
|
+
double privateType,
|
|
35
|
+
const std::optional<std::string>& cipher,
|
|
36
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase
|
|
37
|
+
) override;
|
|
38
|
+
|
|
39
|
+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>
|
|
40
|
+
sign(
|
|
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;
|
|
64
|
+
|
|
65
|
+
protected:
|
|
66
|
+
std::shared_ptr<ArrayBuffer>
|
|
67
|
+
getPublicKey() override;
|
|
68
|
+
|
|
69
|
+
std::shared_ptr<ArrayBuffer>
|
|
70
|
+
getPrivateKey() override;
|
|
71
|
+
|
|
72
|
+
void checkKeyPair();
|
|
73
|
+
|
|
74
|
+
void setCurve(const std::string& curve) override;
|
|
75
|
+
|
|
76
|
+
private:
|
|
77
|
+
std::string curve;
|
|
78
|
+
EVP_PKEY* pkey = nullptr;
|
|
79
|
+
|
|
80
|
+
EVP_PKEY* importPrivateKey(
|
|
81
|
+
const std::optional<std::shared_ptr<ArrayBuffer>>& key
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#include "HybridPbkdf2.hpp"
|
|
2
|
+
#include "Utils.hpp"
|
|
3
|
+
|
|
4
|
+
namespace margelo::nitro::crypto {
|
|
5
|
+
|
|
6
|
+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>
|
|
7
|
+
HybridPbkdf2::pbkdf2(
|
|
8
|
+
const std::shared_ptr<ArrayBuffer>& password,
|
|
9
|
+
const std::shared_ptr<ArrayBuffer>& salt,
|
|
10
|
+
double iterations,
|
|
11
|
+
double keylen,
|
|
12
|
+
const std::string& digest
|
|
13
|
+
) {
|
|
14
|
+
// get owned NativeArrayBuffers before passing to sync function
|
|
15
|
+
auto nativePassword = ToNativeArrayBuffer(password);
|
|
16
|
+
auto nativeSalt = ToNativeArrayBuffer(salt);
|
|
17
|
+
|
|
18
|
+
return Promise<std::shared_ptr<ArrayBuffer>>::async(
|
|
19
|
+
[this, nativePassword, nativeSalt, iterations, keylen, digest]() {
|
|
20
|
+
return this->pbkdf2Sync(nativePassword, nativeSalt, iterations, keylen, digest);
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
std::shared_ptr<ArrayBuffer>
|
|
26
|
+
HybridPbkdf2::pbkdf2Sync(
|
|
27
|
+
const std::shared_ptr<ArrayBuffer>& password,
|
|
28
|
+
const std::shared_ptr<ArrayBuffer>& salt,
|
|
29
|
+
double iterations,
|
|
30
|
+
double keylen,
|
|
31
|
+
const std::string& digest
|
|
32
|
+
) {
|
|
33
|
+
size_t bufferSize = static_cast<size_t>(keylen);
|
|
34
|
+
uint8_t* data = new uint8_t[bufferSize];
|
|
35
|
+
auto result = std::make_shared<NativeArrayBuffer>(data, bufferSize, [=]() { delete[] data; });
|
|
36
|
+
|
|
37
|
+
// use fastpbkdf2 when possible
|
|
38
|
+
if (digest == "sha1") {
|
|
39
|
+
fastpbkdf2_hmac_sha1(password.get()->data(), password.get()->size(),
|
|
40
|
+
salt.get()->data(), salt.get()->size(),
|
|
41
|
+
static_cast<uint32_t>(iterations),
|
|
42
|
+
result.get()->data(), result.get()->size());
|
|
43
|
+
} else if (digest == "sha256") {
|
|
44
|
+
fastpbkdf2_hmac_sha256(password.get()->data(), password.get()->size(),
|
|
45
|
+
salt.get()->data(), salt.get()->size(),
|
|
46
|
+
static_cast<uint32_t>(iterations),
|
|
47
|
+
result.get()->data(), result.get()->size());
|
|
48
|
+
} else if (digest == "sha512") {
|
|
49
|
+
fastpbkdf2_hmac_sha512(password.get()->data(), password.get()->size(),
|
|
50
|
+
salt.get()->data(), salt.get()->size(),
|
|
51
|
+
static_cast<uint32_t>(iterations),
|
|
52
|
+
result.get()->data(), result.get()->size());
|
|
53
|
+
} else {
|
|
54
|
+
// fallback to OpenSSL
|
|
55
|
+
auto *digestByName = EVP_get_digestbyname(digest.c_str());
|
|
56
|
+
if (digestByName == nullptr) {
|
|
57
|
+
throw std::runtime_error("Invalid hash-algorithm: " + digest);
|
|
58
|
+
}
|
|
59
|
+
char *passAsCharA = reinterpret_cast<char *>(password.get()->data());
|
|
60
|
+
const unsigned char *saltAsCharA =
|
|
61
|
+
reinterpret_cast<const unsigned char *>(salt.get()->data());
|
|
62
|
+
unsigned char *resultAsCharA =
|
|
63
|
+
reinterpret_cast<unsigned char *>(result.get()->data());
|
|
64
|
+
PKCS5_PBKDF2_HMAC(passAsCharA, password.get()->size(), saltAsCharA,
|
|
65
|
+
salt.get()->size(), static_cast<uint32_t>(iterations),
|
|
66
|
+
digestByName, result.get()->size(), resultAsCharA);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#include <openssl/evp.h>
|
|
2
|
+
|
|
3
|
+
#include "HybridPbkdf2Spec.hpp"
|
|
4
|
+
#include "fastpbkdf2.h"
|
|
5
|
+
|
|
6
|
+
namespace margelo::nitro::crypto {
|
|
7
|
+
|
|
8
|
+
using namespace facebook;
|
|
9
|
+
|
|
10
|
+
class HybridPbkdf2 : public HybridPbkdf2Spec {
|
|
11
|
+
public:
|
|
12
|
+
HybridPbkdf2() : HybridObject(TAG) {}
|
|
13
|
+
|
|
14
|
+
public:
|
|
15
|
+
// Methods
|
|
16
|
+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>
|
|
17
|
+
pbkdf2(
|
|
18
|
+
const std::shared_ptr<ArrayBuffer>& password,
|
|
19
|
+
const std::shared_ptr<ArrayBuffer>& salt,
|
|
20
|
+
double iterations,
|
|
21
|
+
double keylen,
|
|
22
|
+
const std::string& digest
|
|
23
|
+
) override;
|
|
24
|
+
|
|
25
|
+
std::shared_ptr<ArrayBuffer>
|
|
26
|
+
pbkdf2Sync(
|
|
27
|
+
const std::shared_ptr<ArrayBuffer>& password,
|
|
28
|
+
const std::shared_ptr<ArrayBuffer>& salt,
|
|
29
|
+
double iterations,
|
|
30
|
+
double keylen,
|
|
31
|
+
const std::string& digest
|
|
32
|
+
) override;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#include <openssl/err.h>
|
|
2
|
+
#include <openssl/rand.h>
|
|
3
|
+
|
|
4
|
+
#include "HybridRandom.hpp"
|
|
5
|
+
#include "Utils.hpp"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
size_t checkSize(double size) {
|
|
9
|
+
if (!CheckIsUint32(size)) {
|
|
10
|
+
throw std::runtime_error("size must be uint32");
|
|
11
|
+
}
|
|
12
|
+
if (static_cast<uint32_t>(size) > pow(2, 31) - 1) {
|
|
13
|
+
throw std::runtime_error("size must be less than 2^31 - 1");
|
|
14
|
+
}
|
|
15
|
+
return static_cast<size_t>(size);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
size_t checkOffset(double size, double offset) {
|
|
19
|
+
if (!CheckIsUint32(offset)) {
|
|
20
|
+
throw std::runtime_error("offset must be uint32");
|
|
21
|
+
}
|
|
22
|
+
if (offset > size) {
|
|
23
|
+
throw std::runtime_error("offset must be less than size");
|
|
24
|
+
}
|
|
25
|
+
return static_cast<size_t>(offset);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
namespace margelo::nitro::crypto {
|
|
30
|
+
|
|
31
|
+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>
|
|
32
|
+
HybridRandom::randomFill(const std::shared_ptr<ArrayBuffer>& buffer,
|
|
33
|
+
double dOffset,
|
|
34
|
+
double dSize) {
|
|
35
|
+
// get owned NativeArrayBuffer before passing to sync function
|
|
36
|
+
auto nativeBuffer = ToNativeArrayBuffer(buffer);
|
|
37
|
+
|
|
38
|
+
return Promise<std::shared_ptr<ArrayBuffer>>::async(
|
|
39
|
+
[this, nativeBuffer, dOffset, dSize]() {
|
|
40
|
+
return this->randomFillSync(nativeBuffer, dOffset, dSize);
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
std::shared_ptr<ArrayBuffer>
|
|
46
|
+
HybridRandom::randomFillSync(const std::shared_ptr<ArrayBuffer>& buffer,
|
|
47
|
+
double dOffset,
|
|
48
|
+
double dSize) {
|
|
49
|
+
size_t size = checkSize(dSize);
|
|
50
|
+
size_t offset = checkOffset(dSize, dOffset);
|
|
51
|
+
uint8_t* data = buffer.get()->data();
|
|
52
|
+
if (RAND_bytes(data + offset, (int)size) != 1) {
|
|
53
|
+
throw std::runtime_error("error calling RAND_bytes" +
|
|
54
|
+
std::to_string(ERR_get_error()));
|
|
55
|
+
}
|
|
56
|
+
return buffer;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#include <cmath>
|
|
2
|
+
#include <future>
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <iostream>
|
|
5
|
+
|
|
6
|
+
#include "HybridRandomSpec.hpp"
|
|
7
|
+
|
|
8
|
+
namespace margelo::nitro::crypto {
|
|
9
|
+
|
|
10
|
+
using namespace facebook;
|
|
11
|
+
|
|
12
|
+
class HybridRandom : public HybridRandomSpec {
|
|
13
|
+
public:
|
|
14
|
+
HybridRandom() : HybridObject(TAG) {}
|
|
15
|
+
|
|
16
|
+
public:
|
|
17
|
+
// Methods
|
|
18
|
+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>
|
|
19
|
+
randomFill(const std::shared_ptr<ArrayBuffer>& buffer, double dOffset, double dSize) override;
|
|
20
|
+
|
|
21
|
+
std::shared_ptr<ArrayBuffer>
|
|
22
|
+
randomFillSync(const std::shared_ptr<ArrayBuffer>& buffer, double dOffset, double dSize) override;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
inline void printData(std::string name, uint8_t* data, size_t size) {
|
|
26
|
+
std::cout << "data - " << name << std::endl;
|
|
27
|
+
for (size_t i = 0; i < size; i++) {
|
|
28
|
+
printf("%u ", data[i]);
|
|
29
|
+
}
|
|
30
|
+
printf("\n");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#include <limits>
|
|
2
|
+
|
|
3
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
4
|
+
|
|
5
|
+
// copy a JSArrayBuffer that we do not own into a NativeArrayBuffer that we do own
|
|
6
|
+
inline std::shared_ptr<margelo::nitro::NativeArrayBuffer>
|
|
7
|
+
ToNativeArrayBuffer(const std::shared_ptr<margelo::nitro::ArrayBuffer>& buffer) {
|
|
8
|
+
size_t bufferSize = buffer.get()->size();
|
|
9
|
+
uint8_t* data = new uint8_t[bufferSize];
|
|
10
|
+
memcpy(data, buffer.get()->data(), bufferSize);
|
|
11
|
+
return std::make_shared<margelo::nitro::NativeArrayBuffer>(data, bufferSize, [=]() { delete[] data; });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
inline bool CheckIsUint32(double value) {
|
|
15
|
+
return (value >= std::numeric_limits<uint32_t>::lowest() && value <= std::numeric_limits<uint32_t>::max());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
inline bool CheckIsInt32(double value) {
|
|
19
|
+
return (value >= std::numeric_limits<int32_t>::lowest() && value <= std::numeric_limits<int32_t>::max());
|
|
20
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Ed = void 0;
|
|
7
|
+
var _reactNativeNitroModules = require("react-native-nitro-modules");
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
class Ed {
|
|
10
|
+
constructor(type, config) {
|
|
11
|
+
this.type = type;
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.native = _reactNativeNitroModules.NitroModules.createHybridObject('EdKeyPair');
|
|
14
|
+
this.native.setCurve(type);
|
|
15
|
+
}
|
|
16
|
+
async generateKeyPair() {
|
|
17
|
+
this.native.generateKeyPair(this.config.publicFormat || -1, this.config.publicType || -1, this.config.privateFormat || -1, this.config.privateType || -1, this.config.cipher, this.config.passphrase);
|
|
18
|
+
}
|
|
19
|
+
generateKeyPairSync() {
|
|
20
|
+
this.native.generateKeyPairSync(this.config.publicFormat || -1, this.config.publicType || -1, this.config.privateFormat || -1, this.config.privateType || -1, this.config.cipher, this.config.passphrase);
|
|
21
|
+
}
|
|
22
|
+
getPublicKey() {
|
|
23
|
+
return this.native.getPublicKey();
|
|
24
|
+
}
|
|
25
|
+
getPrivateKey() {
|
|
26
|
+
return this.native.getPrivateKey();
|
|
27
|
+
}
|
|
28
|
+
async sign(message, key) {
|
|
29
|
+
return key ? this.native.sign((0, _utils.binaryLikeToArrayBuffer)(message), (0, _utils.binaryLikeToArrayBuffer)(key)) : this.native.sign((0, _utils.binaryLikeToArrayBuffer)(message));
|
|
30
|
+
}
|
|
31
|
+
signSync(message, key) {
|
|
32
|
+
return key ? this.native.signSync((0, _utils.binaryLikeToArrayBuffer)(message), (0, _utils.binaryLikeToArrayBuffer)(key)) : this.native.signSync((0, _utils.binaryLikeToArrayBuffer)(message));
|
|
33
|
+
}
|
|
34
|
+
async verify(signature, message, key) {
|
|
35
|
+
return key ? this.native.verify((0, _utils.binaryLikeToArrayBuffer)(signature), (0, _utils.binaryLikeToArrayBuffer)(message), (0, _utils.binaryLikeToArrayBuffer)(key)) : this.native.verify((0, _utils.binaryLikeToArrayBuffer)(signature), (0, _utils.binaryLikeToArrayBuffer)(message));
|
|
36
|
+
}
|
|
37
|
+
verifySync(signature, message, key) {
|
|
38
|
+
return key ? this.native.verifySync((0, _utils.binaryLikeToArrayBuffer)(signature), (0, _utils.binaryLikeToArrayBuffer)(message), (0, _utils.binaryLikeToArrayBuffer)(key)) : this.native.verifySync((0, _utils.binaryLikeToArrayBuffer)(signature), (0, _utils.binaryLikeToArrayBuffer)(message));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Ed = Ed;
|
|
42
|
+
//# sourceMappingURL=ed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","_utils","Ed","constructor","type","config","native","NitroModules","createHybridObject","setCurve","generateKeyPair","publicFormat","publicType","privateFormat","privateType","cipher","passphrase","generateKeyPairSync","getPublicKey","getPrivateKey","sign","message","key","toAB","signSync","verify","signature","verifySync","exports"],"sourceRoot":"../../src","sources":["ed.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAIO,MAAME,EAAE,CAAC;EAKdC,WAAWA,CAACC,IAAqB,EAAEC,MAAwB,EAAE;IAC3D,IAAI,CAACD,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,MAAM,GAAGC,qCAAY,CAACC,kBAAkB,CAAY,WAAW,CAAC;IACrE,IAAI,CAACF,MAAM,CAACG,QAAQ,CAACL,IAAI,CAAC;EAC5B;EAEA,MAAMM,eAAeA,CAAA,EAAkB;IACrC,IAAI,CAACJ,MAAM,CAACI,eAAe,CACzB,IAAI,CAACL,MAAM,CAACM,YAAY,IAAK,CAAC,CAAY,EAC1C,IAAI,CAACN,MAAM,CAACO,UAAU,IAAK,CAAC,CAAY,EACxC,IAAI,CAACP,MAAM,CAACQ,aAAa,IAAK,CAAC,CAAY,EAC3C,IAAI,CAACR,MAAM,CAACS,WAAW,IAAK,CAAC,CAAY,EACzC,IAAI,CAACT,MAAM,CAACU,MAAM,EAClB,IAAI,CAACV,MAAM,CAACW,UACd,CAAC;EACH;EAEAC,mBAAmBA,CAAA,EAAS;IAC1B,IAAI,CAACX,MAAM,CAACW,mBAAmB,CAC7B,IAAI,CAACZ,MAAM,CAACM,YAAY,IAAK,CAAC,CAAY,EAC1C,IAAI,CAACN,MAAM,CAACO,UAAU,IAAK,CAAC,CAAY,EACxC,IAAI,CAACP,MAAM,CAACQ,aAAa,IAAK,CAAC,CAAY,EAC3C,IAAI,CAACR,MAAM,CAACS,WAAW,IAAK,CAAC,CAAY,EACzC,IAAI,CAACT,MAAM,CAACU,MAAM,EAClB,IAAI,CAACV,MAAM,CAACW,UACd,CAAC;EACH;EAEAE,YAAYA,CAAA,EAAgB;IAC1B,OAAO,IAAI,CAACZ,MAAM,CAACY,YAAY,CAAC,CAAC;EACnC;EAEAC,aAAaA,CAAA,EAAgB;IAC3B,OAAO,IAAI,CAACb,MAAM,CAACa,aAAa,CAAC,CAAC;EACpC;EAEA,MAAMC,IAAIA,CAACC,OAAmB,EAAEC,GAAgB,EAAwB;IACtE,OAAOA,GAAG,GACN,IAAI,CAAChB,MAAM,CAACc,IAAI,CAAC,IAAAG,8BAAI,EAACF,OAAO,CAAC,EAAE,IAAAE,8BAAI,EAACD,GAAG,CAAC,CAAC,GAC1C,IAAI,CAAChB,MAAM,CAACc,IAAI,CAAC,IAAAG,8BAAI,EAACF,OAAO,CAAC,CAAC;EACrC;EAEAG,QAAQA,CAACH,OAAmB,EAAEC,GAAgB,EAAe;IAC3D,OAAOA,GAAG,GACN,IAAI,CAAChB,MAAM,CAACkB,QAAQ,CAAC,IAAAD,8BAAI,EAACF,OAAO,CAAC,EAAE,IAAAE,8BAAI,EAACD,GAAG,CAAC,CAAC,GAC9C,IAAI,CAAChB,MAAM,CAACkB,QAAQ,CAAC,IAAAD,8BAAI,EAACF,OAAO,CAAC,CAAC;EACzC;EAEA,MAAMI,MAAMA,CACVC,SAAqB,EACrBL,OAAmB,EACnBC,GAAgB,EACE;IAClB,OAAOA,GAAG,GACN,IAAI,CAAChB,MAAM,CAACmB,MAAM,CAAC,IAAAF,8BAAI,EAACG,SAAS,CAAC,EAAE,IAAAH,8BAAI,EAACF,OAAO,CAAC,EAAE,IAAAE,8BAAI,EAACD,GAAG,CAAC,CAAC,GAC7D,IAAI,CAAChB,MAAM,CAACmB,MAAM,CAAC,IAAAF,8BAAI,EAACG,SAAS,CAAC,EAAE,IAAAH,8BAAI,EAACF,OAAO,CAAC,CAAC;EACxD;EAEAM,UAAUA,CACRD,SAAqB,EACrBL,OAAmB,EACnBC,GAAgB,EACP;IACT,OAAOA,GAAG,GACN,IAAI,CAAChB,MAAM,CAACqB,UAAU,CAAC,IAAAJ,8BAAI,EAACG,SAAS,CAAC,EAAE,IAAAH,8BAAI,EAACF,OAAO,CAAC,EAAE,IAAAE,8BAAI,EAACD,GAAG,CAAC,CAAC,GACjE,IAAI,CAAChB,MAAM,CAACqB,UAAU,CAAC,IAAAJ,8BAAI,EAACG,SAAS,CAAC,EAAE,IAAAH,8BAAI,EAACF,OAAO,CAAC,CAAC;EAC5D;AACF;AAACO,OAAA,CAAA1B,EAAA,GAAAA,EAAA","ignoreList":[]}
|