react-native-quick-crypto 0.7.3 → 1.0.0-beta.2

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.
Files changed (309) hide show
  1. package/QuickCrypto.podspec +34 -0
  2. package/README.md +13 -46
  3. package/android/CMakeLists.txt +32 -64
  4. package/android/build.gradle +52 -125
  5. package/android/gradle.properties +4 -4
  6. package/android/src/main/cpp/cpp-adapter.cpp +9 -54
  7. package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
  8. package/cpp/random/HybridRandom.cpp +34 -0
  9. package/cpp/random/HybridRandom.hpp +44 -0
  10. package/cpp/utils/Utils.hpp +9 -0
  11. package/ios/QuickCryptoOnLoad.mm +19 -0
  12. package/lib/commonjs/index.js +39 -39
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/random.js +26 -12
  15. package/lib/commonjs/random.js.map +1 -1
  16. package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
  17. package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
  18. package/lib/commonjs/utils/conversion.js +22 -0
  19. package/lib/commonjs/utils/conversion.js.map +1 -0
  20. package/lib/commonjs/utils/index.js +12 -0
  21. package/lib/commonjs/utils/index.js.map +1 -0
  22. package/lib/commonjs/utils/types.js +2 -0
  23. package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
  24. package/lib/module/index.js +38 -38
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/random.js +26 -12
  27. package/lib/module/random.js.map +1 -1
  28. package/lib/module/specs/random.nitro.js +4 -0
  29. package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
  30. package/lib/module/utils/conversion.js +16 -0
  31. package/lib/module/utils/conversion.js.map +1 -0
  32. package/lib/module/utils/index.js +8 -0
  33. package/lib/module/utils/index.js.map +1 -0
  34. package/lib/module/utils/types.js +2 -0
  35. package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
  36. package/lib/tsconfig.tsbuildinfo +1 -0
  37. package/lib/typescript/index.d.ts +10 -141
  38. package/lib/typescript/index.d.ts.map +1 -1
  39. package/lib/typescript/random.d.ts +4 -5
  40. package/lib/typescript/random.d.ts.map +1 -1
  41. package/lib/typescript/specs/random.nitro.d.ts +9 -0
  42. package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
  43. package/lib/typescript/utils/conversion.d.ts +4 -0
  44. package/lib/typescript/utils/conversion.d.ts.map +1 -0
  45. package/lib/typescript/utils/index.d.ts +6 -0
  46. package/lib/typescript/utils/index.d.ts.map +1 -0
  47. package/lib/typescript/utils/types.d.ts +5 -0
  48. package/lib/typescript/utils/types.d.ts.map +1 -0
  49. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +45 -0
  50. package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +26 -0
  51. package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +57 -0
  52. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +9 -0
  53. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +25 -0
  54. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +29 -0
  55. package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +23 -0
  56. package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +62 -0
  57. package/package.json +50 -106
  58. package/src/index.ts +38 -48
  59. package/src/random.ts +51 -48
  60. package/src/specs/random.nitro.ts +14 -0
  61. package/src/utils/conversion.ts +16 -0
  62. package/src/utils/index.ts +6 -0
  63. package/src/utils/types.ts +15 -0
  64. package/LICENSE +0 -27
  65. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
  66. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
  67. package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
  68. package/cpp/Cipher/MGLCipherHostObject.h +0 -90
  69. package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
  70. package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
  71. package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
  72. package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
  73. package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
  74. package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
  75. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
  76. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
  77. package/cpp/Cipher/MGLPublicCipher.h +0 -124
  78. package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
  79. package/cpp/Cipher/MGLRsa.cpp +0 -573
  80. package/cpp/Cipher/MGLRsa.h +0 -109
  81. package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
  82. package/cpp/HMAC/MGLHmacHostObject.h +0 -39
  83. package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
  84. package/cpp/HMAC/MGLHmacInstaller.h +0 -20
  85. package/cpp/Hash/MGLHashHostObject.cpp +0 -147
  86. package/cpp/Hash/MGLHashHostObject.h +0 -53
  87. package/cpp/Hash/MGLHashInstaller.cpp +0 -44
  88. package/cpp/Hash/MGLHashInstaller.h +0 -20
  89. package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
  90. package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
  91. package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
  92. package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
  93. package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
  94. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
  95. package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
  96. package/cpp/JSIUtils/MGLTypedArray.h +0 -160
  97. package/cpp/MGLKeys.cpp +0 -1426
  98. package/cpp/MGLKeys.h +0 -203
  99. package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
  100. package/cpp/MGLQuickCryptoHostObject.h +0 -30
  101. package/cpp/Random/MGLRandomHostObject.cpp +0 -96
  102. package/cpp/Random/MGLRandomHostObject.h +0 -27
  103. package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
  104. package/cpp/Sig/MGLSignHostObjects.h +0 -128
  105. package/cpp/Sig/MGLSignInstaller.cpp +0 -24
  106. package/cpp/Sig/MGLSignInstaller.h +0 -29
  107. package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
  108. package/cpp/Sig/MGLVerifyInstaller.h +0 -22
  109. package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
  110. package/cpp/Utils/MGLDispatchQueue.h +0 -55
  111. package/cpp/Utils/MGLUtils.cpp +0 -295
  112. package/cpp/Utils/MGLUtils.h +0 -358
  113. package/cpp/Utils/base64.h +0 -320
  114. package/cpp/Utils/logs.h +0 -38
  115. package/cpp/Utils/node.h +0 -13
  116. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
  117. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
  118. package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
  119. package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
  120. package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
  121. package/cpp/webcrypto/MGLWebCrypto.h +0 -32
  122. package/cpp/webcrypto/crypto_aes.cpp +0 -516
  123. package/cpp/webcrypto/crypto_aes.h +0 -79
  124. package/cpp/webcrypto/crypto_ec.cpp +0 -424
  125. package/cpp/webcrypto/crypto_ec.h +0 -78
  126. package/cpp/webcrypto/crypto_keygen.cpp +0 -86
  127. package/cpp/webcrypto/crypto_keygen.h +0 -38
  128. package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
  129. package/ios/QuickCryptoModule.h +0 -5
  130. package/ios/QuickCryptoModule.mm +0 -42
  131. package/lib/commonjs/Cipher.js +0 -502
  132. package/lib/commonjs/Cipher.js.map +0 -1
  133. package/lib/commonjs/Hash.js +0 -99
  134. package/lib/commonjs/Hash.js.map +0 -1
  135. package/lib/commonjs/Hashnames.js +0 -87
  136. package/lib/commonjs/Hashnames.js.map +0 -1
  137. package/lib/commonjs/Hmac.js +0 -79
  138. package/lib/commonjs/Hmac.js.map +0 -1
  139. package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
  140. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
  141. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
  142. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  143. package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
  144. package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
  145. package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
  146. package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
  147. package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
  148. package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
  149. package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
  150. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
  151. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
  152. package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
  153. package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
  154. package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
  155. package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
  156. package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
  157. package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
  158. package/lib/commonjs/Utils.js +0 -608
  159. package/lib/commonjs/Utils.js.map +0 -1
  160. package/lib/commonjs/aes.js +0 -281
  161. package/lib/commonjs/aes.js.map +0 -1
  162. package/lib/commonjs/constants.js +0 -85
  163. package/lib/commonjs/constants.js.map +0 -1
  164. package/lib/commonjs/ec.js +0 -276
  165. package/lib/commonjs/ec.js.map +0 -1
  166. package/lib/commonjs/keygen.js +0 -56
  167. package/lib/commonjs/keygen.js.map +0 -1
  168. package/lib/commonjs/keys.js +0 -492
  169. package/lib/commonjs/keys.js.map +0 -1
  170. package/lib/commonjs/pbkdf2.js +0 -90
  171. package/lib/commonjs/pbkdf2.js.map +0 -1
  172. package/lib/commonjs/rsa.js +0 -248
  173. package/lib/commonjs/rsa.js.map +0 -1
  174. package/lib/commonjs/sig.js +0 -129
  175. package/lib/commonjs/sig.js.map +0 -1
  176. package/lib/commonjs/subtle.js +0 -448
  177. package/lib/commonjs/subtle.js.map +0 -1
  178. package/lib/commonjs/webcrypto.js +0 -14
  179. package/lib/commonjs/webcrypto.js.map +0 -1
  180. package/lib/module/Cipher.js +0 -491
  181. package/lib/module/Cipher.js.map +0 -1
  182. package/lib/module/Hash.js +0 -93
  183. package/lib/module/Hash.js.map +0 -1
  184. package/lib/module/Hashnames.js +0 -85
  185. package/lib/module/Hashnames.js.map +0 -1
  186. package/lib/module/Hmac.js +0 -74
  187. package/lib/module/Hmac.js.map +0 -1
  188. package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
  189. package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
  190. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -49
  191. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  192. package/lib/module/NativeQuickCrypto/aes.js +0 -4
  193. package/lib/module/NativeQuickCrypto/hash.js +0 -2
  194. package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
  195. package/lib/module/NativeQuickCrypto/hmac.js +0 -2
  196. package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
  197. package/lib/module/NativeQuickCrypto/keygen.js +0 -4
  198. package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
  199. package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
  200. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
  201. package/lib/module/NativeQuickCrypto/random.js +0 -2
  202. package/lib/module/NativeQuickCrypto/random.js.map +0 -1
  203. package/lib/module/NativeQuickCrypto/rsa.js +0 -4
  204. package/lib/module/NativeQuickCrypto/sig.js +0 -17
  205. package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
  206. package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
  207. package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
  208. package/lib/module/Utils.js +0 -539
  209. package/lib/module/Utils.js.map +0 -1
  210. package/lib/module/aes.js +0 -274
  211. package/lib/module/aes.js.map +0 -1
  212. package/lib/module/constants.js +0 -81
  213. package/lib/module/constants.js.map +0 -1
  214. package/lib/module/ec.js +0 -267
  215. package/lib/module/ec.js.map +0 -1
  216. package/lib/module/keygen.js +0 -49
  217. package/lib/module/keygen.js.map +0 -1
  218. package/lib/module/keys.js +0 -477
  219. package/lib/module/keys.js.map +0 -1
  220. package/lib/module/pbkdf2.js +0 -84
  221. package/lib/module/pbkdf2.js.map +0 -1
  222. package/lib/module/rsa.js +0 -242
  223. package/lib/module/rsa.js.map +0 -1
  224. package/lib/module/sig.js +0 -124
  225. package/lib/module/sig.js.map +0 -1
  226. package/lib/module/subtle.js +0 -443
  227. package/lib/module/subtle.js.map +0 -1
  228. package/lib/module/webcrypto.js +0 -10
  229. package/lib/module/webcrypto.js.map +0 -1
  230. package/lib/typescript/Cipher.d.ts +0 -81
  231. package/lib/typescript/Cipher.d.ts.map +0 -1
  232. package/lib/typescript/Hash.d.ts +0 -44
  233. package/lib/typescript/Hash.d.ts.map +0 -1
  234. package/lib/typescript/Hashnames.d.ts +0 -11
  235. package/lib/typescript/Hashnames.d.ts.map +0 -1
  236. package/lib/typescript/Hmac.d.ts +0 -37
  237. package/lib/typescript/Hmac.d.ts.map +0 -1
  238. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
  239. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
  240. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
  241. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
  242. package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
  243. package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
  244. package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
  245. package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
  246. package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
  247. package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
  248. package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
  249. package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
  250. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
  251. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
  252. package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
  253. package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
  254. package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
  255. package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
  256. package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
  257. package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
  258. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
  259. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
  260. package/lib/typescript/Utils.d.ts +0 -48
  261. package/lib/typescript/Utils.d.ts.map +0 -1
  262. package/lib/typescript/aes.d.ts +0 -22
  263. package/lib/typescript/aes.d.ts.map +0 -1
  264. package/lib/typescript/constants.d.ts +0 -76
  265. package/lib/typescript/constants.d.ts.map +0 -1
  266. package/lib/typescript/ec.d.ts +0 -7
  267. package/lib/typescript/ec.d.ts.map +0 -1
  268. package/lib/typescript/keygen.d.ts +0 -6
  269. package/lib/typescript/keygen.d.ts.map +0 -1
  270. package/lib/typescript/keys.d.ts +0 -206
  271. package/lib/typescript/keys.d.ts.map +0 -1
  272. package/lib/typescript/pbkdf2.d.ts +0 -12
  273. package/lib/typescript/pbkdf2.d.ts.map +0 -1
  274. package/lib/typescript/rsa.d.ts +0 -12
  275. package/lib/typescript/rsa.d.ts.map +0 -1
  276. package/lib/typescript/sig.d.ts +0 -21
  277. package/lib/typescript/sig.d.ts.map +0 -1
  278. package/lib/typescript/subtle.d.ts +0 -15
  279. package/lib/typescript/subtle.d.ts.map +0 -1
  280. package/lib/typescript/webcrypto.d.ts +0 -9
  281. package/lib/typescript/webcrypto.d.ts.map +0 -1
  282. package/react-native-quick-crypto.podspec +0 -40
  283. package/src/Cipher.ts +0 -832
  284. package/src/Hash.ts +0 -132
  285. package/src/Hashnames.ts +0 -93
  286. package/src/Hmac.ts +0 -106
  287. package/src/NativeQuickCrypto/Cipher.ts +0 -102
  288. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
  289. package/src/NativeQuickCrypto/aes.ts +0 -14
  290. package/src/NativeQuickCrypto/hash.ts +0 -10
  291. package/src/NativeQuickCrypto/hmac.ts +0 -9
  292. package/src/NativeQuickCrypto/keygen.ts +0 -7
  293. package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
  294. package/src/NativeQuickCrypto/random.ts +0 -12
  295. package/src/NativeQuickCrypto/rsa.ts +0 -12
  296. package/src/NativeQuickCrypto/sig.ts +0 -44
  297. package/src/NativeQuickCrypto/webcrypto.ts +0 -72
  298. package/src/Utils.ts +0 -777
  299. package/src/aes.ts +0 -402
  300. package/src/constants.ts +0 -79
  301. package/src/ec.ts +0 -375
  302. package/src/keygen.ts +0 -80
  303. package/src/keys.ts +0 -787
  304. package/src/pbkdf2.ts +0 -169
  305. package/src/rsa.ts +0 -370
  306. package/src/sig.ts +0 -164
  307. package/src/subtle.ts +0 -639
  308. package/src/webcrypto.ts +0 -8
  309. /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
@@ -1,90 +0,0 @@
1
- //
2
- // Created by Oscar on 07.06.22.
3
- //
4
-
5
- #ifndef MGLCipherHostObject_h
6
- #define MGLCipherHostObject_h
7
-
8
- #include <jsi/jsi.h>
9
- #include <openssl/evp.h>
10
-
11
- #include <memory>
12
- #include <string>
13
-
14
- #ifdef ANDROID
15
- #include "JSIUtils/MGLSmartHostObject.h"
16
- #else
17
- #include "MGLSmartHostObject.h"
18
- #endif
19
-
20
- namespace margelo {
21
-
22
- namespace jsi = facebook::jsi;
23
-
24
- class MGLCipherHostObject : public MGLSmartHostObject {
25
- protected:
26
- enum CipherKind { kCipher, kDecipher };
27
- enum UpdateResult { kSuccess, kErrorMessageSize, kErrorState };
28
- enum AuthTagState { kAuthTagUnknown, kAuthTagKnown, kAuthTagPassedToOpenSSL };
29
-
30
- public:
31
- // TODO(osp) Why does an empty constructor need to be here and not on
32
- // HashHostObject?
33
- explicit MGLCipherHostObject(
34
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
35
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
36
-
37
- explicit MGLCipherHostObject(
38
- MGLCipherHostObject *other,
39
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
40
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
41
-
42
- // Without iv
43
- explicit MGLCipherHostObject(
44
- const std::string &cipher_type, jsi::ArrayBuffer *cipher_key,
45
- bool isCipher, unsigned int auth_tag_len, jsi::Runtime &runtime,
46
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
47
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
48
-
49
- // With iv
50
- explicit MGLCipherHostObject(
51
- const std::string &cipher_type, jsi::ArrayBuffer *cipher_key,
52
- bool isCipher, unsigned int auth_tag_len, jsi::ArrayBuffer *iv,
53
- jsi::Runtime &runtime, std::shared_ptr<react::CallInvoker> jsCallInvoker,
54
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
55
-
56
- void commonInit(jsi::Runtime &runtime, const char *cipher_type,
57
- const EVP_CIPHER *cipher, const unsigned char *key,
58
- int key_len, const unsigned char *iv, int iv_len,
59
- unsigned int auth_tag_len);
60
-
61
- void installMethods();
62
-
63
- bool InitAuthenticated(const char *cipher_type, int iv_len,
64
- unsigned int auth_tag_len);
65
-
66
- bool CheckCCMMessageLength(int message_len);
67
-
68
- bool IsAuthenticatedMode() const;
69
-
70
- bool MaybePassAuthTagToOpenSSL();
71
-
72
- virtual ~MGLCipherHostObject();
73
-
74
- private:
75
- // TODO(osp) this is the node version, DeleteFnPtr seems to be some custom
76
- // wrapper, I guess useful for memory deallocation
77
- // DeleteFnPtr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free> ctx_;
78
- // For now I'm manually calling EVP_CIPHER_CTX_free in the implementation
79
- EVP_CIPHER_CTX *ctx_ = nullptr;
80
- bool isCipher_;
81
- bool pending_auth_failed_;
82
- char auth_tag_[EVP_GCM_TLS_TAG_LEN];
83
- AuthTagState auth_tag_state_;
84
- unsigned int auth_tag_len_;
85
- int max_message_size_;
86
- };
87
-
88
- } // namespace margelo
89
-
90
- #endif // MGLCipherHostObject_h
@@ -1,75 +0,0 @@
1
-
2
- #include "MGLCreateCipherInstaller.h"
3
-
4
- #include <memory>
5
-
6
- #include "MGLCipherHostObject.h"
7
- #ifdef ANDROID
8
- #include "JSIUtils/MGLJSIMacros.h"
9
- #else
10
- #include "MGLJSIMacros.h"
11
- #endif
12
-
13
- namespace margelo {
14
-
15
- FieldDefinition getCreateCipherFieldDefinition(
16
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
17
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
18
- return buildPair(
19
- "createCipher", JSIF([=]) {
20
- if (count < 1) {
21
- throw jsi::JSError(runtime, "Params object is required");
22
- }
23
-
24
- if (!arguments[0].isObject()) {
25
- throw jsi::JSError(runtime,
26
- "createCipher: Params needs to be an object");
27
- }
28
-
29
- auto params = arguments[0].getObject(runtime);
30
-
31
- if (!params.hasProperty(runtime, "cipher_type")) {
32
- throw jsi::JSError(runtime, "createCipher: cipher_type is required");
33
- }
34
-
35
- auto cipher_type = params.getProperty(runtime, "cipher_type")
36
- .asString(runtime)
37
- .utf8(runtime);
38
-
39
- if (!params.hasProperty(runtime, "cipher_key")) {
40
- throw jsi::JSError(runtime, "createCipher: cipher_key is required");
41
- }
42
-
43
- auto cipher_key = params.getProperty(runtime, "cipher_key")
44
- .getObject(runtime)
45
- .getArrayBuffer(runtime);
46
-
47
- if (!params.hasProperty(runtime, "auth_tag_len")) {
48
- throw jsi::JSError(runtime, "createCipher: auth_tag_len is required");
49
- }
50
-
51
- unsigned int auth_tag_len = static_cast<int>(
52
- params.getProperty(runtime, "auth_tag_len").getNumber());
53
-
54
- if (params.hasProperty(runtime, "iv") &&
55
- !params.getProperty(runtime, "iv").isNull() &&
56
- !params.getProperty(runtime, "iv")
57
- .isUndefined()) { // createCipheriv
58
- auto iv = params.getProperty(runtime, "iv")
59
- .getObject(runtime)
60
- .getArrayBuffer(runtime);
61
- auto hostObject = std::make_shared<MGLCipherHostObject>(
62
- cipher_type, &cipher_key, true, auth_tag_len, &iv, runtime,
63
- jsCallInvoker, workerQueue);
64
-
65
- return jsi::Object::createFromHostObject(runtime, hostObject);
66
- } else {
67
- auto hostObject = std::make_shared<MGLCipherHostObject>(
68
- cipher_type, &cipher_key, true, auth_tag_len, runtime,
69
- jsCallInvoker, workerQueue);
70
-
71
- return jsi::Object::createFromHostObject(runtime, hostObject);
72
- }
73
- });
74
- }
75
- } // namespace margelo
@@ -1,22 +0,0 @@
1
- #ifndef MGLCreateCipherInstaller_h
2
- #define MGLCreateCipherInstaller_h
3
-
4
- #include <jsi/jsi.h>
5
-
6
- #include <memory>
7
-
8
- #ifdef ANDROID
9
- #include "JSIUtils/MGLSmartHostObject.h"
10
- #else
11
- #include "MGLSmartHostObject.h"
12
- #endif
13
-
14
- namespace margelo {
15
- namespace jsi = facebook::jsi;
16
-
17
- FieldDefinition getCreateCipherFieldDefinition(
18
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
19
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
20
- } // namespace margelo
21
-
22
- #endif
@@ -1,77 +0,0 @@
1
- #include "MGLCreateDecipherInstaller.h"
2
-
3
- #include <memory>
4
-
5
- #include "MGLCipherHostObject.h"
6
-
7
- #ifdef ANDROID
8
- #include "JSIUtils/MGLJSIMacros.h"
9
- #else
10
- #include "MGLJSIMacros.h"
11
- #endif
12
-
13
- using namespace facebook;
14
-
15
- namespace margelo {
16
-
17
- FieldDefinition getCreateDecipherFieldDefinition(
18
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
19
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
20
- return buildPair(
21
- "createDecipher", JSIF([=]) {
22
- if (count < 1) {
23
- throw jsi::JSError(runtime, "Params object is required");
24
- }
25
-
26
- if (!arguments[0].isObject()) {
27
- throw jsi::JSError(runtime,
28
- "createCipher: Params needs to be an object");
29
- }
30
-
31
- auto params = arguments[0].getObject(runtime);
32
-
33
- if (!params.hasProperty(runtime, "cipher_type")) {
34
- throw jsi::JSError(runtime, "createCipher: cipher_type is required");
35
- }
36
-
37
- auto cipher_type = params.getProperty(runtime, "cipher_type")
38
- .asString(runtime)
39
- .utf8(runtime);
40
-
41
- if (!params.hasProperty(runtime, "cipher_key")) {
42
- throw jsi::JSError(runtime, "createCipher: cipher_key is required");
43
- }
44
-
45
- auto cipher_key = params.getProperty(runtime, "cipher_key")
46
- .getObject(runtime)
47
- .getArrayBuffer(runtime);
48
-
49
- if (!params.hasProperty(runtime, "auth_tag_len")) {
50
- throw jsi::JSError(runtime, "createCipher: auth_tag_len is required");
51
- }
52
-
53
- unsigned int auth_tag_len =
54
- (int)params.getProperty(runtime, "auth_tag_len").getNumber();
55
-
56
- if (params.hasProperty(runtime, "iv") &&
57
- !params.getProperty(runtime, "iv").isNull() &&
58
- !params.getProperty(runtime, "iv")
59
- .isUndefined()) { // createDecipheriv
60
- auto iv = params.getProperty(runtime, "iv")
61
- .getObject(runtime)
62
- .getArrayBuffer(runtime);
63
- auto hostObject = std::make_shared<MGLCipherHostObject>(
64
- cipher_type, &cipher_key, false, auth_tag_len, &iv, runtime,
65
- jsCallInvoker, workerQueue);
66
-
67
- return jsi::Object::createFromHostObject(runtime, hostObject);
68
- } else {
69
- auto hostObject = std::make_shared<MGLCipherHostObject>(
70
- cipher_type, &cipher_key, false, auth_tag_len, runtime,
71
- jsCallInvoker, workerQueue);
72
-
73
- return jsi::Object::createFromHostObject(runtime, hostObject);
74
- }
75
- });
76
- }
77
- } // namespace margelo
@@ -1,17 +0,0 @@
1
- #include <jsi/jsi.h>
2
-
3
- #include <memory>
4
-
5
- #ifdef ANDROID
6
- #include "JSIUtils/MGLSmartHostObject.h"
7
- #else
8
- #include "MGLSmartHostObject.h"
9
- #endif
10
-
11
- namespace margelo {
12
- namespace jsi = facebook::jsi;
13
-
14
- FieldDefinition getCreateDecipherFieldDefinition(
15
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
16
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
17
- } // namespace margelo
@@ -1,134 +0,0 @@
1
- //
2
- // MGLGenerateKeyPairInstaller.cpp
3
- // react-native-quick-crypto
4
- //
5
- // Created by Oscar on 24.06.22.
6
- //
7
-
8
- #include "MGLGenerateKeyPairInstaller.h"
9
-
10
- #include <iostream>
11
- #include <memory>
12
- #include <mutex>
13
- #include <string>
14
- #include <thread>
15
- #include <utility>
16
-
17
- #include "MGLRsa.h"
18
-
19
- #ifdef ANDROID
20
- #include "JSIUtils/MGLJSIMacros.h"
21
- #include "JSIUtils/MGLTypedArray.h"
22
- #include "webcrypto/crypto_ec.h"
23
- #else
24
- #include "MGLJSIMacros.h"
25
- #include "MGLTypedArray.h"
26
- #include "crypto_ec.h"
27
- #endif
28
-
29
- using namespace facebook;
30
-
31
- namespace margelo {
32
-
33
- std::mutex m;
34
-
35
- FieldDefinition getGenerateKeyPairFieldDefinition(
36
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
37
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
38
- return buildPair(
39
- "generateKeyPair", JSIF([=]) {
40
-
41
- KeyVariant variant =
42
- static_cast<KeyVariant>((int)arguments[0].asNumber());
43
- std::shared_ptr<RsaKeyPairGenConfig> rsaConfig;
44
- std::shared_ptr<EcKeyPairGenConfig> ecConfig;
45
-
46
- // switch on variant to get proper config from arguments
47
- // outside of lambda 🤮
48
- if (variant == kvRSA_SSA_PKCS1_v1_5 ||
49
- variant == kvRSA_PSS ||
50
- variant == kvRSA_OAEP
51
- ) {
52
- rsaConfig = std::make_shared<RsaKeyPairGenConfig>(
53
- prepareRsaKeyGenConfig(runtime, arguments));
54
- } else
55
- if (variant == kvEC) {
56
- ecConfig = std::make_shared<EcKeyPairGenConfig>(
57
- prepareEcKeyGenConfig(runtime, arguments));
58
- } else {
59
- throw std::runtime_error("KeyVariant not implemented"
60
- + std::to_string((int)variant));
61
- }
62
-
63
- auto promiseConstructor =
64
- runtime.global().getPropertyAsFunction(runtime, "Promise");
65
-
66
- auto promise = promiseConstructor.callAsConstructor(
67
- runtime,
68
- jsi::Function::createFromHostFunction(
69
- runtime,
70
- jsi::PropNameID::forAscii(runtime, "executor"),
71
- 4,
72
- [&jsCallInvoker, variant, rsaConfig, ecConfig](
73
- jsi::Runtime &runtime, const jsi::Value &,
74
- const jsi::Value *promiseArgs, size_t) -> jsi::Value {
75
- auto resolve =
76
- std::make_shared<jsi::Value>(runtime, promiseArgs[0]);
77
- auto reject =
78
- std::make_shared<jsi::Value>(runtime, promiseArgs[1]);
79
-
80
- std::thread t([&runtime, resolve, reject, jsCallInvoker,
81
- variant, rsaConfig, ecConfig]() {
82
- m.lock();
83
- try {
84
- jsCallInvoker->invokeAsync([&runtime, resolve,
85
- variant, rsaConfig, ecConfig]() {
86
- std::pair<jsi::Value, jsi::Value> keys;
87
-
88
- // switch on variant to get proper generateKeyPair
89
- if (variant == kvRSA_SSA_PKCS1_v1_5 ||
90
- variant == kvRSA_PSS ||
91
- variant == kvRSA_OAEP
92
- ) {
93
- keys = generateRsaKeyPair(runtime, rsaConfig);
94
- } else
95
- if (variant == kvEC) {
96
- keys = generateEcKeyPair(runtime, ecConfig);
97
- } else {
98
- throw std::runtime_error("KeyVariant not implemented"
99
- + std::to_string((int)variant));
100
- }
101
-
102
- auto res = jsi::Array::createWithElements(
103
- runtime,
104
- jsi::Value::undefined(),
105
- keys.first,
106
- keys.second);
107
- resolve->asObject(runtime).asFunction(runtime).call(
108
- runtime, std::move(res));
109
- });
110
- } catch (std::exception e) {
111
- jsCallInvoker->invokeAsync(
112
- [&runtime, reject]() {
113
- auto res = jsi::Array::createWithElements(
114
- runtime,
115
- jsi::String::createFromUtf8(
116
- runtime, "Error generating key"),
117
- jsi::Value::undefined(),
118
- jsi::Value::undefined());
119
- reject->asObject(runtime).asFunction(runtime).call(
120
- runtime, std::move(res));
121
- });
122
- }
123
- m.unlock();
124
- });
125
-
126
- t.detach();
127
-
128
- return {};
129
- }));
130
-
131
- return promise;
132
- });
133
- }
134
- } // namespace margelo
@@ -1,35 +0,0 @@
1
-
2
- //
3
- // MGLGenerateKeyPairInstaller.hpp
4
- // react-native-quick-crypto
5
- //
6
- // Created by Oscar on 22.06.22.
7
- //
8
-
9
- #ifndef MGLGenerateKeyPairInstaller_hpp
10
- #define MGLGenerateKeyPairInstaller_hpp
11
-
12
- #include <jsi/jsi.h>
13
-
14
- #include <memory>
15
-
16
- #include "MGLKeys.h"
17
-
18
- #ifdef ANDROID
19
- #include "Cipher/MGLRsa.h"
20
- #include "JSIUtils/MGLSmartHostObject.h"
21
- #include "Utils/MGLUtils.h"
22
- #else
23
- #include "MGLRsa.h"
24
- #include "MGLSmartHostObject.h"
25
- #include "MGLUtils.h"
26
- #endif
27
-
28
- namespace margelo {
29
-
30
- FieldDefinition getGenerateKeyPairFieldDefinition(
31
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
32
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
33
- } // namespace margelo
34
-
35
- #endif /* MGLGenerateKeyPairInstaller_hpp */
@@ -1,63 +0,0 @@
1
- //
2
- // MGLGenerateKeyPairInstaller.cpp
3
- // react-native-quick-crypto
4
- //
5
- // Created by Oscar on 22.06.22.
6
- //
7
-
8
- #include "MGLGenerateKeyPairSyncInstaller.h"
9
-
10
- #include <iostream>
11
- #include <memory>
12
- #include <utility>
13
-
14
- #include "MGLRsa.h"
15
-
16
- #ifdef ANDROID
17
- #include "JSIUtils/MGLJSIMacros.h"
18
- #include "JSIUtils/MGLJSIUtils.h"
19
- #include "JSIUtils/MGLTypedArray.h"
20
- #include "webcrypto/crypto_ec.h"
21
- #else
22
- #include "MGLJSIMacros.h"
23
- #include "MGLJSIUtils.h"
24
- #include "MGLTypedArray.h"
25
- #include "crypto_ec.h"
26
- #endif
27
-
28
- using namespace facebook;
29
-
30
- namespace margelo {
31
-
32
- FieldDefinition getGenerateKeyPairSyncFieldDefinition(
33
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
34
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
35
- return buildPair(
36
- "generateKeyPairSync", JSIF([=]) {
37
- std::pair<jsi::Value, jsi::Value> keys;
38
- KeyVariant variant =
39
- static_cast<KeyVariant>((int)arguments[0].asNumber());
40
-
41
- // switch on variant to get proper config/genKeyPair
42
- if (variant == kvRSA_SSA_PKCS1_v1_5 ||
43
- variant == kvRSA_PSS ||
44
- variant == kvRSA_OAEP
45
- ) {
46
- auto config = std::make_shared<RsaKeyPairGenConfig>(
47
- prepareRsaKeyGenConfig(runtime, arguments));
48
- keys = generateRsaKeyPair(runtime, config);
49
- } else
50
- if (variant == kvEC) {
51
- auto config = std::make_shared<EcKeyPairGenConfig>(
52
- prepareEcKeyGenConfig(runtime, arguments));
53
- keys = generateEcKeyPair(runtime, config);
54
- } else {
55
- throw std::runtime_error("KeyVariant not implemented: " +
56
- std::to_string((int)variant));
57
- }
58
- // keys.first = publicKey keys.second = privateKey
59
- return jsi::Array::createWithElements(
60
- runtime, jsi::Value::undefined(), keys.first, keys.second);
61
- });
62
- }
63
- } // namespace margelo
@@ -1,37 +0,0 @@
1
- //
2
- // MGLGenerateKeyPairInstaller.hpp
3
- // react-native-quick-crypto
4
- //
5
- // Created by Oscar on 22.06.22.
6
- //
7
-
8
- #ifndef MGLGenerateKeyPairSyncInstaller_hpp
9
- #define MGLGenerateKeyPairSyncInstaller_hpp
10
-
11
- #include <jsi/jsi.h>
12
-
13
- #include <memory>
14
-
15
- #ifdef ANDROID
16
- #include "Cipher/MGLRsa.h"
17
- #include "JSIUtils/MGLSmartHostObject.h"
18
- #include "Utils/MGLUtils.h"
19
- #else
20
- #include "MGLRsa.h"
21
- #include "MGLSmartHostObject.h"
22
- #include "MGLUtils.h"
23
- #endif
24
- #include "MGLKeys.h"
25
-
26
- namespace margelo {
27
-
28
- // https://nodejs.org/api/crypto.html go to generateKeyPair
29
- /// It's signature is:
30
- /// generateKeyPair(type: string, options: record, callback: (error, publicKey,
31
- /// privateKey))
32
- FieldDefinition getGenerateKeyPairSyncFieldDefinition(
33
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
34
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
35
- } // namespace margelo
36
-
37
- #endif /* MGLGenerateKeyPairInstaller_hpp */
@@ -1,124 +0,0 @@
1
- //
2
- // MGLPublicCipher.h
3
- // react-native-quick-crypto
4
- //
5
- // Created by Oscar on 17.06.22.
6
- //
7
-
8
- #ifndef MGLPublicCipher_h
9
- #define MGLPublicCipher_h
10
-
11
- #include <jsi/jsi.h>
12
- #include <openssl/evp.h>
13
-
14
- #include <optional>
15
- #include <vector>
16
-
17
- #include "MGLKeys.h"
18
- #ifdef ANDROID
19
- #include "JSIUtils/MGLJSIUtils.h"
20
- #include "JSIUtils/MGLTypedArray.h"
21
- #else
22
- #include "MGLJSIUtils.h"
23
- #include "MGLTypedArray.h"
24
- #include "logs.h"
25
- #endif
26
-
27
- namespace margelo {
28
-
29
- namespace jsi = facebook::jsi;
30
-
31
- class MGLPublicCipher {
32
- public:
33
- typedef int (*EVP_PKEY_cipher_init_t)(EVP_PKEY_CTX* ctx);
34
- typedef int (*EVP_PKEY_cipher_t)(EVP_PKEY_CTX* ctx, unsigned char* out,
35
- size_t* outlen, const unsigned char* in,
36
- size_t inlen);
37
-
38
- enum Operation { kPublic, kPrivate };
39
-
40
- template <Operation operation, EVP_PKEY_cipher_init_t EVP_PKEY_cipher_init,
41
- EVP_PKEY_cipher_t EVP_PKEY_cipher>
42
- static std::optional<jsi::Value> Cipher(jsi::Runtime& runtime,
43
- const ManagedEVPPKey& pkey,
44
- int padding, const EVP_MD* digest,
45
- const jsi::Value& oaep_label,
46
- jsi::ArrayBuffer& data);
47
- };
48
-
49
- template <MGLPublicCipher::Operation operation,
50
- MGLPublicCipher::EVP_PKEY_cipher_init_t EVP_PKEY_cipher_init,
51
- MGLPublicCipher::EVP_PKEY_cipher_t EVP_PKEY_cipher>
52
- std::optional<jsi::Value> MGLPublicCipher::Cipher(jsi::Runtime& runtime,
53
- const ManagedEVPPKey& pkey,
54
- int padding,
55
- const EVP_MD* digest,
56
- const jsi::Value& oaep_label,
57
- jsi::ArrayBuffer& data) {
58
- EVPKeyCtxPointer ctx(EVP_PKEY_CTX_new(pkey.get(), nullptr));
59
-
60
- if (!ctx) {
61
- return {};
62
- }
63
-
64
- int init_ret = EVP_PKEY_cipher_init(ctx.get());
65
- if (init_ret <= 0) {
66
- if (init_ret == -2) {
67
- throw std::runtime_error("operation is not supported by the public key algorithm");
68
- }
69
- return {};
70
- }
71
-
72
- if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), padding) <= 0) {
73
- return {};
74
- }
75
-
76
- if (digest != nullptr) {
77
- if (EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), digest) <= 0) {
78
- return {};
79
- }
80
- }
81
-
82
- if (!oaep_label.isUndefined()) {
83
- auto oaep_label_buffer =
84
- oaep_label.asObject(runtime).getArrayBuffer(runtime);
85
- // OpenSSL takes ownership of the label, so we need to create a copy.
86
- void* label = OPENSSL_memdup(oaep_label_buffer.data(runtime),
87
- oaep_label_buffer.size(runtime));
88
- if (label == nullptr) {
89
- throw jsi::JSError(runtime, "Error openSSL memdump oaep label");
90
- }
91
-
92
- if (0 >= EVP_PKEY_CTX_set0_rsa_oaep_label(
93
- ctx.get(), static_cast<unsigned char*>(label),
94
- static_cast<int>(oaep_label_buffer.size(runtime)))) {
95
- OPENSSL_free(label);
96
- return {};
97
- }
98
- }
99
-
100
- // First pass without storing to get the out_len
101
- size_t out_len = 0;
102
- if (EVP_PKEY_cipher(ctx.get(), nullptr, &out_len, data.data(runtime),
103
- data.size(runtime)) <= 0) {
104
- return {};
105
- }
106
-
107
- std::vector<unsigned char> out_vec(out_len);
108
-
109
- if (EVP_PKEY_cipher(ctx.get(), out_vec.data(), &out_len, data.data(runtime),
110
- data.size(runtime)) <= 0) {
111
- return {};
112
- }
113
-
114
- // trim unnecessary data
115
- std::vector<unsigned char> helper_vec(out_vec.data(),
116
- out_vec.data() + out_len);
117
- MGLTypedArray<MGLTypedArrayKind::Uint8Array> outBuffer(runtime, out_len);
118
- outBuffer.update(runtime, helper_vec);
119
-
120
- return outBuffer;
121
- }
122
- } // namespace margelo
123
-
124
- #endif /* MGLPublicCipher_h */