react-native-quick-crypto 0.7.2 → 1.0.0-beta.1

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 (304) hide show
  1. package/QuickCrypto.podspec +34 -0
  2. package/android/CMakeLists.txt +32 -64
  3. package/android/build.gradle +52 -125
  4. package/android/gradle.properties +3 -3
  5. package/android/src/main/cpp/cpp-adapter.cpp +9 -54
  6. package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
  7. package/ios/QuickCryptoOnLoad.mm +19 -0
  8. package/lib/commonjs/index.js +39 -39
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/package.json +1 -0
  11. package/lib/commonjs/random.js +26 -12
  12. package/lib/commonjs/random.js.map +1 -1
  13. package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
  14. package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
  15. package/lib/commonjs/utils/conversion.js +22 -0
  16. package/lib/commonjs/utils/conversion.js.map +1 -0
  17. package/lib/commonjs/utils/index.js +12 -0
  18. package/lib/commonjs/utils/index.js.map +1 -0
  19. package/lib/commonjs/utils/types.js +2 -0
  20. package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
  21. package/lib/module/index.js +40 -38
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/package.json +1 -0
  24. package/lib/module/random.js +28 -12
  25. package/lib/module/random.js.map +1 -1
  26. package/lib/module/specs/random.nitro.js +4 -0
  27. package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
  28. package/lib/module/utils/conversion.js +16 -0
  29. package/lib/module/utils/conversion.js.map +1 -0
  30. package/lib/module/utils/index.js +8 -0
  31. package/lib/module/utils/index.js.map +1 -0
  32. package/lib/module/utils/types.js +2 -0
  33. package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
  34. package/lib/tsconfig.tsbuildinfo +1 -0
  35. package/lib/typescript/index.d.ts +10 -141
  36. package/lib/typescript/index.d.ts.map +1 -1
  37. package/lib/typescript/random.d.ts +4 -5
  38. package/lib/typescript/random.d.ts.map +1 -1
  39. package/lib/typescript/specs/random.nitro.d.ts +9 -0
  40. package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
  41. package/lib/typescript/utils/conversion.d.ts +4 -0
  42. package/lib/typescript/utils/conversion.d.ts.map +1 -0
  43. package/lib/typescript/utils/index.d.ts +6 -0
  44. package/lib/typescript/utils/index.d.ts.map +1 -0
  45. package/lib/typescript/utils/types.d.ts +5 -0
  46. package/lib/typescript/utils/types.d.ts.map +1 -0
  47. package/package.json +58 -108
  48. package/src/index.ts +38 -48
  49. package/src/random.ts +51 -48
  50. package/src/specs/random.nitro.ts +14 -0
  51. package/src/utils/conversion.ts +16 -0
  52. package/src/utils/index.ts +6 -0
  53. package/src/utils/types.ts +15 -0
  54. package/LICENSE +0 -27
  55. package/README.md +0 -203
  56. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
  57. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
  58. package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
  59. package/cpp/Cipher/MGLCipherHostObject.h +0 -90
  60. package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
  61. package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
  62. package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
  63. package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
  64. package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
  65. package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
  66. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
  67. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
  68. package/cpp/Cipher/MGLPublicCipher.h +0 -120
  69. package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
  70. package/cpp/Cipher/MGLRsa.cpp +0 -573
  71. package/cpp/Cipher/MGLRsa.h +0 -109
  72. package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
  73. package/cpp/HMAC/MGLHmacHostObject.h +0 -39
  74. package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
  75. package/cpp/HMAC/MGLHmacInstaller.h +0 -20
  76. package/cpp/Hash/MGLHashHostObject.cpp +0 -147
  77. package/cpp/Hash/MGLHashHostObject.h +0 -53
  78. package/cpp/Hash/MGLHashInstaller.cpp +0 -44
  79. package/cpp/Hash/MGLHashInstaller.h +0 -20
  80. package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
  81. package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
  82. package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
  83. package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
  84. package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
  85. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
  86. package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
  87. package/cpp/JSIUtils/MGLTypedArray.h +0 -160
  88. package/cpp/MGLKeys.cpp +0 -1426
  89. package/cpp/MGLKeys.h +0 -203
  90. package/cpp/MGLQuickCryptoHostObject.cpp +0 -124
  91. package/cpp/MGLQuickCryptoHostObject.h +0 -30
  92. package/cpp/Random/MGLRandomHostObject.cpp +0 -96
  93. package/cpp/Random/MGLRandomHostObject.h +0 -27
  94. package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
  95. package/cpp/Sig/MGLSignHostObjects.h +0 -128
  96. package/cpp/Sig/MGLSignInstaller.cpp +0 -24
  97. package/cpp/Sig/MGLSignInstaller.h +0 -29
  98. package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
  99. package/cpp/Sig/MGLVerifyInstaller.h +0 -22
  100. package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
  101. package/cpp/Utils/MGLDispatchQueue.h +0 -55
  102. package/cpp/Utils/MGLUtils.cpp +0 -295
  103. package/cpp/Utils/MGLUtils.h +0 -358
  104. package/cpp/Utils/base64.h +0 -320
  105. package/cpp/Utils/logs.h +0 -38
  106. package/cpp/Utils/node.h +0 -13
  107. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
  108. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
  109. package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
  110. package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
  111. package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
  112. package/cpp/webcrypto/MGLWebCrypto.h +0 -32
  113. package/cpp/webcrypto/crypto_aes.cpp +0 -516
  114. package/cpp/webcrypto/crypto_aes.h +0 -79
  115. package/cpp/webcrypto/crypto_ec.cpp +0 -424
  116. package/cpp/webcrypto/crypto_ec.h +0 -78
  117. package/cpp/webcrypto/crypto_keygen.cpp +0 -86
  118. package/cpp/webcrypto/crypto_keygen.h +0 -38
  119. package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
  120. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  121. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  122. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcuserdata/brad.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  123. package/ios/QuickCrypto.xcodeproj/xcuserdata/brad.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  124. package/ios/QuickCryptoModule.h +0 -5
  125. package/ios/QuickCryptoModule.mm +0 -42
  126. package/lib/commonjs/Cipher.js +0 -502
  127. package/lib/commonjs/Cipher.js.map +0 -1
  128. package/lib/commonjs/Hash.js +0 -99
  129. package/lib/commonjs/Hash.js.map +0 -1
  130. package/lib/commonjs/Hashnames.js +0 -87
  131. package/lib/commonjs/Hashnames.js.map +0 -1
  132. package/lib/commonjs/Hmac.js +0 -79
  133. package/lib/commonjs/Hmac.js.map +0 -1
  134. package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
  135. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
  136. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
  137. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  138. package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
  139. package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
  140. package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
  141. package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
  142. package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
  143. package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
  144. package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
  145. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
  146. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
  147. package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
  148. package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
  149. package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
  150. package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
  151. package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
  152. package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
  153. package/lib/commonjs/Utils.js +0 -608
  154. package/lib/commonjs/Utils.js.map +0 -1
  155. package/lib/commonjs/aes.js +0 -281
  156. package/lib/commonjs/aes.js.map +0 -1
  157. package/lib/commonjs/constants.js +0 -85
  158. package/lib/commonjs/constants.js.map +0 -1
  159. package/lib/commonjs/ec.js +0 -276
  160. package/lib/commonjs/ec.js.map +0 -1
  161. package/lib/commonjs/keygen.js +0 -56
  162. package/lib/commonjs/keygen.js.map +0 -1
  163. package/lib/commonjs/keys.js +0 -492
  164. package/lib/commonjs/keys.js.map +0 -1
  165. package/lib/commonjs/pbkdf2.js +0 -90
  166. package/lib/commonjs/pbkdf2.js.map +0 -1
  167. package/lib/commonjs/rsa.js +0 -248
  168. package/lib/commonjs/rsa.js.map +0 -1
  169. package/lib/commonjs/sig.js +0 -129
  170. package/lib/commonjs/sig.js.map +0 -1
  171. package/lib/commonjs/subtle.js +0 -448
  172. package/lib/commonjs/subtle.js.map +0 -1
  173. package/lib/commonjs/webcrypto.js +0 -14
  174. package/lib/commonjs/webcrypto.js.map +0 -1
  175. package/lib/module/Cipher.js +0 -489
  176. package/lib/module/Cipher.js.map +0 -1
  177. package/lib/module/Hash.js +0 -91
  178. package/lib/module/Hash.js.map +0 -1
  179. package/lib/module/Hashnames.js +0 -83
  180. package/lib/module/Hashnames.js.map +0 -1
  181. package/lib/module/Hmac.js +0 -72
  182. package/lib/module/Hmac.js.map +0 -1
  183. package/lib/module/NativeQuickCrypto/Cipher.js +0 -24
  184. package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
  185. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -47
  186. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  187. package/lib/module/NativeQuickCrypto/aes.js +0 -2
  188. package/lib/module/NativeQuickCrypto/hash.js +0 -2
  189. package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
  190. package/lib/module/NativeQuickCrypto/hmac.js +0 -2
  191. package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
  192. package/lib/module/NativeQuickCrypto/keygen.js +0 -2
  193. package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
  194. package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
  195. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
  196. package/lib/module/NativeQuickCrypto/random.js +0 -2
  197. package/lib/module/NativeQuickCrypto/random.js.map +0 -1
  198. package/lib/module/NativeQuickCrypto/rsa.js +0 -2
  199. package/lib/module/NativeQuickCrypto/sig.js +0 -15
  200. package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
  201. package/lib/module/NativeQuickCrypto/webcrypto.js +0 -2
  202. package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
  203. package/lib/module/Utils.js +0 -537
  204. package/lib/module/Utils.js.map +0 -1
  205. package/lib/module/aes.js +0 -272
  206. package/lib/module/aes.js.map +0 -1
  207. package/lib/module/constants.js +0 -79
  208. package/lib/module/constants.js.map +0 -1
  209. package/lib/module/ec.js +0 -265
  210. package/lib/module/ec.js.map +0 -1
  211. package/lib/module/keygen.js +0 -47
  212. package/lib/module/keygen.js.map +0 -1
  213. package/lib/module/keys.js +0 -475
  214. package/lib/module/keys.js.map +0 -1
  215. package/lib/module/pbkdf2.js +0 -82
  216. package/lib/module/pbkdf2.js.map +0 -1
  217. package/lib/module/rsa.js +0 -240
  218. package/lib/module/rsa.js.map +0 -1
  219. package/lib/module/sig.js +0 -122
  220. package/lib/module/sig.js.map +0 -1
  221. package/lib/module/subtle.js +0 -441
  222. package/lib/module/subtle.js.map +0 -1
  223. package/lib/module/webcrypto.js +0 -8
  224. package/lib/module/webcrypto.js.map +0 -1
  225. package/lib/typescript/Cipher.d.ts +0 -81
  226. package/lib/typescript/Cipher.d.ts.map +0 -1
  227. package/lib/typescript/Hash.d.ts +0 -44
  228. package/lib/typescript/Hash.d.ts.map +0 -1
  229. package/lib/typescript/Hashnames.d.ts +0 -11
  230. package/lib/typescript/Hashnames.d.ts.map +0 -1
  231. package/lib/typescript/Hmac.d.ts +0 -37
  232. package/lib/typescript/Hmac.d.ts.map +0 -1
  233. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
  234. package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
  235. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
  236. package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
  237. package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
  238. package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
  239. package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
  240. package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
  241. package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
  242. package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
  243. package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
  244. package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
  245. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
  246. package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
  247. package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
  248. package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
  249. package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
  250. package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
  251. package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
  252. package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
  253. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
  254. package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
  255. package/lib/typescript/Utils.d.ts +0 -48
  256. package/lib/typescript/Utils.d.ts.map +0 -1
  257. package/lib/typescript/aes.d.ts +0 -22
  258. package/lib/typescript/aes.d.ts.map +0 -1
  259. package/lib/typescript/constants.d.ts +0 -76
  260. package/lib/typescript/constants.d.ts.map +0 -1
  261. package/lib/typescript/ec.d.ts +0 -7
  262. package/lib/typescript/ec.d.ts.map +0 -1
  263. package/lib/typescript/keygen.d.ts +0 -6
  264. package/lib/typescript/keygen.d.ts.map +0 -1
  265. package/lib/typescript/keys.d.ts +0 -206
  266. package/lib/typescript/keys.d.ts.map +0 -1
  267. package/lib/typescript/pbkdf2.d.ts +0 -12
  268. package/lib/typescript/pbkdf2.d.ts.map +0 -1
  269. package/lib/typescript/rsa.d.ts +0 -12
  270. package/lib/typescript/rsa.d.ts.map +0 -1
  271. package/lib/typescript/sig.d.ts +0 -21
  272. package/lib/typescript/sig.d.ts.map +0 -1
  273. package/lib/typescript/subtle.d.ts +0 -15
  274. package/lib/typescript/subtle.d.ts.map +0 -1
  275. package/lib/typescript/webcrypto.d.ts +0 -9
  276. package/lib/typescript/webcrypto.d.ts.map +0 -1
  277. package/react-native-quick-crypto.podspec +0 -40
  278. package/src/Cipher.ts +0 -832
  279. package/src/Hash.ts +0 -132
  280. package/src/Hashnames.ts +0 -93
  281. package/src/Hmac.ts +0 -106
  282. package/src/NativeQuickCrypto/Cipher.ts +0 -102
  283. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
  284. package/src/NativeQuickCrypto/aes.ts +0 -14
  285. package/src/NativeQuickCrypto/hash.ts +0 -10
  286. package/src/NativeQuickCrypto/hmac.ts +0 -9
  287. package/src/NativeQuickCrypto/keygen.ts +0 -7
  288. package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
  289. package/src/NativeQuickCrypto/random.ts +0 -12
  290. package/src/NativeQuickCrypto/rsa.ts +0 -12
  291. package/src/NativeQuickCrypto/sig.ts +0 -44
  292. package/src/NativeQuickCrypto/webcrypto.ts +0 -72
  293. package/src/Utils.ts +0 -777
  294. package/src/aes.ts +0 -402
  295. package/src/constants.ts +0 -79
  296. package/src/ec.ts +0 -375
  297. package/src/keygen.ts +0 -80
  298. package/src/keys.ts +0 -787
  299. package/src/pbkdf2.ts +0 -169
  300. package/src/rsa.ts +0 -370
  301. package/src/sig.ts +0 -164
  302. package/src/subtle.ts +0 -639
  303. package/src/webcrypto.ts +0 -8
  304. /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,120 +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
- if (EVP_PKEY_cipher_init(ctx.get()) <= 0) {
65
- return {};
66
- }
67
-
68
- if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), padding) <= 0) {
69
- return {};
70
- }
71
-
72
- if (digest != nullptr) {
73
- if (EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), digest) <= 0) {
74
- return {};
75
- }
76
- }
77
-
78
- if (!oaep_label.isUndefined()) {
79
- auto oaep_label_buffer =
80
- oaep_label.asObject(runtime).getArrayBuffer(runtime);
81
- // OpenSSL takes ownership of the label, so we need to create a copy.
82
- void* label = OPENSSL_memdup(oaep_label_buffer.data(runtime),
83
- oaep_label_buffer.size(runtime));
84
- if (label == nullptr) {
85
- throw jsi::JSError(runtime, "Error openSSL memdump oaep label");
86
- }
87
-
88
- if (0 >= EVP_PKEY_CTX_set0_rsa_oaep_label(
89
- ctx.get(), static_cast<unsigned char*>(label),
90
- static_cast<int>(oaep_label_buffer.size(runtime)))) {
91
- OPENSSL_free(label);
92
- return {};
93
- }
94
- }
95
-
96
- // First pass without storing to get the out_len
97
- size_t out_len = 0;
98
- if (EVP_PKEY_cipher(ctx.get(), nullptr, &out_len, data.data(runtime),
99
- data.size(runtime)) <= 0) {
100
- return {};
101
- }
102
-
103
- std::vector<unsigned char> out_vec(out_len);
104
-
105
- if (EVP_PKEY_cipher(ctx.get(), out_vec.data(), &out_len, data.data(runtime),
106
- data.size(runtime)) <= 0) {
107
- return {};
108
- }
109
-
110
- // trim unnecessary data
111
- std::vector<unsigned char> helper_vec(out_vec.data(),
112
- out_vec.data() + out_len);
113
- MGLTypedArray<MGLTypedArrayKind::Uint8Array> outBuffer(runtime, out_len);
114
- outBuffer.update(runtime, helper_vec);
115
-
116
- return outBuffer;
117
- }
118
- } // namespace margelo
119
-
120
- #endif /* MGLPublicCipher_h */