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.
- package/QuickCrypto.podspec +34 -0
- package/README.md +13 -46
- package/android/CMakeLists.txt +32 -64
- package/android/build.gradle +52 -125
- package/android/gradle.properties +4 -4
- package/android/src/main/cpp/cpp-adapter.cpp +9 -54
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
- package/cpp/random/HybridRandom.cpp +34 -0
- package/cpp/random/HybridRandom.hpp +44 -0
- package/cpp/utils/Utils.hpp +9 -0
- package/ios/QuickCryptoOnLoad.mm +19 -0
- package/lib/commonjs/index.js +39 -39
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/random.js +26 -12
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/commonjs/utils/conversion.js +22 -0
- package/lib/commonjs/utils/conversion.js.map +1 -0
- package/lib/commonjs/utils/index.js +12 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/types.js +2 -0
- package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
- package/lib/module/index.js +38 -38
- package/lib/module/index.js.map +1 -1
- package/lib/module/random.js +26 -12
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/random.nitro.js +4 -0
- package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/module/utils/conversion.js +16 -0
- package/lib/module/utils/conversion.js.map +1 -0
- package/lib/module/utils/index.js +8 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/types.js +2 -0
- package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/typescript/index.d.ts +10 -141
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/random.d.ts +4 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/specs/random.nitro.d.ts +9 -0
- package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +4 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +5 -0
- package/lib/typescript/utils/types.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +45 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +26 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +57 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +9 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +25 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +62 -0
- package/package.json +50 -106
- package/src/index.ts +38 -48
- package/src/random.ts +51 -48
- package/src/specs/random.nitro.ts +14 -0
- package/src/utils/conversion.ts +16 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/types.ts +15 -0
- package/LICENSE +0 -27
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
- package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
- package/cpp/Cipher/MGLCipherHostObject.h +0 -90
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
- package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
- package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
- package/cpp/Cipher/MGLPublicCipher.h +0 -124
- package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
- package/cpp/Cipher/MGLRsa.cpp +0 -573
- package/cpp/Cipher/MGLRsa.h +0 -109
- package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
- package/cpp/HMAC/MGLHmacHostObject.h +0 -39
- package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
- package/cpp/HMAC/MGLHmacInstaller.h +0 -20
- package/cpp/Hash/MGLHashHostObject.cpp +0 -147
- package/cpp/Hash/MGLHashHostObject.h +0 -53
- package/cpp/Hash/MGLHashInstaller.cpp +0 -44
- package/cpp/Hash/MGLHashInstaller.h +0 -20
- package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
- package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
- package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
- package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
- package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
- package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
- package/cpp/JSIUtils/MGLTypedArray.h +0 -160
- package/cpp/MGLKeys.cpp +0 -1426
- package/cpp/MGLKeys.h +0 -203
- package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
- package/cpp/MGLQuickCryptoHostObject.h +0 -30
- package/cpp/Random/MGLRandomHostObject.cpp +0 -96
- package/cpp/Random/MGLRandomHostObject.h +0 -27
- package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
- package/cpp/Sig/MGLSignHostObjects.h +0 -128
- package/cpp/Sig/MGLSignInstaller.cpp +0 -24
- package/cpp/Sig/MGLSignInstaller.h +0 -29
- package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
- package/cpp/Sig/MGLVerifyInstaller.h +0 -22
- package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
- package/cpp/Utils/MGLDispatchQueue.h +0 -55
- package/cpp/Utils/MGLUtils.cpp +0 -295
- package/cpp/Utils/MGLUtils.h +0 -358
- package/cpp/Utils/base64.h +0 -320
- package/cpp/Utils/logs.h +0 -38
- package/cpp/Utils/node.h +0 -13
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
- package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
- package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
- package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
- package/cpp/webcrypto/MGLWebCrypto.h +0 -32
- package/cpp/webcrypto/crypto_aes.cpp +0 -516
- package/cpp/webcrypto/crypto_aes.h +0 -79
- package/cpp/webcrypto/crypto_ec.cpp +0 -424
- package/cpp/webcrypto/crypto_ec.h +0 -78
- package/cpp/webcrypto/crypto_keygen.cpp +0 -86
- package/cpp/webcrypto/crypto_keygen.h +0 -38
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
- package/ios/QuickCryptoModule.h +0 -5
- package/ios/QuickCryptoModule.mm +0 -42
- package/lib/commonjs/Cipher.js +0 -502
- package/lib/commonjs/Cipher.js.map +0 -1
- package/lib/commonjs/Hash.js +0 -99
- package/lib/commonjs/Hash.js.map +0 -1
- package/lib/commonjs/Hashnames.js +0 -87
- package/lib/commonjs/Hashnames.js.map +0 -1
- package/lib/commonjs/Hmac.js +0 -79
- package/lib/commonjs/Hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/commonjs/Utils.js +0 -608
- package/lib/commonjs/Utils.js.map +0 -1
- package/lib/commonjs/aes.js +0 -281
- package/lib/commonjs/aes.js.map +0 -1
- package/lib/commonjs/constants.js +0 -85
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/ec.js +0 -276
- package/lib/commonjs/ec.js.map +0 -1
- package/lib/commonjs/keygen.js +0 -56
- package/lib/commonjs/keygen.js.map +0 -1
- package/lib/commonjs/keys.js +0 -492
- package/lib/commonjs/keys.js.map +0 -1
- package/lib/commonjs/pbkdf2.js +0 -90
- package/lib/commonjs/pbkdf2.js.map +0 -1
- package/lib/commonjs/rsa.js +0 -248
- package/lib/commonjs/rsa.js.map +0 -1
- package/lib/commonjs/sig.js +0 -129
- package/lib/commonjs/sig.js.map +0 -1
- package/lib/commonjs/subtle.js +0 -448
- package/lib/commonjs/subtle.js.map +0 -1
- package/lib/commonjs/webcrypto.js +0 -14
- package/lib/commonjs/webcrypto.js.map +0 -1
- package/lib/module/Cipher.js +0 -491
- package/lib/module/Cipher.js.map +0 -1
- package/lib/module/Hash.js +0 -93
- package/lib/module/Hash.js.map +0 -1
- package/lib/module/Hashnames.js +0 -85
- package/lib/module/Hashnames.js.map +0 -1
- package/lib/module/Hmac.js +0 -74
- package/lib/module/Hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
- package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -49
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/module/NativeQuickCrypto/aes.js +0 -4
- package/lib/module/NativeQuickCrypto/hash.js +0 -2
- package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/module/NativeQuickCrypto/hmac.js +0 -2
- package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/keygen.js +0 -4
- package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/module/NativeQuickCrypto/random.js +0 -2
- package/lib/module/NativeQuickCrypto/random.js.map +0 -1
- package/lib/module/NativeQuickCrypto/rsa.js +0 -4
- package/lib/module/NativeQuickCrypto/sig.js +0 -17
- package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
- package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/module/Utils.js +0 -539
- package/lib/module/Utils.js.map +0 -1
- package/lib/module/aes.js +0 -274
- package/lib/module/aes.js.map +0 -1
- package/lib/module/constants.js +0 -81
- package/lib/module/constants.js.map +0 -1
- package/lib/module/ec.js +0 -267
- package/lib/module/ec.js.map +0 -1
- package/lib/module/keygen.js +0 -49
- package/lib/module/keygen.js.map +0 -1
- package/lib/module/keys.js +0 -477
- package/lib/module/keys.js.map +0 -1
- package/lib/module/pbkdf2.js +0 -84
- package/lib/module/pbkdf2.js.map +0 -1
- package/lib/module/rsa.js +0 -242
- package/lib/module/rsa.js.map +0 -1
- package/lib/module/sig.js +0 -124
- package/lib/module/sig.js.map +0 -1
- package/lib/module/subtle.js +0 -443
- package/lib/module/subtle.js.map +0 -1
- package/lib/module/webcrypto.js +0 -10
- package/lib/module/webcrypto.js.map +0 -1
- package/lib/typescript/Cipher.d.ts +0 -81
- package/lib/typescript/Cipher.d.ts.map +0 -1
- package/lib/typescript/Hash.d.ts +0 -44
- package/lib/typescript/Hash.d.ts.map +0 -1
- package/lib/typescript/Hashnames.d.ts +0 -11
- package/lib/typescript/Hashnames.d.ts.map +0 -1
- package/lib/typescript/Hmac.d.ts +0 -37
- package/lib/typescript/Hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
- package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
- package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
- package/lib/typescript/Utils.d.ts +0 -48
- package/lib/typescript/Utils.d.ts.map +0 -1
- package/lib/typescript/aes.d.ts +0 -22
- package/lib/typescript/aes.d.ts.map +0 -1
- package/lib/typescript/constants.d.ts +0 -76
- package/lib/typescript/constants.d.ts.map +0 -1
- package/lib/typescript/ec.d.ts +0 -7
- package/lib/typescript/ec.d.ts.map +0 -1
- package/lib/typescript/keygen.d.ts +0 -6
- package/lib/typescript/keygen.d.ts.map +0 -1
- package/lib/typescript/keys.d.ts +0 -206
- package/lib/typescript/keys.d.ts.map +0 -1
- package/lib/typescript/pbkdf2.d.ts +0 -12
- package/lib/typescript/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/rsa.d.ts +0 -12
- package/lib/typescript/rsa.d.ts.map +0 -1
- package/lib/typescript/sig.d.ts +0 -21
- package/lib/typescript/sig.d.ts.map +0 -1
- package/lib/typescript/subtle.d.ts +0 -15
- package/lib/typescript/subtle.d.ts.map +0 -1
- package/lib/typescript/webcrypto.d.ts +0 -9
- package/lib/typescript/webcrypto.d.ts.map +0 -1
- package/react-native-quick-crypto.podspec +0 -40
- package/src/Cipher.ts +0 -832
- package/src/Hash.ts +0 -132
- package/src/Hashnames.ts +0 -93
- package/src/Hmac.ts +0 -106
- package/src/NativeQuickCrypto/Cipher.ts +0 -102
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
- package/src/NativeQuickCrypto/aes.ts +0 -14
- package/src/NativeQuickCrypto/hash.ts +0 -10
- package/src/NativeQuickCrypto/hmac.ts +0 -9
- package/src/NativeQuickCrypto/keygen.ts +0 -7
- package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
- package/src/NativeQuickCrypto/random.ts +0 -12
- package/src/NativeQuickCrypto/rsa.ts +0 -12
- package/src/NativeQuickCrypto/sig.ts +0 -44
- package/src/NativeQuickCrypto/webcrypto.ts +0 -72
- package/src/Utils.ts +0 -777
- package/src/aes.ts +0 -402
- package/src/constants.ts +0 -79
- package/src/ec.ts +0 -375
- package/src/keygen.ts +0 -80
- package/src/keys.ts +0 -787
- package/src/pbkdf2.ts +0 -169
- package/src/rsa.ts +0 -370
- package/src/sig.ts +0 -164
- package/src/subtle.ts +0 -639
- package/src/webcrypto.ts +0 -8
- /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
package/src/aes.ts
DELETED
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
|
|
2
|
-
import {
|
|
3
|
-
lazyDOMException,
|
|
4
|
-
type BufferLike,
|
|
5
|
-
hasAnyNotIn,
|
|
6
|
-
validateKeyOps,
|
|
7
|
-
validateByteLength,
|
|
8
|
-
validateMaxBufferLength,
|
|
9
|
-
bufferLikeToArrayBuffer,
|
|
10
|
-
} from './Utils';
|
|
11
|
-
import {
|
|
12
|
-
type ImportFormat,
|
|
13
|
-
type SubtleAlgorithm,
|
|
14
|
-
type KeyUsage,
|
|
15
|
-
CryptoKey,
|
|
16
|
-
createSecretKey,
|
|
17
|
-
SecretKeyObject,
|
|
18
|
-
type JWK,
|
|
19
|
-
type AESAlgorithm,
|
|
20
|
-
CipherOrWrapMode,
|
|
21
|
-
type EncryptDecryptParams,
|
|
22
|
-
type AesGcmParams,
|
|
23
|
-
type AesCbcParams,
|
|
24
|
-
type AesCtrParams,
|
|
25
|
-
type TagLength,
|
|
26
|
-
type AESLength,
|
|
27
|
-
type AesKeyGenParams,
|
|
28
|
-
} from './keys';
|
|
29
|
-
import { generateKeyPromise } from './keygen';
|
|
30
|
-
|
|
31
|
-
// needs to match the values in cpp/webcrypto/crypto_aes.{h,cpp}
|
|
32
|
-
export enum AESKeyVariant {
|
|
33
|
-
AES_CTR_128,
|
|
34
|
-
AES_CTR_192,
|
|
35
|
-
AES_CTR_256,
|
|
36
|
-
AES_CBC_128,
|
|
37
|
-
AES_CBC_192,
|
|
38
|
-
AES_CBC_256,
|
|
39
|
-
AES_GCM_128,
|
|
40
|
-
AES_GCM_192,
|
|
41
|
-
AES_GCM_256,
|
|
42
|
-
AES_KW_128,
|
|
43
|
-
AES_KW_192,
|
|
44
|
-
AES_KW_256,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const kMaxCounterLength = 128;
|
|
48
|
-
const kTagLengths: TagLength[] = [32, 64, 96, 104, 112, 120, 128];
|
|
49
|
-
export const kAesKeyLengths = [128, 192, 256];
|
|
50
|
-
|
|
51
|
-
export const getAlgorithmName = (name: string, length?: number) => {
|
|
52
|
-
if (length === undefined)
|
|
53
|
-
throw lazyDOMException(
|
|
54
|
-
`Invalid algorithm length: ${length}`,
|
|
55
|
-
'SyntaxError'
|
|
56
|
-
);
|
|
57
|
-
switch (name) {
|
|
58
|
-
case 'AES-CBC':
|
|
59
|
-
return `A${length}CBC`;
|
|
60
|
-
case 'AES-CTR':
|
|
61
|
-
return `A${length}CTR`;
|
|
62
|
-
case 'AES-GCM':
|
|
63
|
-
return `A${length}GCM`;
|
|
64
|
-
case 'AES-KW':
|
|
65
|
-
return `A${length}KW`;
|
|
66
|
-
default:
|
|
67
|
-
throw lazyDOMException(`invalid algorithm name: ${name}`, 'SyntaxError');
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
function validateKeyLength(length?: number) {
|
|
72
|
-
if (length !== 128 && length !== 192 && length !== 256)
|
|
73
|
-
throw lazyDOMException(`Invalid key length: ${length}`, 'DataError');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function getVariant(name: AESAlgorithm, length: AESLength): AESKeyVariant {
|
|
77
|
-
switch (name) {
|
|
78
|
-
case 'AES-CBC':
|
|
79
|
-
switch (length) {
|
|
80
|
-
case 128:
|
|
81
|
-
return AESKeyVariant.AES_CBC_128;
|
|
82
|
-
case 192:
|
|
83
|
-
return AESKeyVariant.AES_CBC_192;
|
|
84
|
-
case 256:
|
|
85
|
-
return AESKeyVariant.AES_CBC_256;
|
|
86
|
-
}
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
break;
|
|
89
|
-
case 'AES-CTR':
|
|
90
|
-
switch (length) {
|
|
91
|
-
case 128:
|
|
92
|
-
return AESKeyVariant.AES_CTR_128;
|
|
93
|
-
case 192:
|
|
94
|
-
return AESKeyVariant.AES_CTR_192;
|
|
95
|
-
case 256:
|
|
96
|
-
return AESKeyVariant.AES_CTR_256;
|
|
97
|
-
}
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
break;
|
|
100
|
-
case 'AES-GCM':
|
|
101
|
-
switch (length) {
|
|
102
|
-
case 128:
|
|
103
|
-
return AESKeyVariant.AES_GCM_128;
|
|
104
|
-
case 192:
|
|
105
|
-
return AESKeyVariant.AES_GCM_192;
|
|
106
|
-
case 256:
|
|
107
|
-
return AESKeyVariant.AES_GCM_256;
|
|
108
|
-
}
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
break;
|
|
111
|
-
case 'AES-KW':
|
|
112
|
-
switch (length) {
|
|
113
|
-
case 128:
|
|
114
|
-
return AESKeyVariant.AES_KW_128;
|
|
115
|
-
case 192:
|
|
116
|
-
return AESKeyVariant.AES_KW_192;
|
|
117
|
-
case 256:
|
|
118
|
-
return AESKeyVariant.AES_KW_256;
|
|
119
|
-
}
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
throw lazyDOMException(
|
|
126
|
-
`Error getting variant ${name} at length: ${length}`,
|
|
127
|
-
'DataError'
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function asyncAesCtrCipher(
|
|
132
|
-
mode: CipherOrWrapMode,
|
|
133
|
-
key: CryptoKey,
|
|
134
|
-
data: ArrayBuffer,
|
|
135
|
-
{ counter, length }: AesCtrParams
|
|
136
|
-
): Promise<ArrayBuffer> {
|
|
137
|
-
validateByteLength(counter, 'algorithm.counter', 16);
|
|
138
|
-
// The length must specify an integer between 1 and 128. While
|
|
139
|
-
// there is no default, this should typically be 64.
|
|
140
|
-
if (length === 0 || length > kMaxCounterLength) {
|
|
141
|
-
throw lazyDOMException(
|
|
142
|
-
'AES-CTR algorithm.length must be between 1 and 128',
|
|
143
|
-
'OperationError'
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return NativeQuickCrypto.webcrypto.aesCipher(
|
|
148
|
-
mode,
|
|
149
|
-
key.keyObject.handle,
|
|
150
|
-
data,
|
|
151
|
-
getVariant('AES-CTR', key.algorithm.length as AESLength),
|
|
152
|
-
bufferLikeToArrayBuffer(counter),
|
|
153
|
-
length
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function asyncAesCbcCipher(
|
|
158
|
-
mode: CipherOrWrapMode,
|
|
159
|
-
key: CryptoKey,
|
|
160
|
-
data: ArrayBuffer,
|
|
161
|
-
{ iv }: AesCbcParams
|
|
162
|
-
): Promise<ArrayBuffer> {
|
|
163
|
-
validateByteLength(iv, 'algorithm.iv', 16);
|
|
164
|
-
return NativeQuickCrypto.webcrypto.aesCipher(
|
|
165
|
-
mode,
|
|
166
|
-
key.keyObject.handle,
|
|
167
|
-
data,
|
|
168
|
-
getVariant('AES-CBC', key.algorithm.length as AESLength),
|
|
169
|
-
bufferLikeToArrayBuffer(iv)
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// function asyncAesKwCipher(
|
|
174
|
-
// mode: CipherOrWrapMode,
|
|
175
|
-
// key: CryptoKey,
|
|
176
|
-
// data: BufferLike
|
|
177
|
-
// ): Promise<ArrayBuffer> {
|
|
178
|
-
// return NativeQuickCrypto.webcrypto.aesCipher(
|
|
179
|
-
// mode,
|
|
180
|
-
// key.keyObject.handle,
|
|
181
|
-
// data,
|
|
182
|
-
// getVariant('AES-KW', key.algorithm.length)
|
|
183
|
-
// );
|
|
184
|
-
// }
|
|
185
|
-
|
|
186
|
-
function asyncAesGcmCipher(
|
|
187
|
-
mode: CipherOrWrapMode,
|
|
188
|
-
key: CryptoKey,
|
|
189
|
-
data: ArrayBuffer,
|
|
190
|
-
{ iv, additionalData, tagLength = 128 }: AesGcmParams
|
|
191
|
-
) {
|
|
192
|
-
if (!kTagLengths.includes(tagLength)) {
|
|
193
|
-
throw lazyDOMException(
|
|
194
|
-
`${tagLength} is not a valid AES-GCM tag length`,
|
|
195
|
-
'OperationError'
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
validateMaxBufferLength(iv, 'algorithm.iv');
|
|
200
|
-
|
|
201
|
-
if (additionalData !== undefined) {
|
|
202
|
-
validateMaxBufferLength(additionalData, 'algorithm.additionalData');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const tagByteLength = Math.floor(tagLength / 8);
|
|
206
|
-
let length: number | undefined;
|
|
207
|
-
let tag = new ArrayBuffer(0);
|
|
208
|
-
switch (mode) {
|
|
209
|
-
case CipherOrWrapMode.kWebCryptoCipherDecrypt: {
|
|
210
|
-
// const slice = ArrayBuffer.isView(data)
|
|
211
|
-
// ? DataView.prototype.buffer.slice
|
|
212
|
-
// : ArrayBuffer.prototype.slice;
|
|
213
|
-
tag = data.slice(-tagByteLength);
|
|
214
|
-
|
|
215
|
-
// Refs: https://www.w3.org/TR/WebCryptoAPI/#aes-gcm-operations
|
|
216
|
-
//
|
|
217
|
-
// > If *plaintext* has a length less than *tagLength* bits, then `throw`
|
|
218
|
-
// > an `OperationError`.
|
|
219
|
-
if (tagByteLength > tag.byteLength) {
|
|
220
|
-
throw lazyDOMException(
|
|
221
|
-
'The provided data is too small.',
|
|
222
|
-
'OperationError'
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
data = data.slice(0, -tagByteLength);
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
case CipherOrWrapMode.kWebCryptoCipherEncrypt:
|
|
230
|
-
length = tagByteLength;
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return NativeQuickCrypto.webcrypto.aesCipher(
|
|
235
|
-
mode,
|
|
236
|
-
key.keyObject.handle,
|
|
237
|
-
data,
|
|
238
|
-
getVariant('AES-GCM', key.algorithm.length as AESLength),
|
|
239
|
-
bufferLikeToArrayBuffer(iv),
|
|
240
|
-
length,
|
|
241
|
-
bufferLikeToArrayBuffer(tag),
|
|
242
|
-
bufferLikeToArrayBuffer(additionalData || new ArrayBuffer(0))
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export const aesCipher = (
|
|
247
|
-
mode: CipherOrWrapMode,
|
|
248
|
-
key: CryptoKey,
|
|
249
|
-
data: ArrayBuffer,
|
|
250
|
-
algorithm: EncryptDecryptParams // | WrapUnwrapParams
|
|
251
|
-
): Promise<ArrayBuffer> => {
|
|
252
|
-
switch (algorithm.name) {
|
|
253
|
-
case 'AES-CTR':
|
|
254
|
-
return asyncAesCtrCipher(mode, key, data, algorithm);
|
|
255
|
-
case 'AES-CBC':
|
|
256
|
-
return asyncAesCbcCipher(mode, key, data, algorithm);
|
|
257
|
-
case 'AES-GCM':
|
|
258
|
-
return asyncAesGcmCipher(mode, key, data, algorithm);
|
|
259
|
-
// case 'AES-KW':
|
|
260
|
-
// return asyncAesKwCipher(mode, key, data);
|
|
261
|
-
}
|
|
262
|
-
throw new Error(`aesCipher: Unknown algorithm ${algorithm.name}`);
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
export const aesGenerateKey = async (
|
|
266
|
-
algorithm: AesKeyGenParams,
|
|
267
|
-
extractable: boolean,
|
|
268
|
-
keyUsages: KeyUsage[]
|
|
269
|
-
): Promise<CryptoKey> => {
|
|
270
|
-
const { name, length } = algorithm;
|
|
271
|
-
if (!name) {
|
|
272
|
-
throw lazyDOMException('Algorithm name is undefined', 'SyntaxError');
|
|
273
|
-
}
|
|
274
|
-
if (!kAesKeyLengths.includes(length)) {
|
|
275
|
-
throw lazyDOMException(
|
|
276
|
-
'AES key length must be 128, 192, or 256 bits',
|
|
277
|
-
'OperationError'
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const checkUsages = ['wrapKey', 'unwrapKey'];
|
|
282
|
-
if (name !== 'AES-KW') {
|
|
283
|
-
checkUsages.push('encrypt', 'decrypt');
|
|
284
|
-
}
|
|
285
|
-
// const usagesSet = new SafeSet(keyUsages);
|
|
286
|
-
if (hasAnyNotIn(keyUsages, checkUsages)) {
|
|
287
|
-
throw lazyDOMException(
|
|
288
|
-
`Unsupported key usage for an AES key: ${keyUsages}`,
|
|
289
|
-
'SyntaxError'
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const [err, key] = await generateKeyPromise('aes', { length });
|
|
294
|
-
if (err) {
|
|
295
|
-
throw lazyDOMException(
|
|
296
|
-
`aesGenerateKey (generateKeyPromise) failed: [${err.message}]`,
|
|
297
|
-
{
|
|
298
|
-
name: 'OperationError',
|
|
299
|
-
cause: err,
|
|
300
|
-
}
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return new CryptoKey(
|
|
305
|
-
key as SecretKeyObject,
|
|
306
|
-
{ name, length },
|
|
307
|
-
Array.from(keyUsages),
|
|
308
|
-
extractable
|
|
309
|
-
);
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
export const aesImportKey = async (
|
|
313
|
-
algorithm: SubtleAlgorithm,
|
|
314
|
-
format: ImportFormat,
|
|
315
|
-
keyData: BufferLike | JWK,
|
|
316
|
-
extractable: boolean,
|
|
317
|
-
keyUsages: KeyUsage[]
|
|
318
|
-
): Promise<CryptoKey> => {
|
|
319
|
-
const { name } = algorithm;
|
|
320
|
-
const checkUsages = ['wrapKey', 'unwrapKey'];
|
|
321
|
-
if (name !== 'AES-KW') {
|
|
322
|
-
checkUsages.push('encrypt', 'decrypt');
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// const usagesSet = new SafeSet(keyUsages);
|
|
326
|
-
if (hasAnyNotIn(keyUsages, checkUsages)) {
|
|
327
|
-
throw lazyDOMException(
|
|
328
|
-
'Unsupported key usage for an AES key',
|
|
329
|
-
'SyntaxError'
|
|
330
|
-
);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
let keyObject: SecretKeyObject;
|
|
334
|
-
let length: number | undefined;
|
|
335
|
-
|
|
336
|
-
switch (format) {
|
|
337
|
-
case 'raw': {
|
|
338
|
-
const data = keyData as BufferLike;
|
|
339
|
-
validateKeyLength(data.byteLength * 8);
|
|
340
|
-
keyObject = createSecretKey(keyData);
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
case 'jwk': {
|
|
344
|
-
const data = keyData as JWK;
|
|
345
|
-
|
|
346
|
-
if (!data.kty) throw lazyDOMException('Invalid keyData', 'DataError');
|
|
347
|
-
|
|
348
|
-
if (data.kty !== 'oct')
|
|
349
|
-
throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
|
|
350
|
-
|
|
351
|
-
if (
|
|
352
|
-
keyUsages.length > 0 &&
|
|
353
|
-
data.use !== undefined &&
|
|
354
|
-
data.use !== 'enc'
|
|
355
|
-
) {
|
|
356
|
-
throw lazyDOMException('Invalid JWK "use" Parameter', 'DataError');
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
validateKeyOps(data.key_ops, keyUsages);
|
|
360
|
-
|
|
361
|
-
if (
|
|
362
|
-
data.ext !== undefined &&
|
|
363
|
-
data.ext === false &&
|
|
364
|
-
extractable === true
|
|
365
|
-
) {
|
|
366
|
-
throw lazyDOMException(
|
|
367
|
-
'JWK "ext" Parameter and extractable mismatch',
|
|
368
|
-
'DataError'
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const handle = NativeQuickCrypto.webcrypto.createKeyObjectHandle();
|
|
373
|
-
handle.initJwk(data);
|
|
374
|
-
|
|
375
|
-
({ length } = handle.keyDetail());
|
|
376
|
-
validateKeyLength(length);
|
|
377
|
-
|
|
378
|
-
if (data.alg !== undefined) {
|
|
379
|
-
if (data.alg !== getAlgorithmName(algorithm.name, length))
|
|
380
|
-
throw lazyDOMException(
|
|
381
|
-
'JWK "alg" does not match the requested algorithm',
|
|
382
|
-
'DataError'
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
keyObject = new SecretKeyObject(handle);
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
default:
|
|
390
|
-
throw lazyDOMException(
|
|
391
|
-
`Unable to import AES key with format ${format}`,
|
|
392
|
-
'NotSupportedError'
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
if (length === undefined) {
|
|
397
|
-
({ length } = keyObject.handle.keyDetail());
|
|
398
|
-
validateKeyLength(length);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
return new CryptoKey(keyObject, { name, length }, keyUsages, extractable);
|
|
402
|
-
};
|
package/src/constants.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// Taken by printing node.crypto.constants
|
|
2
|
-
// Node declares them as enums on v8 directly
|
|
3
|
-
// Whenever the API gets updated (or some dependency like OpenSSL) I guess we will have to revisit these
|
|
4
|
-
export const constants = {
|
|
5
|
-
OPENSSL_VERSION_NUMBER: 269488367,
|
|
6
|
-
SSL_OP_ALL: 2147485780,
|
|
7
|
-
SSL_OP_ALLOW_NO_DHE_KEX: 1024,
|
|
8
|
-
SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: 262144,
|
|
9
|
-
SSL_OP_CIPHER_SERVER_PREFERENCE: 4194304,
|
|
10
|
-
SSL_OP_CISCO_ANYCONNECT: 32768,
|
|
11
|
-
SSL_OP_COOKIE_EXCHANGE: 8192,
|
|
12
|
-
SSL_OP_CRYPTOPRO_TLSEXT_BUG: 2147483648,
|
|
13
|
-
SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: 2048,
|
|
14
|
-
SSL_OP_EPHEMERAL_RSA: 0,
|
|
15
|
-
SSL_OP_LEGACY_SERVER_CONNECT: 4,
|
|
16
|
-
SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: 0,
|
|
17
|
-
SSL_OP_MICROSOFT_SESS_ID_BUG: 0,
|
|
18
|
-
SSL_OP_MSIE_SSLV2_RSA_PADDING: 0,
|
|
19
|
-
SSL_OP_NETSCAPE_CA_DN_BUG: 0,
|
|
20
|
-
SSL_OP_NETSCAPE_CHALLENGE_BUG: 0,
|
|
21
|
-
SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: 0,
|
|
22
|
-
SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: 0,
|
|
23
|
-
SSL_OP_NO_COMPRESSION: 131072,
|
|
24
|
-
SSL_OP_NO_ENCRYPT_THEN_MAC: 524288,
|
|
25
|
-
SSL_OP_NO_QUERY_MTU: 4096,
|
|
26
|
-
SSL_OP_NO_RENEGOTIATION: 1073741824,
|
|
27
|
-
SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: 65536,
|
|
28
|
-
SSL_OP_NO_SSLv2: 0,
|
|
29
|
-
SSL_OP_NO_SSLv3: 33554432,
|
|
30
|
-
SSL_OP_NO_TICKET: 16384,
|
|
31
|
-
SSL_OP_NO_TLSv1: 67108864,
|
|
32
|
-
SSL_OP_NO_TLSv1_1: 268435456,
|
|
33
|
-
SSL_OP_NO_TLSv1_2: 134217728,
|
|
34
|
-
SSL_OP_NO_TLSv1_3: 536870912,
|
|
35
|
-
SSL_OP_PKCS1_CHECK_1: 0,
|
|
36
|
-
SSL_OP_PKCS1_CHECK_2: 0,
|
|
37
|
-
SSL_OP_PRIORITIZE_CHACHA: 2097152,
|
|
38
|
-
SSL_OP_SINGLE_DH_USE: 0,
|
|
39
|
-
SSL_OP_SINGLE_ECDH_USE: 0,
|
|
40
|
-
SSL_OP_SSLEAY_080_CLIENT_DH_BUG: 0,
|
|
41
|
-
SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: 0,
|
|
42
|
-
SSL_OP_TLS_BLOCK_PADDING_BUG: 0,
|
|
43
|
-
SSL_OP_TLS_D5_BUG: 0,
|
|
44
|
-
SSL_OP_TLS_ROLLBACK_BUG: 8388608,
|
|
45
|
-
ENGINE_METHOD_RSA: 1,
|
|
46
|
-
ENGINE_METHOD_DSA: 2,
|
|
47
|
-
ENGINE_METHOD_DH: 4,
|
|
48
|
-
ENGINE_METHOD_RAND: 8,
|
|
49
|
-
ENGINE_METHOD_EC: 2048,
|
|
50
|
-
ENGINE_METHOD_CIPHERS: 64,
|
|
51
|
-
ENGINE_METHOD_DIGESTS: 128,
|
|
52
|
-
ENGINE_METHOD_PKEY_METHS: 512,
|
|
53
|
-
ENGINE_METHOD_PKEY_ASN1_METHS: 1024,
|
|
54
|
-
ENGINE_METHOD_ALL: 65535,
|
|
55
|
-
ENGINE_METHOD_NONE: 0,
|
|
56
|
-
DH_CHECK_P_NOT_SAFE_PRIME: 2,
|
|
57
|
-
DH_CHECK_P_NOT_PRIME: 1,
|
|
58
|
-
DH_UNABLE_TO_CHECK_GENERATOR: 4,
|
|
59
|
-
DH_NOT_SUITABLE_GENERATOR: 8,
|
|
60
|
-
ALPN_ENABLED: 1,
|
|
61
|
-
RSA_PKCS1_PADDING: 1,
|
|
62
|
-
RSA_SSLV23_PADDING: 2,
|
|
63
|
-
RSA_NO_PADDING: 3,
|
|
64
|
-
RSA_PKCS1_OAEP_PADDING: 4,
|
|
65
|
-
RSA_X931_PADDING: 5,
|
|
66
|
-
RSA_PKCS1_PSS_PADDING: 6,
|
|
67
|
-
RSA_PSS_SALTLEN_DIGEST: -1,
|
|
68
|
-
RSA_PSS_SALTLEN_MAX_SIGN: -2,
|
|
69
|
-
RSA_PSS_SALTLEN_AUTO: -2,
|
|
70
|
-
defaultCoreCipherList:
|
|
71
|
-
'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA',
|
|
72
|
-
TLS1_VERSION: 769,
|
|
73
|
-
TLS1_1_VERSION: 770,
|
|
74
|
-
TLS1_2_VERSION: 771,
|
|
75
|
-
TLS1_3_VERSION: 772,
|
|
76
|
-
POINT_CONVERSION_COMPRESSED: 2,
|
|
77
|
-
POINT_CONVERSION_UNCOMPRESSED: 4,
|
|
78
|
-
POINT_CONVERSION_HYBRID: 6,
|
|
79
|
-
};
|