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/src/pbkdf2.ts DELETED
@@ -1,169 +0,0 @@
1
- import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
2
- import { Buffer } from '@craftzdog/react-native-buffer';
3
- import {
4
- type BinaryLike,
5
- binaryLikeToArrayBuffer,
6
- lazyDOMException,
7
- bufferLikeToArrayBuffer,
8
- normalizeHashName,
9
- HashContext,
10
- } from './Utils';
11
- import type { CryptoKey, HashAlgorithm, SubtleAlgorithm } from './keys';
12
- import { promisify } from 'util';
13
-
14
- const WRONG_PASS =
15
- 'Password must be a string, a Buffer, a typed array or a DataView';
16
- const WRONG_SALT = `Salt must be a string, a Buffer, a typed array or a DataView`;
17
-
18
- type Password = BinaryLike;
19
- type Salt = BinaryLike;
20
- type Pbkdf2Callback = (err: Error | null, derivedKey?: Buffer) => void;
21
-
22
- function sanitizeInput(input: BinaryLike, errorMsg: string): ArrayBuffer {
23
- try {
24
- return binaryLikeToArrayBuffer(input);
25
- } catch (e: any) {
26
- throw errorMsg;
27
- }
28
- }
29
-
30
- const nativePbkdf2 = NativeQuickCrypto.pbkdf2;
31
-
32
- export function pbkdf2(
33
- password: Password,
34
- salt: Salt,
35
- iterations: number,
36
- keylen: number,
37
- digest: HashAlgorithm,
38
- callback: Pbkdf2Callback
39
- ): void;
40
- export function pbkdf2(
41
- password: Password,
42
- salt: Salt,
43
- iterations: number,
44
- keylen: number,
45
- callback: Pbkdf2Callback
46
- ): void;
47
- export function pbkdf2(
48
- password: Password,
49
- salt: Salt,
50
- iterations: number,
51
- keylen: number,
52
- arg0?: unknown,
53
- arg1?: unknown
54
- ): void {
55
- let digest: HashAlgorithm = 'SHA-1';
56
- let callback: undefined | Pbkdf2Callback;
57
- if (typeof arg0 === 'string') {
58
- digest = arg0 as HashAlgorithm;
59
- if (typeof arg1 === 'function') {
60
- callback = arg1 as Pbkdf2Callback;
61
- }
62
- } else {
63
- if (typeof arg0 === 'function') {
64
- callback = arg0 as Pbkdf2Callback;
65
- }
66
- }
67
- if (callback === undefined) {
68
- throw new Error('No callback provided to pbkdf2');
69
- }
70
-
71
- const sanitizedPassword = sanitizeInput(password, WRONG_PASS);
72
- const sanitizedSalt = sanitizeInput(salt, WRONG_SALT);
73
- const normalizedDigest = normalizeHashName(digest, HashContext.Node);
74
-
75
- nativePbkdf2
76
- .pbkdf2(
77
- sanitizedPassword,
78
- sanitizedSalt,
79
- iterations,
80
- keylen,
81
- normalizedDigest
82
- )
83
- .then(
84
- (res: ArrayBuffer) => {
85
- callback!(null, Buffer.from(res));
86
- },
87
- (e: Error) => {
88
- callback!(e);
89
- }
90
- );
91
- }
92
-
93
- export function pbkdf2Sync(
94
- password: Password,
95
- salt: Salt,
96
- iterations: number,
97
- keylen: number,
98
- digest?: HashAlgorithm
99
- ): ArrayBuffer {
100
- const sanitizedPassword = sanitizeInput(password, WRONG_PASS);
101
- const sanitizedSalt = sanitizeInput(salt, WRONG_SALT);
102
-
103
- const algo = digest ? normalizeHashName(digest, HashContext.Node) : 'sha1';
104
- let result: ArrayBuffer = nativePbkdf2.pbkdf2Sync(
105
- sanitizedPassword,
106
- sanitizedSalt,
107
- iterations,
108
- keylen,
109
- algo
110
- );
111
-
112
- return Buffer.from(result);
113
- }
114
-
115
- // We need this because the typescript overload signatures in pbkdf2() above do
116
- // not play nice with promisify() below.
117
- const pbkdf2WithDigest = (
118
- password: Password,
119
- salt: Salt,
120
- iterations: number,
121
- keylen: number,
122
- digest: HashAlgorithm,
123
- callback: Pbkdf2Callback
124
- ) => pbkdf2(password, salt, iterations, keylen, digest, callback);
125
-
126
- const pbkdf2Promise = promisify(pbkdf2WithDigest);
127
- export async function pbkdf2DeriveBits(
128
- algorithm: SubtleAlgorithm,
129
- baseKey: CryptoKey,
130
- length: number
131
- ): Promise<ArrayBuffer> {
132
- const { iterations, hash, salt } = algorithm;
133
- const normalizedHash = normalizeHashName(hash);
134
- if (!normalizedHash) {
135
- throw lazyDOMException('hash cannot be blank', 'OperationError');
136
- }
137
- if (!iterations || iterations === 0) {
138
- throw lazyDOMException('iterations cannot be zero', 'OperationError');
139
- }
140
- if (!salt) {
141
- throw lazyDOMException(WRONG_SALT, 'OperationError');
142
- }
143
- const raw = baseKey.keyObject.export();
144
-
145
- if (length === 0)
146
- throw lazyDOMException('length cannot be zero', 'OperationError');
147
- if (length === null)
148
- throw lazyDOMException('length cannot be null', 'OperationError');
149
- if (length % 8) {
150
- throw lazyDOMException('length must be a multiple of 8', 'OperationError');
151
- }
152
-
153
- const sanitizedPassword = sanitizeInput(raw, WRONG_PASS);
154
- const sanitizedSalt = sanitizeInput(salt, WRONG_SALT);
155
- let result: Buffer | undefined = await pbkdf2Promise(
156
- sanitizedPassword,
157
- sanitizedSalt,
158
- iterations,
159
- length / 8,
160
- normalizedHash as HashAlgorithm
161
- );
162
- if (!result) {
163
- throw lazyDOMException(
164
- 'received bad result from pbkdf2()',
165
- 'OperationError'
166
- );
167
- }
168
- return bufferLikeToArrayBuffer(result);
169
- }
package/src/rsa.ts DELETED
@@ -1,370 +0,0 @@
1
- import { KeyVariantLookup } from './NativeQuickCrypto/Cipher';
2
- import { generateKeyPairPromise } from './Cipher';
3
- import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
4
- import type { KeyObjectHandle } from './NativeQuickCrypto/webcrypto';
5
- import {
6
- lazyDOMException,
7
- type BufferLike,
8
- validateKeyOps,
9
- normalizeHashName,
10
- HashContext,
11
- hasAnyNotIn,
12
- getUsagesUnion,
13
- bigIntArrayToUnsignedInt,
14
- validateMaxBufferLength,
15
- bufferLikeToArrayBuffer,
16
- } from './Utils';
17
- import {
18
- CryptoKey,
19
- PrivateKeyObject,
20
- type HashAlgorithm,
21
- type ImportFormat,
22
- type JWK,
23
- type KeyUsage,
24
- type SubtleAlgorithm,
25
- PublicKeyObject,
26
- type AnyAlgorithm,
27
- KeyType,
28
- createPublicKey,
29
- type CryptoKeyPair,
30
- KWebCryptoKeyFormat,
31
- CipherOrWrapMode,
32
- type RsaOaepParams,
33
- type DigestAlgorithm,
34
- } from './keys';
35
-
36
- // TODO: keep in in sync with C++ side (cpp/Cipher/MGLRsa.h)
37
- export enum RSAKeyVariant {
38
- RSA_SSA_PKCS1_v1_5,
39
- RSA_PSS,
40
- RSA_OAEP,
41
- }
42
-
43
- function verifyAcceptableRsaKeyUse(
44
- name: AnyAlgorithm,
45
- isPublic: boolean,
46
- usages: KeyUsage[]
47
- ): void {
48
- let checkSet;
49
- switch (name) {
50
- case 'RSA-OAEP':
51
- checkSet = isPublic ? ['encrypt', 'wrapKey'] : ['decrypt', 'unwrapKey'];
52
- break;
53
- case 'RSA-PSS':
54
- // Fall through
55
- case 'RSASSA-PKCS1-v1_5':
56
- checkSet = isPublic ? ['verify'] : ['sign'];
57
- break;
58
- default:
59
- throw lazyDOMException(
60
- 'The algorithm is not supported',
61
- 'NotSupportedError'
62
- );
63
- }
64
- if (hasAnyNotIn(usages, checkSet)) {
65
- throw lazyDOMException(
66
- `Unsupported key usage for an ${name} key`,
67
- 'SyntaxError'
68
- );
69
- }
70
- }
71
-
72
- const rsaOaepCipher = (
73
- mode: CipherOrWrapMode,
74
- key: CryptoKey,
75
- data: ArrayBuffer,
76
- { label }: RsaOaepParams
77
- ): Promise<ArrayBuffer> => {
78
- const type =
79
- mode === CipherOrWrapMode.kWebCryptoCipherEncrypt ? 'public' : 'private';
80
- if (key.type !== type) {
81
- throw lazyDOMException(
82
- 'The requested operation is not valid for the provided key',
83
- 'InvalidAccessError'
84
- );
85
- }
86
- if (label !== undefined) {
87
- validateMaxBufferLength(label, 'algorithm.label');
88
- }
89
-
90
- return NativeQuickCrypto.webcrypto.rsaCipher(
91
- mode,
92
- key.keyObject.handle,
93
- data,
94
- RSAKeyVariant.RSA_OAEP,
95
- normalizeHashName(key.algorithm.hash) as DigestAlgorithm,
96
- label !== undefined ? bufferLikeToArrayBuffer(label) : undefined
97
- );
98
- };
99
-
100
- export const rsaCipher = rsaOaepCipher;
101
-
102
- export const rsaKeyGenerate = async (
103
- algorithm: SubtleAlgorithm,
104
- extractable: boolean,
105
- keyUsages: KeyUsage[]
106
- ): Promise<CryptoKeyPair> => {
107
- const { name, modulusLength, publicExponent, hash: rawHash } = algorithm;
108
- const hash: HashAlgorithm = normalizeHashName(rawHash);
109
-
110
- // const usageSet = new SafeSet(keyUsages);
111
- const publicExponentConverted = bigIntArrayToUnsignedInt(publicExponent);
112
- if (publicExponentConverted === undefined) {
113
- throw lazyDOMException(
114
- 'The publicExponent must be equivalent to an unsigned 32-bit value',
115
- 'OperationError'
116
- );
117
- }
118
-
119
- switch (name) {
120
- case 'RSA-OAEP':
121
- if (
122
- hasAnyNotIn(keyUsages, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])
123
- ) {
124
- throw lazyDOMException(
125
- 'Unsupported key usage for a RSA key',
126
- 'SyntaxError'
127
- );
128
- }
129
- break;
130
- default:
131
- if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
132
- throw lazyDOMException(
133
- 'Unsupported key usage for a RSA key',
134
- 'SyntaxError'
135
- );
136
- }
137
- }
138
-
139
- const [err, keypair] = await generateKeyPairPromise('rsa', {
140
- modulusLength,
141
- publicExponent: publicExponentConverted,
142
- });
143
- if (err) {
144
- throw lazyDOMException(
145
- 'The operation failed for an operation-specific reason',
146
- { name: 'OperationError', cause: err }
147
- );
148
- }
149
-
150
- const keyAlgorithm = {
151
- name,
152
- modulusLength,
153
- publicExponent: publicExponentConverted,
154
- hash,
155
- };
156
-
157
- let publicUsages: KeyUsage[] = [];
158
- let privateUsages: KeyUsage[] = [];
159
- switch (name) {
160
- case 'RSA-OAEP': {
161
- publicUsages = getUsagesUnion(keyUsages, 'encrypt', 'wrapKey');
162
- privateUsages = getUsagesUnion(keyUsages, 'decrypt', 'unwrapKey');
163
- break;
164
- }
165
- default: {
166
- publicUsages = getUsagesUnion(keyUsages, 'verify');
167
- privateUsages = getUsagesUnion(keyUsages, 'sign');
168
- break;
169
- }
170
- }
171
-
172
- const pub = new PublicKeyObject(keypair?.publicKey as KeyObjectHandle);
173
- const publicKey = new CryptoKey(pub, keyAlgorithm, publicUsages, true);
174
-
175
- const priv = new PrivateKeyObject(keypair?.privateKey as KeyObjectHandle);
176
- const privateKey = new CryptoKey(
177
- priv,
178
- keyAlgorithm,
179
- privateUsages,
180
- extractable
181
- );
182
-
183
- return { publicKey, privateKey };
184
- };
185
-
186
- export const rsaExportKey = (
187
- key: CryptoKey,
188
- format: KWebCryptoKeyFormat
189
- ): ArrayBuffer => {
190
- const variant = KeyVariantLookup[key.algorithm.name];
191
- if (variant === undefined) {
192
- throw lazyDOMException(
193
- `Unrecognized algorithm name '${key.algorithm.name}'`,
194
- 'NotSupportedError'
195
- );
196
- }
197
- return NativeQuickCrypto.webcrypto.rsaExportKey(
198
- format,
199
- key.keyObject.handle,
200
- variant
201
- );
202
- };
203
-
204
- export const rsaImportKey = (
205
- format: ImportFormat,
206
- keyData: BufferLike | JWK,
207
- algorithm: SubtleAlgorithm,
208
- extractable: boolean,
209
- keyUsages: KeyUsage[]
210
- ): CryptoKey => {
211
- // const usagesSet = new SafeSet(keyUsages);
212
- let keyObject: PublicKeyObject | PrivateKeyObject;
213
- switch (format) {
214
- case 'spki': {
215
- verifyAcceptableRsaKeyUse(algorithm.name, true, keyUsages);
216
- try {
217
- keyObject = createPublicKey({
218
- key: keyData,
219
- format: 'der',
220
- type: 'spki',
221
- });
222
- } catch (err) {
223
- throw lazyDOMException('Invalid keyData', {
224
- name: 'DataError',
225
- cause: err,
226
- });
227
- }
228
- break;
229
- }
230
- // case 'pkcs8': {
231
- // verifyAcceptableRsaKeyUse(algorithm.name, false, keyUsages);
232
- // try {
233
- // keyObject = createPrivateKey({
234
- // key: keyData,
235
- // format: 'der',
236
- // type: 'pkcs8',
237
- // });
238
- // } catch (err) {
239
- // throw lazyDOMException('Invalid keyData', {
240
- // name: 'DataError',
241
- // cause: err,
242
- // });
243
- // }
244
- // break;
245
- // }
246
- case 'jwk': {
247
- const data = keyData as JWK;
248
- if (!data.kty) {
249
- throw lazyDOMException('Invalid keyData', 'DataError');
250
- }
251
- if (data.kty !== 'RSA')
252
- throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
253
-
254
- verifyAcceptableRsaKeyUse(
255
- algorithm.name,
256
- data.d === undefined,
257
- keyUsages
258
- );
259
-
260
- if (keyUsages.length > 0 && data.use !== undefined) {
261
- const checkUse = algorithm.name === 'RSA-OAEP' ? 'enc' : 'sig';
262
- if (data.use !== checkUse)
263
- throw lazyDOMException('Invalid JWK "use" Parameter', 'DataError');
264
- }
265
-
266
- validateKeyOps(data.key_ops, keyUsages);
267
-
268
- if (
269
- data.ext !== undefined &&
270
- data.ext === false &&
271
- extractable === true
272
- ) {
273
- throw lazyDOMException(
274
- 'JWK "ext" Parameter and extractable mismatch',
275
- 'DataError'
276
- );
277
- }
278
-
279
- if (data.alg !== undefined) {
280
- const hash = normalizeHashName(
281
- data.alg as HashAlgorithm,
282
- HashContext.WebCrypto
283
- );
284
- if (hash !== algorithm.hash)
285
- throw lazyDOMException(
286
- 'JWK "alg" does not match the requested algorithm',
287
- 'DataError'
288
- );
289
- }
290
-
291
- const handle = NativeQuickCrypto.webcrypto.createKeyObjectHandle();
292
- const type = handle.initJwk(data);
293
- if (type === undefined)
294
- throw lazyDOMException('Invalid JWK', 'DataError');
295
-
296
- keyObject =
297
- type === KeyType.Private
298
- ? new PrivateKeyObject(handle)
299
- : new PublicKeyObject(handle);
300
-
301
- break;
302
- }
303
- default:
304
- throw lazyDOMException(
305
- `Unable to import RSA key with format ${format}`,
306
- 'NotSupportedError'
307
- );
308
- }
309
-
310
- if (keyObject.asymmetricKeyType !== 'rsa') {
311
- throw lazyDOMException('Invalid key type', 'DataError');
312
- }
313
-
314
- const { modulusLength, publicExponent } = keyObject.handle.keyDetail();
315
-
316
- if (publicExponent === undefined) {
317
- throw lazyDOMException('publicExponent is undefined', 'DataError');
318
- }
319
-
320
- return new CryptoKey(
321
- keyObject,
322
- {
323
- name: algorithm.name,
324
- modulusLength,
325
- publicExponent: new Uint8Array(publicExponent),
326
- hash: algorithm.hash,
327
- },
328
- keyUsages,
329
- extractable
330
- );
331
- };
332
-
333
- // function rsaSignVerify(key, data, { saltLength }, signature) {
334
- // let padding;
335
- // if (key.algorithm.name === 'RSA-PSS') {
336
- // padding = RSA_PKCS1_PSS_PADDING;
337
- // // TODO(@jasnell): Validate maximum size of saltLength
338
- // // based on the key size:
339
- // // Math.ceil((keySizeInBits - 1)/8) - digestSizeInBytes - 2
340
- // validateInt32(saltLength, 'algorithm.saltLength', -2);
341
- // }
342
-
343
- // const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify;
344
- // const type = mode === kSignJobModeSign ? 'private' : 'public';
345
-
346
- // if (key.type !== type)
347
- // throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError');
348
-
349
- // return jobPromise(() => new SignJob(
350
- // kCryptoJobAsync,
351
- // signature === undefined ? kSignJobModeSign : kSignJobModeVerify,
352
- // key[kKeyObject][kHandle],
353
- // undefined,
354
- // undefined,
355
- // undefined,
356
- // data,
357
- // normalizeHashName(key.algorithm.hash.name),
358
- // saltLength,
359
- // padding,
360
- // undefined,
361
- // signature));
362
- // }
363
-
364
- // module.exports = {
365
- // rsaCipher: rsaOaepCipher,
366
- // rsaExportKey,
367
- // rsaImportKey,
368
- // rsaKeyGenerate,
369
- // rsaSignVerify,
370
- // };
package/src/sig.ts DELETED
@@ -1,164 +0,0 @@
1
- import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
2
- import type { InternalSign, InternalVerify } from './NativeQuickCrypto/sig';
3
- import Stream from 'readable-stream';
4
-
5
- // TODO(osp) same as publicCipher on node this are defined on C++ and exposed to node
6
- // Do the same here
7
- enum DSASigEnc {
8
- kSigEncDER,
9
- kSigEncP1363,
10
- }
11
-
12
- import {
13
- type BinaryLike,
14
- binaryLikeToArrayBuffer,
15
- getDefaultEncoding,
16
- } from './Utils';
17
- import {
18
- preparePrivateKey,
19
- preparePublicOrPrivateKey,
20
- type EncodingOptions,
21
- } from './keys';
22
-
23
- const createInternalSign = NativeQuickCrypto.createSign;
24
- const createInternalVerify = NativeQuickCrypto.createVerify;
25
-
26
- function getPadding(options: any) {
27
- return getIntOption('padding', options);
28
- }
29
-
30
- function getSaltLength(options: any) {
31
- return getIntOption('saltLength', options);
32
- }
33
-
34
- function getDSASignatureEncoding(options: any) {
35
- if (typeof options === 'object') {
36
- const { dsaEncoding = 'der' } = options;
37
- if (dsaEncoding === 'der') return DSASigEnc.kSigEncDER;
38
- else if (dsaEncoding === 'ieee-p1363') return DSASigEnc.kSigEncP1363;
39
- throw new Error(`options.dsaEncoding: ${dsaEncoding} not a valid encoding`);
40
- }
41
-
42
- return DSASigEnc.kSigEncDER;
43
- }
44
-
45
- function getIntOption(name: string, options: any) {
46
- const value = options[name];
47
- if (value !== undefined) {
48
- // eslint-disable-next-line no-bitwise
49
- if (value === value >> 0) {
50
- return value;
51
- }
52
- throw new Error(`options.${name}: ${value} not a valid int value`);
53
- }
54
- return undefined;
55
- }
56
-
57
- class Verify extends Stream.Writable {
58
- private internal: InternalVerify;
59
- constructor(algorithm: string, options: Stream.WritableOptions) {
60
- super(options);
61
- this.internal = createInternalVerify();
62
- this.internal.init(algorithm);
63
- }
64
-
65
- _write(chunk: BinaryLike, encoding: string, callback: () => void) {
66
- this.update(chunk, encoding);
67
- callback();
68
- }
69
-
70
- update(data: BinaryLike, encoding?: string) {
71
- encoding = encoding ?? getDefaultEncoding();
72
- data = binaryLikeToArrayBuffer(data, encoding);
73
- this.internal.update(data);
74
- return this;
75
- }
76
-
77
- verify(options: EncodingOptions, signature: BinaryLike): boolean {
78
- if (!options) {
79
- throw new Error('Crypto sign key required');
80
- }
81
-
82
- const { data, format, type, passphrase } =
83
- preparePublicOrPrivateKey(options);
84
-
85
- const rsaPadding = getPadding(options);
86
- const pssSaltLength = getSaltLength(options);
87
-
88
- // Options specific to (EC)DSA
89
- const dsaSigEnc = getDSASignatureEncoding(options);
90
-
91
- const ret = this.internal.verify(
92
- data,
93
- format,
94
- type,
95
- passphrase,
96
- binaryLikeToArrayBuffer(signature),
97
- rsaPadding,
98
- pssSaltLength,
99
- dsaSigEnc
100
- );
101
-
102
- return ret;
103
- }
104
- }
105
-
106
- class Sign extends Stream.Writable {
107
- private internal: InternalSign;
108
- constructor(algorithm: string, options: Stream.WritableOptions) {
109
- super(options);
110
- this.internal = createInternalSign();
111
- this.internal.init(algorithm);
112
- }
113
-
114
- _write(chunk: BinaryLike, encoding: string, callback: () => void) {
115
- this.update(chunk, encoding);
116
- callback();
117
- }
118
-
119
- update(data: BinaryLike, encoding?: string) {
120
- encoding = encoding ?? getDefaultEncoding();
121
- data = binaryLikeToArrayBuffer(data, encoding);
122
- this.internal.update(data);
123
- return this;
124
- }
125
-
126
- sign(options: EncodingOptions, encoding?: string) {
127
- if (!options) {
128
- throw new Error('Crypto sign key required');
129
- }
130
-
131
- const { data, format, type, passphrase } = preparePrivateKey(options);
132
-
133
- const rsaPadding = getPadding(options);
134
- const pssSaltLength = getSaltLength(options);
135
-
136
- // Options specific to (EC)DSA
137
- const dsaSigEnc = getDSASignatureEncoding(options);
138
-
139
- const ret = this.internal.sign(
140
- data,
141
- format,
142
- type,
143
- passphrase,
144
- rsaPadding,
145
- pssSaltLength,
146
- dsaSigEnc
147
- );
148
-
149
- encoding = encoding || getDefaultEncoding();
150
- if (encoding && encoding !== 'buffer') {
151
- return Buffer.from(ret).toString(encoding as any);
152
- }
153
-
154
- return Buffer.from(ret);
155
- }
156
- }
157
-
158
- export function createSign(algorithm: string, options?: any) {
159
- return new Sign(algorithm, options);
160
- }
161
-
162
- export function createVerify(algorithm: string, options?: any) {
163
- return new Verify(algorithm, options);
164
- }