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
package/cpp/MGLKeys.h DELETED
@@ -1,203 +0,0 @@
1
- //
2
- // MGLCipherKeys.h
3
- // react-native-quick-crypto
4
- //
5
- // Created by Oscar on 20.06.22.
6
- //
7
-
8
- #ifndef MGLCipherKeys_h
9
- #define MGLCipherKeys_h
10
-
11
- #include <jsi/jsi.h>
12
- #include <openssl/evp.h>
13
-
14
- #include <memory>
15
- #include <optional>
16
- #include <string>
17
-
18
- #ifdef ANDROID
19
- #include "Utils/MGLUtils.h"
20
- #include "JSIUtils/MGLSmartHostObject.h"
21
- #else
22
- #include "MGLUtils.h"
23
- #include "MGLSmartHostObject.h"
24
- #endif
25
-
26
- // This file should roughly match https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.cc
27
-
28
- namespace margelo {
29
-
30
- namespace jsi = facebook::jsi;
31
-
32
- enum PKEncodingType {
33
- // RSAPublicKey / RSAPrivateKey according to PKCS#1.
34
- kKeyEncodingPKCS1,
35
- // PrivateKeyInfo or EncryptedPrivateKeyInfo according to PKCS#8.
36
- kKeyEncodingPKCS8,
37
- // SubjectPublicKeyInfo according to X.509.
38
- kKeyEncodingSPKI,
39
- // ECPrivateKey according to SEC1.
40
- kKeyEncodingSEC1
41
- };
42
-
43
- enum PKFormatType { kKeyFormatDER, kKeyFormatPEM, kKeyFormatJWK };
44
-
45
- enum KeyType { kKeyTypeSecret, kKeyTypePublic, kKeyTypePrivate };
46
-
47
- enum KeyEncodingContext {
48
- kKeyContextInput,
49
- kKeyContextExport,
50
- kKeyContextGenerate
51
- };
52
-
53
- enum class ParseKeyResult {
54
- kParseKeyOk,
55
- kParseKeyNotRecognized,
56
- kParseKeyNeedPassphrase,
57
- kParseKeyFailed
58
- };
59
-
60
- enum class WebCryptoKeyExportStatus {
61
- OK,
62
- INVALID_KEY_TYPE,
63
- FAILED
64
- };
65
-
66
- struct AsymmetricKeyEncodingConfig {
67
- bool output_key_object_ = false;
68
- PKFormatType format_ = kKeyFormatDER;
69
- std::optional<PKEncodingType> type_ = std::nullopt;
70
- };
71
-
72
- using PublicKeyEncodingConfig = AsymmetricKeyEncodingConfig;
73
-
74
- struct PrivateKeyEncodingConfig : public AsymmetricKeyEncodingConfig {
75
- const EVP_CIPHER *cipher_;
76
- // The ByteSource alone is not enough to distinguish between "no passphrase"
77
- // and a zero-length passphrase (which can be a null pointer), therefore, we
78
- // use a NonCopyableMaybe.
79
- NonCopyableMaybe<ByteSource> passphrase_;
80
- };
81
-
82
- // Here node uses extends MemoryRetainer no clue what that is, something with
83
- // Snapshots stripped it for our implementation but if something doesn't work,
84
- // you know why
85
- class ManagedEVPPKey {
86
- public:
87
- ManagedEVPPKey() {}
88
- explicit ManagedEVPPKey(EVPKeyPointer &&pkey);
89
- ManagedEVPPKey(const ManagedEVPPKey &that);
90
- ManagedEVPPKey &operator=(const ManagedEVPPKey &that);
91
-
92
- operator bool() const;
93
- EVP_PKEY *get() const;
94
-
95
- static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
96
- jsi::Runtime &runtime, const jsi::Value *arguments, unsigned int *offset,
97
- KeyEncodingContext context);
98
-
99
- static NonCopyableMaybe<PrivateKeyEncodingConfig> GetPrivateKeyEncodingFromJs(
100
- jsi::Runtime &runtime, const jsi::Value *arguments, unsigned int *offset,
101
- KeyEncodingContext context);
102
- //
103
- static ManagedEVPPKey GetParsedKey(jsi::Runtime &runtime,
104
- EVPKeyPointer &&pkey,
105
- ParseKeyResult ret,
106
- const char *default_msg);
107
-
108
- static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(jsi::Runtime &runtime,
109
- const jsi::Value *args,
110
- unsigned int *offset);
111
-
112
- static ManagedEVPPKey GetPrivateKeyFromJs(jsi::Runtime &runtime,
113
- const jsi::Value *args,
114
- unsigned int *offset,
115
- bool allow_key_object);
116
-
117
- static jsi::Value ToEncodedPublicKey(jsi::Runtime &runtime,
118
- ManagedEVPPKey key,
119
- const PublicKeyEncodingConfig &config);
120
-
121
- static jsi::Value ToEncodedPrivateKey(jsi::Runtime &runtime,
122
- ManagedEVPPKey key,
123
- const PrivateKeyEncodingConfig &config);
124
-
125
- private:
126
- size_t size_of_private_key() const;
127
- size_t size_of_public_key() const;
128
-
129
- EVPKeyPointer pkey_;
130
- };
131
-
132
- // Analogous to the KeyObjectData class on node
133
- // https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.h#L132
134
- class KeyObjectData {
135
- public:
136
- static std::shared_ptr<KeyObjectData> CreateSecret(ByteSource key);
137
-
138
- static std::shared_ptr<KeyObjectData> CreateAsymmetric(
139
- KeyType type,
140
- const ManagedEVPPKey& pkey);
141
-
142
- KeyType GetKeyType() const;
143
-
144
- // These functions allow unprotected access to the raw key material and should
145
- // only be used to implement cryptographic operations requiring the key.
146
- ManagedEVPPKey GetAsymmetricKey() const;
147
- std::string GetSymmetricKey() const;
148
- size_t GetSymmetricKeySize() const;
149
-
150
- private:
151
- explicit KeyObjectData(ByteSource symmetric_key);
152
-
153
- KeyObjectData(
154
- KeyType type,
155
- const ManagedEVPPKey& pkey);
156
-
157
- const KeyType key_type_;
158
- const ByteSource symmetric_key_;
159
- const size_t symmetric_key_len_;
160
- const ManagedEVPPKey asymmetric_key_;
161
- };
162
-
163
- // Analogous to the KeyObjectHandle class in node
164
- // https://github.com/nodejs/node/blob/main/src/crypto/crypto_keys.h#L164
165
- class JSI_EXPORT KeyObjectHandle: public jsi::HostObject {
166
- public:
167
- KeyObjectHandle() {}
168
- jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
169
- const std::shared_ptr<KeyObjectData>& Data();
170
-
171
- static std::shared_ptr<KeyObjectHandle> Create(std::shared_ptr<KeyObjectData> data);
172
-
173
- protected:
174
- jsi::Value Export(jsi::Runtime &rt);
175
- jsi::Value ExportJWK(jsi::Runtime &rt);
176
- jsi::Value ExportPublicKey(
177
- jsi::Runtime& rt,
178
- const PublicKeyEncodingConfig& config) const;
179
- jsi::Value ExportPrivateKey(
180
- jsi::Runtime& rt,
181
- const PrivateKeyEncodingConfig& config) const;
182
- jsi::Value ExportSecretKey(jsi::Runtime& rt) const;
183
- jsi::Value GetKeyDetail(jsi::Runtime &rt);
184
- jsi::Value GetAsymmetricKeyType(jsi::Runtime &rt) const;
185
- jsi::Value Init(jsi::Runtime &rt);
186
- jsi::Value InitECRaw(jsi::Runtime &rt);
187
- jsi::Value InitJWK(jsi::Runtime &rt);
188
-
189
- private:
190
- std::shared_ptr<KeyObjectData> data_;
191
- };
192
-
193
- WebCryptoKeyExportStatus PKEY_SPKI_Export(
194
- KeyObjectData* key_data,
195
- ByteSource* out);
196
-
197
- WebCryptoKeyExportStatus PKEY_PKCS8_Export(
198
- KeyObjectData* key_data,
199
- ByteSource* out);
200
-
201
- } // namespace margelo
202
-
203
- #endif /* MGLCipherKeys_h */
@@ -1,127 +0,0 @@
1
- // Copyright 2022 Margelo
2
- #include "MGLQuickCryptoHostObject.h"
3
-
4
- #include <ReactCommon/TurboModuleUtils.h>
5
- #include <jsi/jsi.h>
6
-
7
- #include <memory>
8
- #include <string>
9
- #include <vector>
10
-
11
- #ifdef ANDROID
12
- #include "Cipher/MGLCreateCipherInstaller.h"
13
- #include "Cipher/MGLCreateDecipherInstaller.h"
14
- #include "Cipher/MGLGenerateKeyPairInstaller.h"
15
- #include "Cipher/MGLGenerateKeyPairSyncInstaller.h"
16
- #include "Cipher/MGLPublicCipher.h"
17
- #include "Cipher/MGLPublicCipherInstaller.h"
18
- #include "HMAC/MGLHmacInstaller.h"
19
- #include "Hash/MGLHashInstaller.h"
20
- #include "Random/MGLRandomHostObject.h"
21
- #include "Sig/MGLSignInstaller.h"
22
- #include "Sig/MGLVerifyInstaller.h"
23
- #include "fastpbkdf2/MGLPbkdf2HostObject.h"
24
- #include "webcrypto/MGLWebCrypto.h"
25
- #else
26
- #include "MGLCreateCipherInstaller.h"
27
- #include "MGLCreateDecipherInstaller.h"
28
- #include "MGLGenerateKeyPairInstaller.h"
29
- #include "MGLGenerateKeyPairSyncInstaller.h"
30
- #include "MGLHashInstaller.h"
31
- #include "MGLHmacInstaller.h"
32
- #include "MGLPbkdf2HostObject.h"
33
- #include "MGLPublicCipher.h"
34
- #include "MGLPublicCipherInstaller.h"
35
- #include "MGLRandomHostObject.h"
36
- #include "MGLSignInstaller.h"
37
- #include "MGLVerifyInstaller.h"
38
- #include "MGLWebCrypto.h"
39
- #endif
40
-
41
- namespace margelo {
42
-
43
- namespace jsi = facebook::jsi;
44
-
45
- MGLQuickCryptoHostObject::MGLQuickCryptoHostObject(
46
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
47
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
48
- : MGLSmartHostObject(jsCallInvoker, workerQueue) {
49
- // HmacInstaller
50
- this->fields.push_back(getHmacFieldDefinition(jsCallInvoker, workerQueue));
51
-
52
- // HashInstaller
53
- this->fields.push_back(getHashFieldDefinition(jsCallInvoker, workerQueue));
54
-
55
- // createCipher
56
- this->fields.push_back(
57
- getCreateCipherFieldDefinition(jsCallInvoker, workerQueue));
58
-
59
- // createDecipher
60
- this->fields.push_back(
61
- getCreateDecipherFieldDefinition(jsCallInvoker, workerQueue));
62
-
63
- // publicEncrypt
64
- this->fields.push_back(
65
- getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
66
- EVP_PKEY_encrypt_init,
67
- EVP_PKEY_encrypt>(
68
- "publicEncrypt", jsCallInvoker, workerQueue));
69
-
70
- // privateDecrypt
71
- this->fields.push_back(
72
- getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
73
- EVP_PKEY_decrypt_init,
74
- EVP_PKEY_decrypt>(
75
- "privateDecrypt", jsCallInvoker, workerQueue));
76
-
77
- // privateEncrypt
78
- this->fields.push_back(
79
- getPublicCipherFieldDefinition<MGLPublicCipher::kPrivate,
80
- EVP_PKEY_sign_init,
81
- EVP_PKEY_sign>(
82
- "privateEncrypt", jsCallInvoker, workerQueue));
83
-
84
- // publicDecrypt
85
- this->fields.push_back(
86
- getPublicCipherFieldDefinition<MGLPublicCipher::kPublic,
87
- EVP_PKEY_verify_recover_init,
88
- EVP_PKEY_verify_recover>(
89
- "publicDecrypt", jsCallInvoker, workerQueue));
90
-
91
- // generateKeyPair
92
- this->fields.push_back(
93
- getGenerateKeyPairFieldDefinition(jsCallInvoker, workerQueue));
94
-
95
- // generateKeyPairSync
96
- this->fields.push_back(
97
- getGenerateKeyPairSyncFieldDefinition(jsCallInvoker, workerQueue));
98
-
99
- // Pbkdf2HostObject
100
- this->fields.push_back(JSI_VALUE("pbkdf2", {
101
- auto hostObject =
102
- std::make_shared<MGLPbkdf2HostObject>(jsCallInvoker, workerQueue);
103
- return jsi::Object::createFromHostObject(runtime, hostObject);
104
- }));
105
-
106
- // RandomHostObject
107
- this->fields.push_back(JSI_VALUE("random", {
108
- auto hostObject =
109
- std::make_shared<MGLRandomHostObject>(jsCallInvoker, workerQueue);
110
- return jsi::Object::createFromHostObject(runtime, hostObject);
111
- }));
112
-
113
- // createSign
114
- this->fields.push_back(getSignFieldDefinition(jsCallInvoker, workerQueue));
115
-
116
- // createVerify
117
- this->fields.push_back(getVerifyFieldDefinition(jsCallInvoker, workerQueue));
118
-
119
- // subtle API
120
- this->fields.push_back(JSI_VALUE("webcrypto", {
121
- auto hostObject = std::make_shared<MGLWebCryptoHostObject>(
122
- jsCallInvoker, workerQueue);
123
- return jsi::Object::createFromHostObject(runtime, hostObject);
124
- }));
125
- }
126
-
127
- } // namespace margelo
@@ -1,30 +0,0 @@
1
- // Copyright 2022 Margelo
2
- #ifndef CPP_FASTCRYPTOHOSTOBJECT_H_
3
- #define CPP_FASTCRYPTOHOSTOBJECT_H_
4
-
5
- #include <ReactCommon/CallInvoker.h>
6
- #include <jsi/jsi.h>
7
-
8
- #include <memory>
9
-
10
- #include "JSIUtils/MGLSmartHostObject.h"
11
- #include "JSIUtils/MGLTypedArray.h"
12
- #include "Utils/MGLDispatchQueue.h"
13
-
14
- namespace margelo {
15
-
16
- namespace jsi = facebook::jsi;
17
- namespace react = facebook::react;
18
-
19
- class JSI_EXPORT MGLQuickCryptoHostObject : public MGLSmartHostObject {
20
- public:
21
- explicit MGLQuickCryptoHostObject(
22
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
23
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
24
-
25
- virtual ~MGLQuickCryptoHostObject() { invalidateJsiPropNameIDCache(); }
26
- };
27
-
28
- } // namespace margelo
29
-
30
- #endif // CPP_FASTCRYPTOHOSTOBJECT_H_
@@ -1,96 +0,0 @@
1
- //
2
- // Created by Szymon on 25/02/2022.
3
- //
4
-
5
- #include "MGLRandomHostObject.h"
6
-
7
- #ifdef ANDROID
8
- #include "JSIUtils/MGLTypedArray.h"
9
- #else
10
- #include "MGLTypedArray.h"
11
- #endif
12
- #include <openssl/bn.h>
13
- #include <openssl/dsa.h>
14
- #include <openssl/ec.h>
15
- #include <openssl/err.h>
16
- #include <openssl/evp.h>
17
- #include <openssl/kdf.h>
18
- #include <openssl/rand.h>
19
- #include <openssl/rsa.h>
20
- #include <openssl/ssl.h>
21
-
22
- #include <memory>
23
- #include <utility>
24
-
25
- namespace margelo {
26
- namespace jsi = facebook::jsi;
27
- namespace react = facebook::react;
28
-
29
- MGLRandomHostObject::MGLRandomHostObject(
30
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
31
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
32
- : MGLSmartHostObject(jsCallInvoker, workerQueue) {
33
- this->fields.push_back(buildPair(
34
- "randomFill", JSIF([=]) {
35
- if (count != 3) {
36
- throw jsi::JSError(runtime,
37
- "randomFill(..) expects exactly 4 arguments!");
38
- }
39
-
40
- if(!arguments[0].isObject() || !arguments[0].asObject(runtime).isArrayBuffer(runtime)) {
41
- throw std::runtime_error("First argument it not an array buffer");
42
- }
43
-
44
- if (!arguments[0].isObject()
45
- || !arguments[0].asObject(runtime).isArrayBuffer(runtime)) {
46
- throw std::runtime_error("First argument it not an array buffer");
47
- }
48
-
49
- auto result = arguments[0].asObject(runtime).getArrayBuffer(runtime);
50
- auto *resultData = result.data(runtime);
51
- auto resultPreventGC =
52
- std::make_shared<jsi::ArrayBuffer>(std::move(result));
53
-
54
- auto offset = (int)arguments[1].asNumber();
55
- auto size = arguments[2].asNumber();
56
-
57
- return react::createPromiseAsJSIValue(
58
- runtime, [=](jsi::Runtime &runtime,
59
- std::shared_ptr<react::Promise> promise) {
60
- // TODO(Szymon) implement check prime once we have bignums
61
- this->runOnWorkerThread([=]() {
62
- if (RAND_bytes(resultData + offset, size) != 1) {
63
- this->runOnJSThread([=]() {
64
- promise->reject("Sth went wrong with RAND_bytes");
65
- });
66
- }
67
- this->runOnJSThread([=]() {
68
- promise->resolve(
69
- jsi::ArrayBuffer(std::move(*resultPreventGC)));
70
- });
71
- });
72
- });
73
- }));
74
-
75
- this->fields.push_back(buildPair(
76
- "randomFillSync", JSIF([=]) {
77
- if (count != 3) {
78
- throw jsi::JSError(runtime,
79
- "randomFillSync(..) expects exactly 4 arguments!");
80
- }
81
-
82
- auto result = arguments[0].asObject(runtime).getArrayBuffer(runtime);
83
- auto *resultData = result.data(runtime);
84
- auto offset = (int)arguments[1].asNumber();
85
- auto size = arguments[2].asNumber();
86
-
87
- if (RAND_bytes(resultData + offset, size) != 1) {
88
- throw jsi::JSError(runtime, "Sth went wrong with RAND_bytes" +
89
- std::to_string(ERR_get_error()));
90
- }
91
-
92
- return result;
93
- }));
94
- }
95
-
96
- } // namespace margelo
@@ -1,27 +0,0 @@
1
- //
2
- // Created by Szymon on 25/02/2022.
3
- //
4
-
5
- #ifndef MGL_RANDOMHOSTOBJECT_H
6
- #define MGL_RANDOMHOSTOBJECT_H
7
-
8
- #include <memory>
9
-
10
- #ifdef ANDROID
11
- #include "JSIUtils/MGLSmartHostObject.h"
12
- #else
13
- #include "MGLSmartHostObject.h"
14
- #endif
15
-
16
- namespace margelo {
17
- namespace jsi = facebook::jsi;
18
-
19
- class MGLRandomHostObject : public MGLSmartHostObject {
20
- public:
21
- MGLRandomHostObject(
22
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
23
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
24
- };
25
-
26
- } // namespace margelo
27
- #endif // MGL_RANDOMHOSTOBJECT_H