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,128 +0,0 @@
1
- #ifndef MGLSignHostObjects_h
2
- #define MGLSignHostObjects_h
3
-
4
- #include <jsi/jsi.h>
5
- #include <openssl/evp.h>
6
-
7
- #include <memory>
8
- #include <optional>
9
- #include <string>
10
- #include <utility>
11
-
12
- #include "MGLKeys.h"
13
- #ifdef ANDROID
14
- #include "JSIUtils/MGLSmartHostObject.h"
15
- #include "Utils/MGLUtils.h"
16
- #else
17
- #include "MGLSmartHostObject.h"
18
- #include "MGLUtils.h"
19
- #endif
20
-
21
- namespace margelo {
22
-
23
- namespace jsi = facebook::jsi;
24
-
25
- static const unsigned int kNoDsaSignature = static_cast<unsigned int>(-1);
26
-
27
- enum mode { kModeSign, kModeVerify };
28
-
29
- enum DSASigEnc {
30
- kSigEncDER,
31
- kSigEncP1363,
32
- };
33
-
34
- class SignBase : public MGLSmartHostObject {
35
- public:
36
- SignBase(std::shared_ptr<react::CallInvoker> jsCallInvoker,
37
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
38
-
39
- typedef enum {
40
- kSignOk,
41
- kSignUnknownDigest,
42
- kSignInit,
43
- kSignNotInitialised,
44
- kSignUpdate,
45
- kSignPrivateKey,
46
- kSignPublicKey,
47
- kSignMalformedSignature
48
- } Error;
49
-
50
- struct SignResult {
51
- Error error;
52
- std::optional<jsi::Value> signature;
53
-
54
- explicit SignResult(Error err, std::optional<jsi::Value> sig = std::nullopt)
55
- : error(err), signature(std::move(sig)) {}
56
- };
57
-
58
- void InstallMethods(mode);
59
-
60
- SignResult SignFinal(jsi::Runtime& runtime, const ManagedEVPPKey& pkey,
61
- int padding, std::optional<int>& salt_len,
62
- DSASigEnc dsa_sig_enc);
63
-
64
- Error VerifyFinal(const ManagedEVPPKey& pkey, const ByteSource& sig,
65
- int padding, std::optional<int>& saltlen,
66
- bool* verify_result);
67
-
68
- protected:
69
- EVPMDPointer mdctx_;
70
- };
71
-
72
- struct SignConfiguration final { // : public MemoryRetainer
73
- enum Mode {
74
- kSign,
75
- kVerify
76
- };
77
- enum Flags {
78
- kHasNone = 0,
79
- kHasSaltLength = 1,
80
- kHasPadding = 2
81
- };
82
-
83
- // CryptoJobMode job_mode; // all async for now
84
- Mode mode;
85
- ManagedEVPPKey key;
86
- ByteSource data;
87
- ByteSource signature;
88
- const EVP_MD* digest = nullptr;
89
- int flags = SignConfiguration::kHasNone;
90
- int padding = 0;
91
- int salt_length = 0;
92
- DSASigEnc dsa_encoding = kSigEncDER;
93
-
94
- SignConfiguration() = default;
95
-
96
- // explicit SignConfiguration(SignConfiguration&& other) noexcept;
97
-
98
- // SignConfiguration& operator=(SignConfiguration&& other) noexcept;
99
-
100
- // void MemoryInfo(MemoryTracker* tracker) const override;
101
- // SET_MEMORY_INFO_NAME(SignConfiguration)
102
- // SET_SELF_SIZE(SignConfiguration)
103
- };
104
-
105
- class SubtleSignVerify {
106
- public:
107
- SignConfiguration GetParamsFromJS(jsi::Runtime &rt, const jsi::Value *args);
108
- void DoSignVerify(jsi::Runtime &rt, const SignConfiguration &params, ByteSource &out);
109
- jsi::Value EncodeOutput(jsi::Runtime &rt,const SignConfiguration &params, ByteSource &out);
110
- };
111
-
112
- class MGLSignHostObject : public SignBase {
113
- public:
114
- explicit MGLSignHostObject(
115
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
116
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
117
- };
118
-
119
- class MGLVerifyHostObject : public SignBase {
120
- public:
121
- explicit MGLVerifyHostObject(
122
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
123
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
124
- };
125
-
126
- } // namespace margelo
127
-
128
- #endif /* MGLSignHostObjects_h */
@@ -1,24 +0,0 @@
1
- #include "MGLSignInstaller.h"
2
-
3
- #include "MGLSignHostObjects.h"
4
- #ifdef ANDROID
5
- #include "JSIUtils/MGLJSIMacros.h"
6
- #else
7
- #include "MGLJSIMacros.h"
8
- #include "logs.h"
9
- #endif
10
-
11
- namespace margelo {
12
-
13
- FieldDefinition getSignFieldDefinition(
14
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
15
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
16
- return buildPair(
17
- "createSign", JSIF([=]) {
18
- auto hostObject =
19
- std::make_shared<MGLSignHostObject>(jsCallInvoker, workerQueue);
20
- return jsi::Object::createFromHostObject(runtime, hostObject);
21
- });
22
- }
23
-
24
- } // namespace margelo
@@ -1,29 +0,0 @@
1
- //
2
- // MGLSignInstaller.hpp
3
- // DoubleConversion
4
- //
5
- // Created by Oscar on 30.06.22.
6
- //
7
-
8
- #ifndef MGLSignInstaller_h
9
- #define MGLSignInstaller_h
10
-
11
- #include <jsi/jsi.h>
12
-
13
- #include <memory>
14
-
15
- #ifdef ANDROID
16
- #include "JSIUtils/MGLSmartHostObject.h"
17
- #else
18
- #include "MGLSmartHostObject.h"
19
- #endif
20
-
21
- namespace margelo {
22
- namespace jsi = facebook::jsi;
23
-
24
- FieldDefinition getSignFieldDefinition(
25
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
26
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
27
- } // namespace margelo
28
-
29
- #endif /* MGLSignInstaller_h */
@@ -1,24 +0,0 @@
1
- #include "MGLVerifyInstaller.h"
2
-
3
- #include "MGLSignHostObjects.h"
4
- #ifdef ANDROID
5
- #include "JSIUtils/MGLJSIMacros.h"
6
- #else
7
- #include "MGLJSIMacros.h"
8
- #include "logs.h"
9
- #endif
10
-
11
- namespace margelo {
12
-
13
- FieldDefinition getVerifyFieldDefinition(
14
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
15
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
16
- return buildPair(
17
- "createVerify", JSIF([=]) {
18
- auto hostObject =
19
- std::make_shared<MGLVerifyHostObject>(jsCallInvoker, workerQueue);
20
- return jsi::Object::createFromHostObject(runtime, hostObject);
21
- });
22
- }
23
-
24
- } // namespace margelo
@@ -1,22 +0,0 @@
1
- #ifndef MGLVerifyInstaller_h
2
- #define MGLVerifyInstaller_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 getVerifyFieldDefinition(
18
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
19
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
20
- } // namespace margelo
21
-
22
- #endif /* MGLVerifyInstaller_h */
@@ -1,75 +0,0 @@
1
- //
2
- // Created by Szymon on 23/02/2022.
3
- //
4
-
5
- #include "MGLDispatchQueue.h"
6
-
7
- #include <utility>
8
-
9
- namespace margelo {
10
-
11
- namespace DispatchQueue {
12
-
13
- dispatch_queue::dispatch_queue(std::string name, size_t thread_cnt)
14
- : name_{std::move(name)}, threads_(thread_cnt) {
15
- printf("Creating dispatch queue: %s\n", name_.c_str());
16
- printf("Dispatch threads: %zu\n", thread_cnt);
17
-
18
- for (size_t i = 0; i < threads_.size(); i++) {
19
- threads_[i] = std::thread(&dispatch_queue::dispatch_thread_handler, this);
20
- }
21
- }
22
-
23
- dispatch_queue::~dispatch_queue() {
24
- printf("Destructor: Destroying dispatch threads...\n");
25
-
26
- // Signal to dispatch threads that it's time to wrap up
27
- std::unique_lock<std::mutex> lock(lock_);
28
- quit_ = true;
29
- cv_.notify_all();
30
- lock.unlock();
31
-
32
- // Wait for threads to finish before we exit
33
- for (size_t i = 0; i < threads_.size(); i++) {
34
- if (threads_[i].joinable()) {
35
- printf("Destructor: Joining thread %zu until completion\n", i);
36
- threads_[i].join();
37
- }
38
- }
39
- }
40
-
41
- void dispatch_queue::dispatch(const fp_t &op) {
42
- std::unique_lock<std::mutex> lock(lock_);
43
- q_.push(op);
44
- cv_.notify_one();
45
- }
46
-
47
- void dispatch_queue::dispatch(fp_t &&op) {
48
- std::unique_lock<std::mutex> lock(lock_);
49
- q_.push(std::move(op));
50
- cv_.notify_one();
51
- }
52
-
53
- void dispatch_queue::dispatch_thread_handler(void) {
54
- std::unique_lock<std::mutex> lock(lock_);
55
-
56
- do {
57
- // Wait until we have data or a quit signal
58
- cv_.wait(lock, [this] { return (q_.size() || quit_); });
59
-
60
- // after wait, we own the lock
61
- if (!quit_ && q_.size()) {
62
- auto op = std::move(q_.front());
63
- q_.pop();
64
-
65
- // unlock now that we're done messing with the queue
66
- lock.unlock();
67
-
68
- op();
69
-
70
- lock.lock();
71
- }
72
- } while (!quit_);
73
- }
74
- } // namespace DispatchQueue
75
- } // namespace margelo
@@ -1,55 +0,0 @@
1
- //
2
- // Created by Szymon on 23/02/2022.
3
- //
4
-
5
- #ifndef MGL_DISPATCHQUEUE_H
6
- #define MGL_DISPATCHQUEUE_H
7
-
8
- #include <condition_variable>
9
- #include <cstdint>
10
- #include <cstdio>
11
- #include <functional>
12
- #include <mutex>
13
- #include <queue>
14
- #include <string>
15
- #include <thread>
16
- #include <vector>
17
-
18
- namespace margelo {
19
-
20
- // taken from
21
- // https://github.com/embeddedartistry/embedded-resources/blob/master/examples/cpp/dispatch.cpp
22
- namespace DispatchQueue {
23
- class dispatch_queue {
24
- typedef std::function<void(void)> fp_t;
25
-
26
- public:
27
- explicit dispatch_queue(std::string name, size_t thread_cnt = 1);
28
- ~dispatch_queue();
29
-
30
- // dispatch and copy
31
- void dispatch(const fp_t &op);
32
- // dispatch and move
33
- void dispatch(fp_t &&op);
34
-
35
- // Deleted operations
36
- dispatch_queue(const dispatch_queue &rhs) = delete;
37
- dispatch_queue &operator=(const dispatch_queue &rhs) = delete;
38
- dispatch_queue(dispatch_queue &&rhs) = delete;
39
- dispatch_queue &operator=(dispatch_queue &&rhs) = delete;
40
-
41
- private:
42
- std::string name_;
43
- std::mutex lock_;
44
- std::vector<std::thread> threads_;
45
- std::queue<fp_t> q_;
46
- std::condition_variable cv_;
47
- bool quit_ = false;
48
-
49
- void dispatch_thread_handler(void);
50
- };
51
- } // namespace DispatchQueue
52
-
53
- } // namespace margelo
54
-
55
- #endif // MGL_DISPATCHQUEUE_H
@@ -1,295 +0,0 @@
1
- #include "MGLUtils.h"
2
-
3
- #include <jsi/jsi.h>
4
-
5
- #include <iostream>
6
- #include <optional>
7
- #include <string>
8
-
9
- #include "base64.h"
10
-
11
- #ifdef ANDROID
12
- #include "JSIUtils/MGLJSIMacros.h"
13
- #else
14
- #include "MGLJSIMacros.h"
15
- #endif
16
-
17
- namespace margelo {
18
-
19
- namespace jsi = facebook::jsi;
20
-
21
- ByteSource ArrayBufferToByteSource(jsi::Runtime& runtime,
22
- const jsi::ArrayBuffer& buffer) {
23
- if (buffer.size(runtime) == 0) return ByteSource();
24
- char* buf = MallocOpenSSL<char>(buffer.size(runtime));
25
- CHECK_NOT_NULL(buf);
26
- // const cast artificially removes the const qualifier, but you cannot still
27
- // modify the data in this case, this is safe because we are just memcopying
28
- // to the buffer
29
- memcpy(buf, const_cast<jsi::ArrayBuffer&>(buffer).data(runtime),
30
- buffer.size(runtime));
31
- return ByteSource::Allocated(buf, buffer.size(runtime));
32
- }
33
-
34
- ByteSource ArrayBufferToNTCByteSource(jsi::Runtime& runtime,
35
- const jsi::ArrayBuffer& buffer) {
36
- if (buffer.size(runtime) == 0) return ByteSource();
37
- char* buf = MallocOpenSSL<char>(buffer.size(runtime) + 1);
38
- CHECK_NOT_NULL(buf);
39
- buf[buffer.size(runtime)] = 0;
40
- // const cast artificially removes the const qualifier, but you cannot still
41
- // modify the data in this case, this is safe because we are just memcopying
42
- // to the buffer
43
- memcpy(buf, const_cast<jsi::ArrayBuffer&>(buffer).data(runtime),
44
- buffer.size(runtime));
45
- return ByteSource::Allocated(buf, buffer.size(runtime));
46
- }
47
-
48
- ByteSource::ByteSource(ByteSource&& other) noexcept
49
- : data_(other.data_),
50
- allocated_data_(other.allocated_data_),
51
- size_(other.size_) {
52
- other.allocated_data_ = nullptr;
53
- }
54
-
55
- ByteSource::~ByteSource() { OPENSSL_clear_free(allocated_data_, size_); }
56
-
57
- ByteSource& ByteSource::operator=(ByteSource&& other) noexcept {
58
- if (&other != this) {
59
- OPENSSL_clear_free(allocated_data_, size_);
60
- data_ = other.data_;
61
- allocated_data_ = other.allocated_data_;
62
- other.allocated_data_ = nullptr;
63
- size_ = other.size_;
64
- }
65
- return *this;
66
- }
67
-
68
- // std::unique_ptr<BackingStore> ByteSource::ReleaseToBackingStore() {
69
- // // It's ok for allocated_data_ to be nullptr but
70
- // // only if size_ is zero.
71
- // CHECK_IMPLIES(size_ > 0, allocated_data_ != nullptr);
72
- // std::unique_ptr<BackingStore> ptr = ArrayBuffer::NewBackingStore(
73
- // allocated_data_,
74
- // size(),
75
- // [](void*
76
- // data,
77
- // size_t
78
- // length,
79
- // void*
80
- // deleter_data)
81
- // {
82
- // OPENSSL_clear_free(deleter_data,
83
- // length);
84
- // },
85
- // allocated_data_);
86
- // CHECK(ptr);
87
- // allocated_data_ = nullptr;
88
- // data_ = nullptr;
89
- // size_ = 0;
90
- // return ptr;
91
- // }
92
- //
93
- // Local<ArrayBuffer> ByteSource::ToArrayBuffer(Environment* env) {
94
- // std::unique_ptr<BackingStore> store = ReleaseToBackingStore();
95
- // return ArrayBuffer::New(env->isolate(), std::move(store));
96
- // }
97
- //
98
- // MaybeLocal<Uint8Array> ByteSource::ToBuffer(Environment* env) {
99
- // Local<ArrayBuffer> ab = ToArrayBuffer(env);
100
- // return Buffer::New(env, ab, 0, ab->ByteLength());
101
- // }
102
-
103
- ByteSource ByteSource::FromBIO(const BIOPointer& bio) {
104
- // CHECK(bio);
105
- BUF_MEM* bptr;
106
- BIO_get_mem_ptr(bio.get(), &bptr);
107
- ByteSource::Builder out(bptr->length);
108
- memcpy(out.data<void>(), bptr->data, bptr->length);
109
- return std::move(out).release();
110
- }
111
-
112
- ByteSource ByteSource::FromEncodedString(jsi::Runtime &rt,
113
- const std::string key,
114
- enum encoding enc) {
115
- // memcpy & size together properly handle strings containing \0 characters
116
- std::string result = StringBytesWrite(rt, key, enc);
117
- size_t size = result.size();
118
- ByteSource::Builder out(size);
119
- memcpy(out.data<void>(), result.data(), size);
120
- return std::move(out).release(size);
121
- }
122
-
123
- ByteSource ByteSource::FromStringOrBuffer(jsi::Runtime& runtime,
124
- const jsi::Value& value) {
125
- return value.isString()
126
- ? FromString(value.asString(runtime).utf8(runtime))
127
- : FromBuffer(runtime,
128
- value.asObject(runtime).getArrayBuffer(runtime));
129
- }
130
-
131
- // ntc = null terminated copy
132
- ByteSource ByteSource::FromString(std::string str, bool ntc) {
133
- // CHECK(str->IsString());
134
- size_t size = str.size();
135
- size_t alloc_size = ntc ? size + 1 : size;
136
- ByteSource::Builder out(alloc_size);
137
- if (ntc) {
138
- strcpy(out.data<char>(), str.data());
139
- } else {
140
- strncpy(out.data<char>(), str.data(), alloc_size);
141
- }
142
-
143
- return std::move(out).release(alloc_size);
144
- }
145
-
146
- ByteSource ByteSource::FromBuffer(jsi::Runtime& runtime,
147
- const jsi::ArrayBuffer& buffer, bool ntc) {
148
- return ntc ? ArrayBufferToNTCByteSource(runtime, buffer)
149
- : ArrayBufferToByteSource(runtime, buffer);
150
- }
151
- //
152
- // ByteSource ByteSource::FromSecretKeyBytes(
153
- // Environment* env,
154
- // Local<Value> value) {
155
- // // A key can be passed as a string, buffer or KeyObject with type
156
- // 'secret'.
157
- // // If it is a string, we need to convert it to a buffer. We are not doing
158
- // that
159
- // // in JS to avoid creating an unprotected copy on the heap.
160
- // return value->IsString() || IsAnyByteSource(value) ?
161
- // ByteSource::FromStringOrBuffer(env, value) :
162
- // ByteSource::FromSymmetricKeyObjectHandle(value);
163
- // }
164
-
165
- // ByteSource ByteSource::NullTerminatedCopy(Environment* env,
166
- // Local<Value> value) {
167
- // return Buffer::HasInstance(value) ? FromBuffer(value, true)
168
- // : FromString(env, value.As<String>(), true);
169
- // }
170
-
171
- // ByteSource ByteSource::FromSymmetricKeyObjectHandle(Local<Value> handle) {
172
- // CHECK(handle->IsObject());
173
- // KeyObjectHandle* key = Unwrap<KeyObjectHandle>(handle.As<Object>());
174
- // CHECK_NOT_NULL(key);
175
- // return Foreign(key->Data()->GetSymmetricKey(),
176
- // key->Data()->GetSymmetricKeySize());
177
- // }
178
-
179
- ByteSource ByteSource::Allocated(void* data, size_t size) {
180
- return ByteSource(data, data, size);
181
- }
182
-
183
- ByteSource ByteSource::Foreign(const void* data, size_t size) {
184
- return ByteSource(data, nullptr, size);
185
- }
186
-
187
- ByteSource ByteSource::FromBN(const BIGNUM* bn, size_t size) {
188
- std::vector<uint8_t> buf(size);
189
- CHECK_EQ(BN_bn2binpad(bn, buf.data(), size), size);
190
- ByteSource::Builder out(size);
191
- memcpy(out.data<void>(), buf.data(), size);
192
- return std::move(out).release();
193
- }
194
-
195
- ByteSource GetByteSourceFromJS(jsi::Runtime &rt,
196
- const jsi::Value &value,
197
- std::string name) {
198
- if (!value.isObject() || !value.asObject(rt).isArrayBuffer(rt)) {
199
- throw jsi::JSError(rt, "arg is not an array buffer: " + name);
200
- }
201
- ByteSource data = ByteSource::FromStringOrBuffer(rt, value);
202
- if (data.size() > INT_MAX) {
203
- throw jsi::JSError(rt, "arg is too big (> int32): " + name);
204
- }
205
- return data;
206
- }
207
-
208
- std::string EncodeBignum(const BIGNUM* bn,
209
- size_t size,
210
- bool url) {
211
- if (size == 0)
212
- size = BN_num_bytes(bn);
213
- std::vector<uint8_t> buf(size);
214
- CHECK_EQ(BN_bn2binpad(bn, buf.data(), size), size);
215
- std::string data(buf.begin(), buf.end());
216
- return EncodeBase64(data, url);
217
- }
218
-
219
- // loosely based on Node src/string_bytes.cc - StringBytes::Write()
220
- std::string StringBytesWrite(jsi::Runtime &rt,
221
- const std::string val,
222
- enum encoding encoding) {
223
- std::string result;
224
-
225
- switch (encoding) {
226
- case BASE64:
227
- // fallthrough
228
- case BASE64URL:
229
- result = DecodeBase64(val);
230
- break;
231
- default:
232
- throw jsi::JSError(rt, "Encoding not supported");
233
- }
234
-
235
- return result;
236
- }
237
-
238
- std::string EncodeBase64(const std::string data, bool url) {
239
- return base64_encode(data, url);
240
- }
241
-
242
- std::string DecodeBase64(const std::string &in, bool remove_linebreaks) {
243
- return base64_decode(in, remove_linebreaks);
244
- }
245
-
246
- MUST_USE_RESULT CSPRNGResult CSPRNG(void* buffer, size_t length) {
247
- unsigned char* buf = static_cast<unsigned char*>(buffer);
248
- do {
249
- if (1 == RAND_status()) {
250
- #if OPENSSL_VERSION_MAJOR >= 3
251
- if (1 == RAND_bytes_ex(nullptr, buf, length, 0)) return {true};
252
- #else
253
- while (length > INT_MAX && 1 == RAND_bytes(buf, INT_MAX)) {
254
- buf += INT_MAX;
255
- length -= INT_MAX;
256
- }
257
- if (length <= INT_MAX && 1 == RAND_bytes(buf, static_cast<int>(length)))
258
- return {true};
259
- #endif
260
- }
261
- #if OPENSSL_VERSION_MAJOR >= 3
262
- const auto code = ERR_peek_last_error();
263
- // A misconfigured OpenSSL 3 installation may report 1 from RAND_poll()
264
- // and RAND_status() but fail in RAND_bytes() if it cannot look up
265
- // a matching algorithm for the CSPRNG.
266
- if (ERR_GET_LIB(code) == ERR_LIB_RAND) {
267
- const auto reason = ERR_GET_REASON(code);
268
- if (reason == RAND_R_ERROR_INSTANTIATING_DRBG ||
269
- reason == RAND_R_UNABLE_TO_FETCH_DRBG ||
270
- reason == RAND_R_UNABLE_TO_CREATE_DRBG) {
271
- return {false};
272
- }
273
- }
274
- #endif
275
- } while (1 == RAND_poll());
276
-
277
- return {false};
278
- }
279
-
280
- bool SetRsaOaepLabel(const EVPKeyCtxPointer& ctx, const ByteSource& label) {
281
- if (label.size() != 0) {
282
- // OpenSSL takes ownership of the label, so we need to create a copy.
283
- void* label_copy = OPENSSL_memdup(label.data(), label.size());
284
- CHECK_NOT_NULL(label_copy);
285
- int ret = EVP_PKEY_CTX_set0_rsa_oaep_label(
286
- ctx.get(), static_cast<unsigned char*>(label_copy), label.size());
287
- if (ret <= 0) {
288
- OPENSSL_free(label_copy);
289
- return false;
290
- }
291
- }
292
- return true;
293
- }
294
-
295
- } // namespace margelo