react-native-quick-crypto 0.3.2 → 0.4.0
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/README.md +10 -6
- package/android/CMakeLists.txt +10 -2
- package/android/gradle.properties +1 -1
- package/cpp/Cipher/MGLCipherHostObject.cpp +4 -5
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +1 -3
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +6 -3
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +5 -3
- package/cpp/Cipher/MGLPublicCipher.h +1 -1
- package/cpp/Cipher/MGLPublicCipherInstaller.h +1 -1
- package/cpp/Cipher/MGLRsa.h +5 -1
- package/cpp/JSIUtils/MGLJSIMacros.h +69 -6
- package/cpp/{Cipher/MGLCipherKeys.cpp → MGLKeys.cpp} +47 -49
- package/cpp/{Cipher/MGLCipherKeys.h → MGLKeys.h} +29 -30
- package/cpp/MGLQuickCryptoHostObject.cpp +12 -0
- package/cpp/Sig/MGLSignHostObjects.cpp +889 -0
- package/cpp/Sig/MGLSignHostObjects.h +88 -0
- package/cpp/Sig/MGLSignInstaller.cpp +24 -0
- package/cpp/Sig/MGLSignInstaller.h +29 -0
- package/cpp/Sig/MGLVerifyInstaller.cpp +24 -0
- package/cpp/Sig/MGLVerifyInstaller.h +22 -0
- package/cpp/Utils/MGLUtils.cpp +67 -29
- package/cpp/Utils/MGLUtils.h +17 -17
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +1 -0
- package/lib/commonjs/QuickCrypto.js +4 -0
- package/lib/commonjs/QuickCrypto.js.map +1 -1
- package/lib/commonjs/keys.js +1 -4
- package/lib/commonjs/keys.js.map +1 -1
- package/lib/commonjs/sig.js +170 -0
- package/lib/commonjs/sig.js.map +1 -0
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/module/NativeQuickCrypto/sig.js +2 -0
- package/lib/module/NativeQuickCrypto/sig.js.map +1 -0
- package/lib/module/QuickCrypto.js +3 -0
- package/lib/module/QuickCrypto.js.map +1 -1
- package/lib/module/keys.js +1 -4
- package/lib/module/keys.js.map +1 -1
- package/lib/module/sig.js +155 -0
- package/lib/module/sig.js.map +1 -0
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +3 -0
- package/lib/typescript/NativeQuickCrypto/sig.d.ts +12 -0
- package/lib/typescript/QuickCrypto.d.ts +3 -0
- package/lib/typescript/index.d.ts +2 -3
- package/lib/typescript/sig.d.ts +35 -0
- package/package.json +3 -2
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +3 -0
- package/src/NativeQuickCrypto/sig.ts +17 -0
- package/src/QuickCrypto.ts +3 -0
- package/src/keys.ts +18 -13
- package/src/sig.ts +179 -0
package/README.md
CHANGED
|
@@ -9,11 +9,10 @@ A fast implementation of Node's `crypto` module.
|
|
|
9
9
|
Unlike any other current JS-based polyfills, react-native-quick-crypto is written in C/C++ JSI and provides much greater performance - especially on mobile devices.
|
|
10
10
|
QuickCrypto can be used as a drop-in replacement for your Web3/Crypto apps to speed up common cryptography functions.
|
|
11
11
|
|
|
12
|
-
* 🏎️ Up to
|
|
12
|
+
* 🏎️ Up to 58x faster than all other solutions
|
|
13
13
|
* ⚡️ Lightning fast implementation with pure C++ and JSI, instead of JS
|
|
14
14
|
* 🧪 Well tested in JS and C++ (OpenSSL)
|
|
15
15
|
* 💰 Made for crypto apps and Wallets
|
|
16
|
-
* 🤌 Up to 5x smaller in JS-bundle size
|
|
17
16
|
* 🔢 Secure native compiled cryptography
|
|
18
17
|
* 🔁 Easy drop-in replacement for [crypto-browserify](https://github.com/crypto-browserify/crypto-browserify) or [react-native-crypto](https://github.com/tradle/react-native-crypto)
|
|
19
18
|
|
|
@@ -23,19 +22,19 @@ For example, creating a Wallet using ethers.js uses complex algorithms to genera
|
|
|
23
22
|
const start = performance.now()
|
|
24
23
|
const wallet = ethers.Wallet.createRandom()
|
|
25
24
|
const end = performance.now()
|
|
26
|
-
console.log(`Creating a Wallet took ${end - start}ms.`)
|
|
25
|
+
console.log(`Creating a Wallet took ${end - start} ms.`)
|
|
27
26
|
```
|
|
28
27
|
|
|
29
28
|
**Without** react-native-crypto 🐢:
|
|
30
29
|
|
|
31
30
|
```
|
|
32
|
-
Creating a Wallet took
|
|
31
|
+
Creating a Wallet took 16862 ms
|
|
33
32
|
```
|
|
34
33
|
|
|
35
34
|
**With** react-native-crypto ⚡️:
|
|
36
35
|
|
|
37
36
|
```
|
|
38
|
-
Creating a Wallet took
|
|
37
|
+
Creating a Wallet took 289 ms
|
|
39
38
|
```
|
|
40
39
|
|
|
41
40
|
---
|
|
@@ -89,7 +88,12 @@ Now, all imports for `crypto` will be resolved as `react-native-quick-crypto` in
|
|
|
89
88
|
|
|
90
89
|
## Sponsors
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
<div align="center">
|
|
92
|
+
|
|
93
|
+
<img width="350" src="./img/sponsors/litentry.png" align="center"><br/>
|
|
94
|
+
<a href="https://litentry.com"><b>Litentry</b></a> - A decentralized identity aggregator, providing the structure and tools to empower you and your identity.
|
|
95
|
+
|
|
96
|
+
</div>
|
|
93
97
|
|
|
94
98
|
## Limitations
|
|
95
99
|
|
package/android/CMakeLists.txt
CHANGED
|
@@ -6,8 +6,8 @@ file (GLOB LIBFBJNI_INCLUDES "${BUILD_DIR}/fbjni-*-headers.jar/")
|
|
|
6
6
|
file (GLOB LIBRN_SO "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
|
|
7
7
|
set (CMAKE_CXX_STANDARD 17)
|
|
8
8
|
# TODO(osp) remove before release
|
|
9
|
-
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
|
|
10
|
-
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
|
|
9
|
+
#set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
|
|
10
|
+
#set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
|
|
11
11
|
|
|
12
12
|
include_directories(
|
|
13
13
|
../cpp
|
|
@@ -48,6 +48,14 @@ add_library(reactnativequickcrypto # <-- Library name
|
|
|
48
48
|
"../cpp/Cipher/MGLCipherHostObject.cpp"
|
|
49
49
|
"../cpp/Cipher/MGLCreateCipherInstaller.cpp"
|
|
50
50
|
"../cpp/Cipher/MGLCreateDecipherInstaller.cpp"
|
|
51
|
+
"../cpp/MGLKeys.cpp"
|
|
52
|
+
"../cpp/Utils/MGLUtils.cpp"
|
|
53
|
+
"../cpp/Cipher/MGLRsa.cpp"
|
|
54
|
+
"../cpp/Cipher/MGLGenerateKeyPairInstaller.cpp"
|
|
55
|
+
"../cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp"
|
|
56
|
+
"../cpp/Sig/MGLSignInstaller.cpp"
|
|
57
|
+
"../cpp/Sig/MGLVerifyInstaller.cpp"
|
|
58
|
+
"../cpp/Sig/MGLSignHostObjects.cpp"
|
|
51
59
|
${INCLUDE_JSI_CPP} # only on older RN versions
|
|
52
60
|
)
|
|
53
61
|
|
|
@@ -252,7 +252,7 @@ void MGLCipherHostObject::installMethods() {
|
|
|
252
252
|
// On the node version there are several layers of wrapping and errors
|
|
253
253
|
// are not immediately surfaced On our version we can simply throw an
|
|
254
254
|
// error as soon as something goes wrong
|
|
255
|
-
throw jsi::JSError(runtime,
|
|
255
|
+
throw jsi::JSError(runtime, "kErrorState");
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
const int mode = EVP_CIPHER_CTX_mode(ctx_);
|
|
@@ -502,10 +502,9 @@ void MGLCipherHostObject::installMethods() {
|
|
|
502
502
|
}
|
|
503
503
|
|
|
504
504
|
if (!is_valid) {
|
|
505
|
-
jsi::detail::throwJSError(
|
|
506
|
-
|
|
507
|
-
throw jsi::JSError(runtime,
|
|
508
|
-
"Invalid authentication tag length: " + tag_len);
|
|
505
|
+
jsi::detail::throwJSError(runtime,
|
|
506
|
+
"Invalid authentication tag length");
|
|
507
|
+
throw jsi::JSError(runtime, "Invalid authentication tag length");
|
|
509
508
|
}
|
|
510
509
|
|
|
511
510
|
auth_tag_len_ = tag_len;
|
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
#include <memory>
|
|
5
5
|
|
|
6
|
+
#include "MGLCipherHostObject.h"
|
|
6
7
|
#ifdef ANDROID
|
|
7
8
|
#include "JSIUtils/MGLJSIMacros.h"
|
|
8
9
|
#else
|
|
9
10
|
#include "MGLJSIMacros.h"
|
|
10
11
|
#endif
|
|
11
|
-
#include "MGLCipherHostObject.h"
|
|
12
|
-
|
|
13
|
-
using namespace facebook;
|
|
14
12
|
|
|
15
13
|
namespace margelo {
|
|
16
14
|
|
|
@@ -13,14 +13,17 @@
|
|
|
13
13
|
|
|
14
14
|
#include <memory>
|
|
15
15
|
|
|
16
|
+
#include "MGLKeys.h"
|
|
17
|
+
|
|
16
18
|
#ifdef ANDROID
|
|
19
|
+
#include "Cipher/MGLRsa.h"
|
|
17
20
|
#include "JSIUtils/MGLSmartHostObject.h"
|
|
21
|
+
#include "Utils/MGLUtils.h"
|
|
18
22
|
#else
|
|
19
|
-
#include "MGLSmartHostObject.h"
|
|
20
|
-
#endif
|
|
21
|
-
#include "MGLCipherKeys.h"
|
|
22
23
|
#include "MGLRsa.h"
|
|
24
|
+
#include "MGLSmartHostObject.h"
|
|
23
25
|
#include "MGLUtils.h"
|
|
26
|
+
#endif
|
|
24
27
|
|
|
25
28
|
namespace margelo {
|
|
26
29
|
|
|
@@ -13,13 +13,15 @@
|
|
|
13
13
|
#include <memory>
|
|
14
14
|
|
|
15
15
|
#ifdef ANDROID
|
|
16
|
+
#include "Cipher/MGLRsa.h"
|
|
16
17
|
#include "JSIUtils/MGLSmartHostObject.h"
|
|
18
|
+
#include "Utils/MGLUtils.h"
|
|
17
19
|
#else
|
|
18
|
-
#include "MGLSmartHostObject.h"
|
|
19
|
-
#endif
|
|
20
|
-
#include "MGLCipherKeys.h"
|
|
21
20
|
#include "MGLRsa.h"
|
|
21
|
+
#include "MGLSmartHostObject.h"
|
|
22
22
|
#include "MGLUtils.h"
|
|
23
|
+
#endif
|
|
24
|
+
#include "MGLKeys.h"
|
|
23
25
|
|
|
24
26
|
namespace margelo {
|
|
25
27
|
|
package/cpp/Cipher/MGLRsa.h
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 24/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
1
|
#ifndef MGL_JSIMACROS_H
|
|
6
2
|
#define MGL_JSIMACROS_H
|
|
7
3
|
|
|
8
4
|
#include <utility>
|
|
9
5
|
|
|
10
|
-
//
|
|
11
|
-
|
|
6
|
+
// Windows 8+ does not like abort() in Release mode
|
|
7
|
+
#ifdef _WIN32
|
|
8
|
+
#define ABORT_NO_BACKTRACE() _exit(134)
|
|
9
|
+
#else
|
|
10
|
+
#define ABORT_NO_BACKTRACE() abort()
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
struct AssertionInfo {
|
|
14
|
+
const char *file_line; // filename:line
|
|
15
|
+
const char *message;
|
|
16
|
+
const char *function;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
inline void Abort() {
|
|
20
|
+
// DumpBacktrace(stderr);
|
|
21
|
+
fflush(stderr);
|
|
22
|
+
ABORT_NO_BACKTRACE();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
inline void Assert(const AssertionInfo &info) {
|
|
26
|
+
// std::string name = GetHumanReadableProcessName();
|
|
27
|
+
|
|
28
|
+
fprintf(stderr, "%s:%s%s Assertion `%s' failed.\n", info.file_line,
|
|
29
|
+
info.function, *info.function ? ":" : "", info.message);
|
|
30
|
+
fflush(stderr);
|
|
31
|
+
|
|
32
|
+
Abort();
|
|
33
|
+
}
|
|
12
34
|
|
|
13
35
|
#define HOST_LAMBDA(name, body) HOST_LAMBDA_CAP(name, [=], body)
|
|
14
36
|
|
|
@@ -34,4 +56,45 @@
|
|
|
34
56
|
const jsi::Value *arguments, size_t count) \
|
|
35
57
|
->jsi::Value
|
|
36
58
|
|
|
59
|
+
// Macros stolen from Node
|
|
60
|
+
#define ABORT() node::Abort()
|
|
61
|
+
|
|
62
|
+
#define ERROR_AND_ABORT(expr) \
|
|
63
|
+
do { \
|
|
64
|
+
/* Make sure that this struct does not end up in inline code, but */ \
|
|
65
|
+
/* rather in a read-only data section when modifying this code. */ \
|
|
66
|
+
static const AssertionInfo args = {__FILE__ ":" STRINGIFY(__LINE__), \
|
|
67
|
+
#expr, PRETTY_FUNCTION_NAME}; \
|
|
68
|
+
Assert(args); \
|
|
69
|
+
} while (0)
|
|
70
|
+
#ifdef __GNUC__
|
|
71
|
+
#define LIKELY(expr) __builtin_expect(!!(expr), 1)
|
|
72
|
+
#define UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
|
73
|
+
#define PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__
|
|
74
|
+
#else
|
|
75
|
+
#define LIKELY(expr) expr
|
|
76
|
+
#define UNLIKELY(expr) expr
|
|
77
|
+
#define PRETTY_FUNCTION_NAME ""
|
|
78
|
+
#endif
|
|
79
|
+
|
|
80
|
+
#define STRINGIFY_(x) #x
|
|
81
|
+
#define STRINGIFY(x) STRINGIFY_(x)
|
|
82
|
+
|
|
83
|
+
#define CHECK(expr) \
|
|
84
|
+
do { \
|
|
85
|
+
if (UNLIKELY(!(expr))) { \
|
|
86
|
+
ERROR_AND_ABORT(expr); \
|
|
87
|
+
} \
|
|
88
|
+
} while (0)
|
|
89
|
+
|
|
90
|
+
#define CHECK_EQ(a, b) CHECK((a) == (b))
|
|
91
|
+
#define CHECK_GE(a, b) CHECK((a) >= (b))
|
|
92
|
+
#define CHECK_GT(a, b) CHECK((a) > (b))
|
|
93
|
+
#define CHECK_LE(a, b) CHECK((a) <= (b))
|
|
94
|
+
#define CHECK_LT(a, b) CHECK((a) < (b))
|
|
95
|
+
#define CHECK_NE(a, b) CHECK((a) != (b))
|
|
96
|
+
#define CHECK_NULL(val) CHECK((val) == nullptr)
|
|
97
|
+
#define CHECK_NOT_NULL(val) CHECK((val) != nullptr)
|
|
98
|
+
#define CHECK_IMPLIES(a, b) CHECK(!(a) || (b))
|
|
99
|
+
|
|
37
100
|
#endif // MGL_JSIMACROS_H
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Created by Oscar on 20.06.22.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
#include "
|
|
8
|
+
#include "MGLKeys.h"
|
|
9
9
|
|
|
10
10
|
#include <jsi/jsi.h>
|
|
11
11
|
#include <openssl/bio.h>
|
|
@@ -15,12 +15,16 @@
|
|
|
15
15
|
#include <utility>
|
|
16
16
|
#include <vector>
|
|
17
17
|
|
|
18
|
+
#ifdef ANDROID
|
|
19
|
+
#include "JSIUtils/MGLJSIMacros.h"
|
|
20
|
+
#include "JSIUtils/MGLJSIUtils.h"
|
|
21
|
+
#include "JSIUtils/MGLTypedArray.h"
|
|
22
|
+
#include "Utils/MGLUtils.h"
|
|
23
|
+
#else
|
|
24
|
+
#include "MGLJSIMacros.h"
|
|
18
25
|
#include "MGLJSIUtils.h"
|
|
19
26
|
#include "MGLTypedArray.h"
|
|
20
27
|
#include "MGLUtils.h"
|
|
21
|
-
#ifdef ANDROID
|
|
22
|
-
#else
|
|
23
|
-
#include "logs.h"
|
|
24
28
|
#endif
|
|
25
29
|
|
|
26
30
|
namespace margelo {
|
|
@@ -33,8 +37,8 @@ void GetKeyFormatAndTypeFromJs(AsymmetricKeyEncodingConfig* config,
|
|
|
33
37
|
// During key pair generation, it is possible not to specify a key encoding,
|
|
34
38
|
// which will lead to a key object being returned.
|
|
35
39
|
if (args[*offset].isUndefined()) {
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
CHECK_EQ(context, kKeyContextGenerate);
|
|
41
|
+
CHECK(args[*offset + 1].isUndefined());
|
|
38
42
|
config->output_key_object_ = true;
|
|
39
43
|
} else {
|
|
40
44
|
config->output_key_object_ = false;
|
|
@@ -44,16 +48,13 @@ void GetKeyFormatAndTypeFromJs(AsymmetricKeyEncodingConfig* config,
|
|
|
44
48
|
config->format_ = static_cast<PKFormatType>((int)args[*offset].getNumber());
|
|
45
49
|
|
|
46
50
|
if (args[*offset + 1].isNumber()) {
|
|
47
|
-
config->type_ =
|
|
48
|
-
static_cast<PKEncodingType>((int)args[*offset + 1].getNumber())
|
|
51
|
+
config->type_ =
|
|
52
|
+
static_cast<PKEncodingType>((int)args[*offset + 1].getNumber());
|
|
49
53
|
} else {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// (context == kKeyContextGenerate &&
|
|
55
|
-
// config->format_ == kKeyFormatJWK));
|
|
56
|
-
// CHECK(args[*offset + 1]->IsNullOrUndefined());
|
|
54
|
+
CHECK(
|
|
55
|
+
(context == kKeyContextInput && config->format_ == kKeyFormatPEM) ||
|
|
56
|
+
(context == kKeyContextGenerate && config->format_ == kKeyFormatJWK));
|
|
57
|
+
CHECK(args[*offset + 1].isUndefined());
|
|
57
58
|
config->type_ = std::nullopt;
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -193,11 +194,10 @@ ParseKeyResult ParsePrivateKey(EVPKeyPointer* pkey,
|
|
|
193
194
|
pkey->reset(PEM_read_bio_PrivateKey(bio.get(), nullptr, PasswordCallback,
|
|
194
195
|
&passphrase));
|
|
195
196
|
} else {
|
|
196
|
-
|
|
197
|
+
CHECK_EQ(config.format_, kKeyFormatDER);
|
|
197
198
|
|
|
198
199
|
if (!config.type_.has_value()) {
|
|
199
|
-
|
|
200
|
-
// throw new crashing exception
|
|
200
|
+
throw new std::runtime_error("ParsePrivateKey key config has no type!");
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
if (config.type_.value() == kKeyEncodingPKCS1) {
|
|
@@ -216,7 +216,7 @@ ParseKeyResult ParsePrivateKey(EVPKeyPointer* pkey,
|
|
|
216
216
|
if (p8inf) pkey->reset(EVP_PKCS82PKEY(p8inf.get()));
|
|
217
217
|
}
|
|
218
218
|
} else {
|
|
219
|
-
|
|
219
|
+
CHECK_EQ(config.type_.value(), kKeyEncodingSEC1);
|
|
220
220
|
const unsigned char* p = reinterpret_cast<const unsigned char*>(key);
|
|
221
221
|
pkey->reset(d2i_PrivateKey(EVP_PKEY_EC, nullptr, &p, key_len));
|
|
222
222
|
}
|
|
@@ -692,36 +692,34 @@ PublicKeyEncodingConfig ManagedEVPPKey::GetPublicKeyEncodingFromJs(
|
|
|
692
692
|
return result;
|
|
693
693
|
}
|
|
694
694
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
//
|
|
714
|
-
//
|
|
715
|
-
//
|
|
716
|
-
//
|
|
717
|
-
//
|
|
718
|
-
//
|
|
719
|
-
//
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
// }
|
|
724
|
-
//}
|
|
695
|
+
ManagedEVPPKey ManagedEVPPKey::GetPrivateKeyFromJs(jsi::Runtime& runtime,
|
|
696
|
+
const jsi::Value* args,
|
|
697
|
+
unsigned int* offset,
|
|
698
|
+
bool allow_key_object) {
|
|
699
|
+
if (args[*offset].isString() ||
|
|
700
|
+
args[*offset].asObject(runtime).isArrayBuffer(runtime)) {
|
|
701
|
+
ByteSource key = ByteSource::FromStringOrBuffer(runtime, args[*offset]);
|
|
702
|
+
(*offset)++;
|
|
703
|
+
NonCopyableMaybe<PrivateKeyEncodingConfig> config =
|
|
704
|
+
GetPrivateKeyEncodingFromJs(runtime, args, offset, kKeyContextInput);
|
|
705
|
+
if (config.IsEmpty()) return ManagedEVPPKey();
|
|
706
|
+
|
|
707
|
+
EVPKeyPointer pkey;
|
|
708
|
+
ParseKeyResult ret =
|
|
709
|
+
ParsePrivateKey(&pkey, config.Release(), key.data<char>(), key.size());
|
|
710
|
+
return GetParsedKey(runtime, std::move(pkey), ret,
|
|
711
|
+
"Failed to read private key");
|
|
712
|
+
} else {
|
|
713
|
+
// CHECK(args[*offset]->IsObject() && allow_key_object);
|
|
714
|
+
// KeyObjectHandle* key;
|
|
715
|
+
// ASSIGN_OR_RETURN_UNWRAP(&key, args[*offset].As<Object>(),
|
|
716
|
+
// ManagedEVPPKey()); CHECK_EQ(key->Data()->GetKeyType(),
|
|
717
|
+
// kKeyTypePrivate);
|
|
718
|
+
// (*offset) += 4;
|
|
719
|
+
// return key->Data()->GetAsymmetricKey();
|
|
720
|
+
throw jsi::JSError(runtime, "KeyObject are not currently supported");
|
|
721
|
+
}
|
|
722
|
+
}
|
|
725
723
|
|
|
726
724
|
ManagedEVPPKey ManagedEVPPKey::GetPublicOrPrivateKeyFromJs(
|
|
727
725
|
jsi::Runtime& runtime, const jsi::Value* args, unsigned int* offset) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
//
|
|
2
|
-
// MGLCipherKeys.
|
|
3
|
-
// react-native-
|
|
2
|
+
// MGLCipherKeys.h
|
|
3
|
+
// react-native-quick-crypto
|
|
4
4
|
//
|
|
5
5
|
// Created by Oscar on 20.06.22.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
#ifndef
|
|
9
|
-
#define
|
|
8
|
+
#ifndef MGLCipherKeys_h
|
|
9
|
+
#define MGLCipherKeys_h
|
|
10
10
|
|
|
11
11
|
#include <jsi/jsi.h>
|
|
12
12
|
#include <openssl/evp.h>
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
#include <string>
|
|
17
17
|
|
|
18
18
|
#ifdef ANDROID
|
|
19
|
-
#include "
|
|
19
|
+
#include "Utils/MGLUtils.h"
|
|
20
20
|
#else
|
|
21
21
|
#include "MGLUtils.h"
|
|
22
22
|
#endif
|
|
@@ -62,7 +62,7 @@ struct AsymmetricKeyEncodingConfig {
|
|
|
62
62
|
using PublicKeyEncodingConfig = AsymmetricKeyEncodingConfig;
|
|
63
63
|
|
|
64
64
|
struct PrivateKeyEncodingConfig : public AsymmetricKeyEncodingConfig {
|
|
65
|
-
const EVP_CIPHER*
|
|
65
|
+
const EVP_CIPHER *cipher_;
|
|
66
66
|
// The ByteSource alone is not enough to distinguish between "no passphrase"
|
|
67
67
|
// and a zero-length passphrase (which can be a null pointer), therefore, we
|
|
68
68
|
// use a NonCopyableMaybe.
|
|
@@ -75,50 +75,49 @@ struct PrivateKeyEncodingConfig : public AsymmetricKeyEncodingConfig {
|
|
|
75
75
|
class ManagedEVPPKey {
|
|
76
76
|
public:
|
|
77
77
|
ManagedEVPPKey() {}
|
|
78
|
-
explicit ManagedEVPPKey(EVPKeyPointer&&
|
|
79
|
-
ManagedEVPPKey(const ManagedEVPPKey&
|
|
80
|
-
ManagedEVPPKey&
|
|
78
|
+
explicit ManagedEVPPKey(EVPKeyPointer &&pkey);
|
|
79
|
+
ManagedEVPPKey(const ManagedEVPPKey &that);
|
|
80
|
+
ManagedEVPPKey &operator=(const ManagedEVPPKey &that);
|
|
81
81
|
|
|
82
82
|
operator bool() const;
|
|
83
|
-
EVP_PKEY*
|
|
83
|
+
EVP_PKEY *get() const;
|
|
84
84
|
|
|
85
85
|
static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
|
|
86
|
-
jsi::Runtime&
|
|
86
|
+
jsi::Runtime &runtime, const jsi::Value *arguments, unsigned int *offset,
|
|
87
87
|
KeyEncodingContext context);
|
|
88
88
|
|
|
89
89
|
static NonCopyableMaybe<PrivateKeyEncodingConfig> GetPrivateKeyEncodingFromJs(
|
|
90
|
-
jsi::Runtime&
|
|
90
|
+
jsi::Runtime &runtime, const jsi::Value *arguments, unsigned int *offset,
|
|
91
91
|
KeyEncodingContext context);
|
|
92
92
|
//
|
|
93
|
-
static ManagedEVPPKey GetParsedKey(jsi::Runtime&
|
|
94
|
-
EVPKeyPointer&&
|
|
95
|
-
const char*
|
|
93
|
+
static ManagedEVPPKey GetParsedKey(jsi::Runtime &runtime,
|
|
94
|
+
EVPKeyPointer &&pkey, ParseKeyResult ret,
|
|
95
|
+
const char *default_msg);
|
|
96
96
|
|
|
97
|
-
static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(jsi::Runtime&
|
|
98
|
-
const jsi::Value*
|
|
99
|
-
unsigned int*
|
|
97
|
+
static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(jsi::Runtime &runtime,
|
|
98
|
+
const jsi::Value *args,
|
|
99
|
+
unsigned int *offset);
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// allow_key_object);
|
|
101
|
+
static ManagedEVPPKey GetPrivateKeyFromJs(jsi::Runtime &runtime,
|
|
102
|
+
const jsi::Value *args,
|
|
103
|
+
unsigned int *offset,
|
|
104
|
+
bool allow_key_object);
|
|
106
105
|
|
|
107
106
|
static std::optional<StringOrBuffer> ToEncodedPublicKey(
|
|
108
|
-
jsi::Runtime&
|
|
109
|
-
const PublicKeyEncodingConfig&
|
|
107
|
+
jsi::Runtime &runtime, ManagedEVPPKey key,
|
|
108
|
+
const PublicKeyEncodingConfig &config);
|
|
110
109
|
|
|
111
110
|
static std::optional<StringOrBuffer> ToEncodedPrivateKey(
|
|
112
|
-
jsi::Runtime&
|
|
113
|
-
const PrivateKeyEncodingConfig&
|
|
111
|
+
jsi::Runtime &runtime, ManagedEVPPKey key,
|
|
112
|
+
const PrivateKeyEncodingConfig &config);
|
|
114
113
|
|
|
115
114
|
private:
|
|
116
|
-
size_t size_of_private_key() const;
|
|
117
|
-
size_t size_of_public_key() const;
|
|
115
|
+
// size_t size_of_private_key() const;
|
|
116
|
+
// size_t size_of_public_key() const;
|
|
118
117
|
|
|
119
118
|
EVPKeyPointer pkey_;
|
|
120
119
|
};
|
|
121
120
|
|
|
122
121
|
} // namespace margelo
|
|
123
122
|
|
|
124
|
-
#endif /*
|
|
123
|
+
#endif /* MGLCipherKeys_h */
|
|
@@ -11,11 +11,15 @@
|
|
|
11
11
|
#ifdef ANDROID
|
|
12
12
|
#include "Cipher/MGLCreateCipherInstaller.h"
|
|
13
13
|
#include "Cipher/MGLCreateDecipherInstaller.h"
|
|
14
|
+
#include "Cipher/MGLGenerateKeyPairInstaller.h"
|
|
15
|
+
#include "Cipher/MGLGenerateKeyPairSyncInstaller.h"
|
|
14
16
|
#include "Cipher/MGLPublicCipher.h"
|
|
15
17
|
#include "Cipher/MGLPublicCipherInstaller.h"
|
|
16
18
|
#include "HMAC/MGLHmacInstaller.h"
|
|
17
19
|
#include "Hash/MGLHashInstaller.h"
|
|
18
20
|
#include "Random/MGLRandomHostObject.h"
|
|
21
|
+
#include "Sig/MGLSignInstaller.h"
|
|
22
|
+
#include "Sig/MGLVerifyInstaller.h"
|
|
19
23
|
#include "fastpbkdf2/MGLPbkdf2HostObject.h"
|
|
20
24
|
#else
|
|
21
25
|
#include "MGLCreateCipherInstaller.h"
|
|
@@ -28,6 +32,8 @@
|
|
|
28
32
|
#include "MGLPublicCipher.h"
|
|
29
33
|
#include "MGLPublicCipherInstaller.h"
|
|
30
34
|
#include "MGLRandomHostObject.h"
|
|
35
|
+
#include "MGLSignInstaller.h"
|
|
36
|
+
#include "MGLVerifyInstaller.h"
|
|
31
37
|
#endif
|
|
32
38
|
|
|
33
39
|
namespace margelo {
|
|
@@ -98,6 +104,12 @@ MGLQuickCryptoHostObject::MGLQuickCryptoHostObject(
|
|
|
98
104
|
std::make_shared<MGLRandomHostObject>(jsCallInvoker, workerQueue);
|
|
99
105
|
return jsi::Object::createFromHostObject(runtime, hostObject);
|
|
100
106
|
}));
|
|
107
|
+
|
|
108
|
+
// createSign
|
|
109
|
+
this->fields.push_back(getSignFieldDefinition(jsCallInvoker, workerQueue));
|
|
110
|
+
|
|
111
|
+
// createVerify
|
|
112
|
+
this->fields.push_back(getVerifyFieldDefinition(jsCallInvoker, workerQueue));
|
|
101
113
|
}
|
|
102
114
|
|
|
103
115
|
} // namespace margelo
|