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,109 +0,0 @@
1
- //
2
- // MGLRsa.hpp
3
- // react-native-quick-crypto
4
- //
5
- // Created by Oscar on 22.06.22.
6
- //
7
-
8
- #ifndef MGLRsa_hpp
9
- #define MGLRsa_hpp
10
-
11
- #include <jsi/jsi.h>
12
-
13
- #include <memory>
14
- #include <optional>
15
- #include <utility>
16
-
17
- #include "MGLKeys.h"
18
- #ifdef ANDROID
19
- #include "Utils/MGLUtils.h"
20
- #else
21
- #include "MGLUtils.h"
22
- #endif
23
-
24
- namespace margelo {
25
-
26
- namespace jsi = facebook::jsi;
27
-
28
- // TODO: keep in in sync with JS side (src/rsa.ts)
29
- enum RSAKeyVariant {
30
- kKeyVariantRSA_SSA_PKCS1_v1_5,
31
- kKeyVariantRSA_PSS,
32
- kKeyVariantRSA_OAEP
33
- };
34
-
35
- // On node there is a complete madness of structs/classes that encapsulate and
36
- // initialize the data in a generic manner this is to be later be used to
37
- // generate the keys in a thread-safe manner (I think) I'm however too dumb and
38
- // after ~4hrs I have given up on trying to replicate/extract the important
39
- // parts For now I'm storing a single config param, a generic abstraction is
40
- // necessary for more schemes. this struct is just a very simplified version
41
- // meant to carry information around
42
- struct RsaKeyPairGenConfig {
43
- PublicKeyEncodingConfig public_key_encoding;
44
- PrivateKeyEncodingConfig private_key_encoding;
45
- ManagedEVPPKey key;
46
-
47
- KeyVariant variant;
48
- unsigned int modulus_bits;
49
- unsigned int exponent;
50
-
51
- // The following options are used for RSA-PSS. If any of them are set, a
52
- // RSASSA-PSS-params sequence will be added to the key.
53
- const EVP_MD* md = nullptr;
54
- const EVP_MD* mgf1_md = nullptr;
55
- int saltlen = -1;
56
- };
57
-
58
- RsaKeyPairGenConfig prepareRsaKeyGenConfig(jsi::Runtime& runtime,
59
- const jsi::Value* arguments);
60
-
61
- std::pair<jsi::Value, jsi::Value> generateRsaKeyPair(
62
- jsi::Runtime& runtime, std::shared_ptr<RsaKeyPairGenConfig> config);
63
-
64
- jsi::Value ExportJWKRsaKey(jsi::Runtime &rt,
65
- std::shared_ptr<KeyObjectData> key,
66
- jsi::Object &target);
67
-
68
- std::shared_ptr<KeyObjectData> ImportJWKRsaKey(jsi::Runtime &rt,
69
- jsi::Object &jwk);
70
-
71
- jsi::Value GetRsaKeyDetail(jsi::Runtime &rt,
72
- std::shared_ptr<KeyObjectData> key);
73
-
74
- struct RsaKeyExportConfig final {
75
- WebCryptoKeyFormat format;
76
- std::shared_ptr<KeyObjectData> key_;
77
- KeyVariant variant;
78
- };
79
-
80
- class RsaKeyExport {
81
- public:
82
- bool GetParamsFromJS(jsi::Runtime &rt, const jsi::Value *args);
83
- WebCryptoKeyExportStatus DoExport(ByteSource* out);
84
- private:
85
- RsaKeyExportConfig params_;
86
- };
87
-
88
- struct RSACipherConfig final {
89
- WebCryptoCipherMode mode;
90
- std::shared_ptr<KeyObjectData> key;
91
- ByteSource data;
92
- RSAKeyVariant variant;
93
- ByteSource label;
94
- int padding = 0;
95
- const EVP_MD* digest = nullptr;
96
-
97
- RSACipherConfig() = default;
98
- };
99
-
100
- class RSACipher {
101
- public:
102
- RSACipher() {}
103
- RSACipherConfig GetParamsFromJS(jsi::Runtime &rt, const jsi::Value *args);
104
- WebCryptoCipherStatus DoCipher(const RSACipherConfig &params, ByteSource *out);
105
- };
106
-
107
- } // namespace margelo
108
-
109
- #endif /* MGLRsa_hpp */
@@ -1,95 +0,0 @@
1
- // Copyright 2022 Margelo
2
-
3
- #ifdef ANDROID
4
- #include "MGLHmacHostObject.h"
5
-
6
- #include "JSIUtils/MGLTypedArray.h"
7
- #else
8
- #include "MGLHmacHostObject.h"
9
- #include "MGLTypedArray.h"
10
- #endif
11
-
12
- #include <jsi/jsi.h>
13
- #include <openssl/hmac.h>
14
-
15
- #include <memory>
16
- #include <string>
17
- #include <vector>
18
-
19
- #define OUT
20
-
21
- namespace margelo {
22
-
23
- using namespace facebook;
24
-
25
- const EVP_MD *parseHashAlgorithm(const std::string &hashAlgorithm) {
26
- if (hashAlgorithm == "sha1") {
27
- return EVP_sha1();
28
- }
29
- if (hashAlgorithm == "sha256") {
30
- return EVP_sha256();
31
- }
32
- if (hashAlgorithm == "sha512") {
33
- return EVP_sha512();
34
- }
35
- const EVP_MD *res = EVP_get_digestbyname(hashAlgorithm.c_str());
36
- if (res != nullptr) {
37
- return res;
38
- }
39
- throw std::runtime_error("Invalid Hash Algorithm!");
40
- }
41
-
42
- MGLHmacHostObject::MGLHmacHostObject(
43
- const std::string &hashAlgorithm, jsi::Runtime &runtime,
44
- jsi::ArrayBuffer &key, std::shared_ptr<react::CallInvoker> jsCallInvoker,
45
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
46
- : MGLSmartHostObject(jsCallInvoker, workerQueue) {
47
- this->context = HMAC_CTX_new();
48
- if (key.size(runtime) == 0) {
49
- HMAC_Init_ex(this->context, "", 0, parseHashAlgorithm(hashAlgorithm),
50
- nullptr);
51
- } else {
52
- HMAC_Init_ex(this->context, key.data(runtime),
53
- static_cast<int>(key.size(runtime)),
54
- parseHashAlgorithm(hashAlgorithm), nullptr);
55
- }
56
-
57
- this->fields.push_back(HOST_LAMBDA("update", {
58
- if (!arguments[0].isObject() ||
59
- !arguments[0].getObject(runtime).isArrayBuffer(runtime)) {
60
- throw jsi::JSError(
61
- runtime,
62
- "MGLHmacHostObject::update: First argument ('message') "
63
- "has to be of type ArrayBuffer!");
64
- }
65
-
66
- auto message = arguments[0].getObject(runtime).getArrayBuffer(runtime);
67
-
68
- HMAC_Update(this->context, message.data(runtime), message.size(runtime));
69
-
70
- return jsi::Value::undefined();
71
- }));
72
-
73
- this->fields.push_back(HOST_LAMBDA("digest", {
74
- auto size = HMAC_size(this->context);
75
-
76
- unsigned char *OUT md = new unsigned char[size];
77
- unsigned int OUT length;
78
-
79
- HMAC_Final(this->context, md, &length);
80
-
81
- MGLTypedArray<MGLTypedArrayKind::Uint8Array> MGLtypedArray(runtime, length);
82
- std::vector<unsigned char> vec(md, md + length);
83
- MGLtypedArray.update(runtime, vec);
84
-
85
- return MGLtypedArray;
86
- }));
87
- }
88
-
89
- MGLHmacHostObject::~MGLHmacHostObject() {
90
- if (this->context != nullptr) {
91
- HMAC_CTX_free(this->context);
92
- }
93
- }
94
-
95
- } // namespace margelo
@@ -1,39 +0,0 @@
1
- //
2
- // HmacHostObject.h
3
- //
4
- // Created by Marc Rousavy on 22.02.22.
5
- //
6
-
7
- #ifndef MGLHmacHostObject_h
8
- #define MGLHmacHostObject_h
9
-
10
- #include <jsi/jsi.h>
11
- #include <openssl/hmac.h>
12
-
13
- #include <memory>
14
- #include <string>
15
-
16
- #ifdef ANDROID
17
- #include "JSIUtils/MGLSmartHostObject.h"
18
- #else
19
- #include "MGLSmartHostObject.h"
20
- #endif
21
-
22
- namespace margelo {
23
-
24
- using namespace facebook;
25
-
26
- class MGLHmacHostObject : public MGLSmartHostObject {
27
- public:
28
- explicit MGLHmacHostObject(
29
- const std::string &hashAlgorithm, jsi::Runtime &runtime,
30
- jsi::ArrayBuffer &key, std::shared_ptr<react::CallInvoker> jsCallInvoker,
31
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
32
- virtual ~MGLHmacHostObject();
33
-
34
- private:
35
- HMAC_CTX *context;
36
- };
37
- } // namespace margelo
38
-
39
- #endif /* MGLHmacHostObject_h */
@@ -1,43 +0,0 @@
1
- //
2
- // HMAC-JSI-Installer.m
3
- // PinkPanda
4
- //
5
- // Created by Marc Rousavy on 31.10.21.
6
- //
7
-
8
- #include "MGLHmacInstaller.h"
9
-
10
- #include <openssl/hmac.h>
11
-
12
- #ifdef ANDROID
13
- #include "JSIUtils/MGLJSIMacros.h"
14
- #include "MGLHmacHostObject.h"
15
- #else
16
- #include "MGLHmacHostObject.h"
17
- #include "MGLJSIMacros.h"
18
- #endif
19
-
20
- using namespace facebook;
21
-
22
- namespace margelo {
23
-
24
- FieldDefinition getHmacFieldDefinition(
25
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
26
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
27
- // createHmac(hashAlgorithm: 'sha1' | 'sha256' | 'sha512',
28
- // key: string)
29
- return HOST_LAMBDA("createHmac", {
30
- if (count != 2) {
31
- throw jsi::JSError(runtime,
32
- "createHmac(..) expects exactly 2 arguments!");
33
- }
34
-
35
- auto hashAlgorithm = arguments[0].asString(runtime).utf8(runtime);
36
- auto key = arguments[1].getObject(runtime).getArrayBuffer(runtime);
37
-
38
- auto hostObject = std::make_shared<MGLHmacHostObject>(
39
- hashAlgorithm, runtime, key, jsCallInvoker, workerQueue);
40
- return jsi::Object::createFromHostObject(runtime, hostObject);
41
- });
42
- }
43
- } // namespace margelo
@@ -1,20 +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
- /// It's signature is:
15
- /// createHmac(hashAlgorithm: 'sha1' | 'sha256' | 'sha512',
16
- /// key: string): HMAC
17
- FieldDefinition getHmacFieldDefinition(
18
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
19
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
20
- } // namespace margelo
@@ -1,147 +0,0 @@
1
- // Copyright 2022 Margelo
2
-
3
- #include "MGLHashHostObject.h"
4
-
5
- #ifdef ANDROID
6
- #include "JSIUtils/MGLTypedArray.h"
7
- #else
8
- #include "MGLTypedArray.h"
9
- #endif
10
-
11
- #include <jsi/jsi.h>
12
- #include <openssl/err.h>
13
-
14
- #include <memory>
15
- #include <string>
16
- #include <vector>
17
-
18
- #define OUT
19
-
20
- namespace margelo {
21
-
22
- using namespace facebook;
23
- namespace jsi = facebook::jsi;
24
-
25
- const EVP_MD *parseHashAlgorithmForHashObject(
26
- const std::string &hashAlgorithm) {
27
- const EVP_MD *res = EVP_get_digestbyname(hashAlgorithm.c_str());
28
- if (res != nullptr) {
29
- return res;
30
- }
31
- throw std::runtime_error("Invalid Hash Algorithm!");
32
- }
33
-
34
- MGLHashHostObject::MGLHashHostObject(
35
- MGLHashHostObject *other, std::shared_ptr<react::CallInvoker> jsCallInvoker,
36
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
37
- : MGLSmartHostObject(jsCallInvoker, workerQueue) {
38
- const EVP_MD *md = EVP_MD_CTX_md(other->mdctx_);
39
- this->mdctx_ = EVP_MD_CTX_new();
40
- EVP_MD_CTX_copy(this->mdctx_, other->mdctx_);
41
- md_len_ = EVP_MD_size(md);
42
-
43
- installMethods();
44
- }
45
-
46
- MGLHashHostObject::MGLHashHostObject(
47
- const std::string hashAlgorithm, unsigned int md_len,
48
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
49
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
50
- : MGLSmartHostObject(jsCallInvoker, workerQueue) {
51
- const EVP_MD *md = parseHashAlgorithmForHashObject(hashAlgorithm);
52
- mdctx_ = EVP_MD_CTX_new();
53
- if (!mdctx_ || EVP_DigestInit_ex(mdctx_, md, nullptr) <= 0) {
54
- EVP_MD_CTX_reset(mdctx_);
55
- return;
56
- }
57
- md_len_ = EVP_MD_size(md);
58
- if (md_len != -1) {
59
- md_len_ = md_len;
60
- }
61
-
62
- installMethods();
63
- }
64
-
65
- void MGLHashHostObject::installMethods() {
66
- this->fields.push_back(HOST_LAMBDA("update", {
67
- if (!arguments[0].isObject() ||
68
- !arguments[0].getObject(runtime).isArrayBuffer(runtime)) {
69
- throw jsi::JSError(runtime,
70
- "HashHostObject::update: First argument ('message') "
71
- "has to be of type ArrayBuffer!");
72
- }
73
- auto messageBuffer =
74
- arguments[0].getObject(runtime).getArrayBuffer(runtime);
75
-
76
- const unsigned char *data =
77
- reinterpret_cast<const unsigned char *>(messageBuffer.data(runtime));
78
- int size = messageBuffer.size(runtime);
79
-
80
- EVP_DigestUpdate(mdctx_, data, size);
81
-
82
- return jsi::Value::undefined();
83
- }));
84
-
85
- this->fields.push_back(buildPair(
86
- "copy", JSIF([this]) {
87
- int md_len = -1;
88
- if (!arguments[0].isUndefined()) {
89
- md_len = static_cast<int>(arguments[0].asNumber());
90
- }
91
- std::shared_ptr<MGLHashHostObject> copy =
92
- std::make_shared<MGLHashHostObject>(
93
- this, this->weakJsCallInvoker.lock(), this->dispatchQueue);
94
- if (md_len != -1) {
95
- copy->md_len_ = md_len;
96
- }
97
- return jsi::Object::createFromHostObject(runtime, copy);
98
- }));
99
-
100
- this->fields.push_back(buildPair(
101
- "digest", JSIF([this]) {
102
- unsigned int len = md_len_;
103
-
104
- if (digest_ == nullptr && len > 0) {
105
- // Some hash algorithms such as SHA3 do not support calling
106
- // EVP_DigestFinal_ex more than once, however, Hash._flush
107
- // and Hash.digest can both be used to retrieve the digest,
108
- // so we need to cache it.
109
- // See https://github.com/nodejs/node/issues/28245.
110
-
111
- char *md_value = new char[len];
112
-
113
- size_t default_len = EVP_MD_CTX_size(mdctx_);
114
- int ret;
115
- if (len == default_len) {
116
- ret = EVP_DigestFinal_ex(
117
- mdctx_, reinterpret_cast<unsigned char *>(md_value), &len);
118
- } else {
119
- ret = EVP_DigestFinalXOF(
120
- mdctx_, reinterpret_cast<unsigned char *>(md_value), len);
121
- }
122
-
123
- if (ret != 1) {
124
- throw jsi::JSError(
125
- runtime, "openSSL error:" + std::to_string(ERR_get_error()));
126
- }
127
-
128
- digest_ = md_value;
129
- }
130
-
131
- MGLTypedArray<MGLTypedArrayKind::Uint8Array> typedArray(runtime, len);
132
- std::vector<unsigned char> vec(digest_, digest_ + len);
133
- typedArray.update(runtime, vec);
134
- return typedArray;
135
- }));
136
- }
137
-
138
- MGLHashHostObject::~MGLHashHostObject() {
139
- if (this->mdctx_ != nullptr) {
140
- EVP_MD_CTX_free(this->mdctx_);
141
- }
142
- if (digest_ != nullptr) {
143
- delete[] digest_;
144
- }
145
- }
146
-
147
- } // namespace margelo
@@ -1,53 +0,0 @@
1
- // Copyright 2022 Margelo
2
- // HashHostObject.h
3
- //
4
- //
5
-
6
- #ifndef HashHostObject_h
7
- #define HashHostObject_h
8
-
9
- #include <jsi/jsi.h>
10
- #include <openssl/dsa.h>
11
- #include <openssl/ec.h>
12
- #include <openssl/err.h>
13
- #include <openssl/evp.h>
14
- #include <openssl/kdf.h>
15
- #include <openssl/rsa.h>
16
- #include <openssl/ssl.h>
17
-
18
- #include <memory>
19
- #include <string>
20
-
21
- #ifdef ANDROID
22
- #include "JSIUtils/MGLSmartHostObject.h"
23
- #else
24
- #include "MGLSmartHostObject.h"
25
- #endif
26
-
27
- namespace margelo {
28
-
29
- using namespace facebook;
30
-
31
- class MGLHashHostObject : public MGLSmartHostObject {
32
- public:
33
- explicit MGLHashHostObject(
34
- std::string hashAlgorithm, unsigned int md_len,
35
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
36
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
37
-
38
- explicit MGLHashHostObject(
39
- MGLHashHostObject *other,
40
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
41
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
42
- void installMethods();
43
-
44
- virtual ~MGLHashHostObject();
45
-
46
- private:
47
- EVP_MD_CTX *mdctx_ = nullptr;
48
- unsigned int md_len_ = 0;
49
- char *digest_ = nullptr;
50
- };
51
- } // namespace margelo
52
-
53
- #endif /* MGLHashHostObject_h */
@@ -1,44 +0,0 @@
1
- //
2
- // Hash-JSI-Installer.m
3
- // PinkPanda
4
- //
5
- // Created by Marc Rousavy on 31.10.21.
6
- //
7
-
8
- #include "MGLHashInstaller.h"
9
-
10
- #include <memory>
11
-
12
- #ifdef ANDROID
13
- #include "JSIUtils/MGLJSIMacros.h"
14
- #else
15
- #include "MGLJSIMacros.h"
16
- #endif
17
-
18
- #include "MGLHashHostObject.h"
19
-
20
- using namespace facebook;
21
-
22
- namespace margelo {
23
-
24
- FieldDefinition getHashFieldDefinition(
25
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
26
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
27
- // createHash(hashAlgorithm: 'sha1' | 'sha256' | 'sha512')
28
- return HOST_LAMBDA("createHash", {
29
- if (count != 1 && count != 2) {
30
- throw jsi::JSError(runtime, "createHash(..) expects 1-2 arguments!");
31
- }
32
-
33
- auto hashAlgorithm = arguments[0].asString(runtime).utf8(runtime);
34
- int md_len = -1;
35
- if (!arguments[1].isUndefined()) {
36
- md_len = (int)arguments[1].asNumber();
37
- }
38
-
39
- auto hostObject = std::make_shared<MGLHashHostObject>(
40
- hashAlgorithm, md_len, jsCallInvoker, workerQueue);
41
- return jsi::Object::createFromHostObject(runtime, hostObject);
42
- });
43
- }
44
- } // namespace margelo
@@ -1,20 +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
- /// It's signature is:
15
- /// createHmac(hashAlgorithm: 'sha1' | 'sha256' | 'sha512',
16
- /// key: string): HMAC
17
- FieldDefinition getHashFieldDefinition(
18
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
19
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
20
- } // namespace margelo
@@ -1,110 +0,0 @@
1
- #ifndef MGL_JSIMACROS_H
2
- #define MGL_JSIMACROS_H
3
-
4
- #include <utility>
5
-
6
- // Windows 8+ does not like abort() in Release mode
7
- #ifdef _WIN32
8
- #define ABORT_NO_BACKTRACE() _exit(134)
9
- #else
10
- #define ABORT_NO_BACKTRACE() abort()
11
- #endif
12
-
13
- struct AssertionInfo {
14
- const char *file_line; // filename:line
15
- const char *message;
16
- const char *function;
17
- };
18
-
19
- inline void Abort() {
20
- // DumpBacktrace(stderr);
21
- fflush(stderr);
22
- ABORT_NO_BACKTRACE();
23
- }
24
-
25
- inline void Assert(const AssertionInfo &info) {
26
- // std::string name = GetHumanReadableProcessName();
27
-
28
- fprintf(stderr, "%s:%s%s Assertion `%s' failed.\n", info.file_line,
29
- info.function, *info.function ? ":" : "", info.message);
30
- fflush(stderr);
31
-
32
- Abort();
33
- }
34
-
35
- #define HOSTFN(name, basecount) \
36
- jsi::Function::createFromHostFunction( \
37
- rt, \
38
- jsi::PropNameID::forAscii(rt, name), \
39
- basecount, \
40
- [=](jsi::Runtime &rt, \
41
- const jsi::Value &thisValue, \
42
- const jsi::Value *args, \
43
- size_t count) -> jsi::Value
44
-
45
- #define HOST_LAMBDA(name, body) HOST_LAMBDA_CAP(name, [=], body)
46
-
47
- #define HOST_LAMBDA_CAP(name, capture, body) \
48
- std::make_pair( \
49
- name, capture(jsi::Runtime &runtime) { \
50
- const auto func = \
51
- capture(jsi::Runtime & runtime, const jsi::Value &thisValue, \
52
- const jsi::Value *arguments, size_t count) \
53
- ->jsi::Value body; \
54
- auto propNameID = jsi::PropNameID::forAscii(runtime, name); \
55
- return jsi::Function::createFromHostFunction(runtime, propNameID, 0, \
56
- func); \
57
- })
58
-
59
- #define JSI_VALUE(name, body) JSI_VALUE_CAP(name, [=], body)
60
-
61
- #define JSI_VALUE_CAP(name, capture, body) \
62
- std::make_pair(name, capture(jsi::Runtime &runtime) body)
63
-
64
- #define JSIF(capture) \
65
- capture(jsi::Runtime &runtime, const jsi::Value &thisValue, \
66
- const jsi::Value *arguments, size_t count) \
67
- ->jsi::Value
68
-
69
- // Macros stolen from Node
70
- #define ABORT() node::Abort()
71
-
72
- #define ERROR_AND_ABORT(expr) \
73
- do { \
74
- /* Make sure that this struct does not end up in inline code, but */ \
75
- /* rather in a read-only data section when modifying this code. */ \
76
- static const AssertionInfo args = {__FILE__ ":" STRINGIFY(__LINE__), \
77
- #expr, PRETTY_FUNCTION_NAME}; \
78
- Assert(args); \
79
- } while (0)
80
- #ifdef __GNUC__
81
- #define LIKELY(expr) __builtin_expect(!!(expr), 1)
82
- #define UNLIKELY(expr) __builtin_expect(!!(expr), 0)
83
- #define PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__
84
- #else
85
- #define LIKELY(expr) expr
86
- #define UNLIKELY(expr) expr
87
- #define PRETTY_FUNCTION_NAME ""
88
- #endif
89
-
90
- #define STRINGIFY_(x) #x
91
- #define STRINGIFY(x) STRINGIFY_(x)
92
-
93
- #define CHECK(expr) \
94
- do { \
95
- if (UNLIKELY(!(expr))) { \
96
- ERROR_AND_ABORT(expr); \
97
- } \
98
- } while (0)
99
-
100
- #define CHECK_EQ(a, b) CHECK((a) == (b))
101
- #define CHECK_GE(a, b) CHECK((a) >= (b))
102
- #define CHECK_GT(a, b) CHECK((a) > (b))
103
- #define CHECK_LE(a, b) CHECK((a) <= (b))
104
- #define CHECK_LT(a, b) CHECK((a) < (b))
105
- #define CHECK_NE(a, b) CHECK((a) != (b))
106
- #define CHECK_NULL(val) CHECK((val) == nullptr)
107
- #define CHECK_NOT_NULL(val) CHECK((val) != nullptr)
108
- #define CHECK_IMPLIES(a, b) CHECK(!(a) || (b))
109
-
110
- #endif // MGL_JSIMACROS_H