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/cpp/Utils/logs.h
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
#ifdef ANDROID
|
|
2
|
-
// LOGS ANDROID
|
|
3
|
-
#include <android/log.h>
|
|
4
|
-
#define LOG_TAG "react-native-quick-crypto"
|
|
5
|
-
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
|
|
6
|
-
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
|
7
|
-
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
|
8
|
-
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
|
|
9
|
-
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
|
10
|
-
#define LOGSIMPLE(...)
|
|
11
|
-
#else
|
|
12
|
-
// LOGS NO ANDROID
|
|
13
|
-
#include <stdio.h>
|
|
14
|
-
#define LOG_TAG "react-native-quick-crypto"
|
|
15
|
-
#define LOGV(...) \
|
|
16
|
-
printf(" "); \
|
|
17
|
-
printf(__VA_ARGS__); \
|
|
18
|
-
printf("\t - <%s> \n", LOG_TAG);
|
|
19
|
-
#define LOGD(...) \
|
|
20
|
-
printf(" "); \
|
|
21
|
-
printf(__VA_ARGS__); \
|
|
22
|
-
printf("\t - <%s> \n", LOG_TAG);
|
|
23
|
-
#define LOGI(...) \
|
|
24
|
-
printf(" "); \
|
|
25
|
-
printf(__VA_ARGS__); \
|
|
26
|
-
printf("\t - <%s> \n", LOG_TAG);
|
|
27
|
-
#define LOGW(...) \
|
|
28
|
-
printf(" * Warning: "); \
|
|
29
|
-
printf(__VA_ARGS__); \
|
|
30
|
-
printf("\t - <%s> \n", LOG_TAG);
|
|
31
|
-
#define LOGE(...) \
|
|
32
|
-
printf(" *** Error: "); \
|
|
33
|
-
printf(__VA_ARGS__); \
|
|
34
|
-
printf("\t - <%s> \n", LOG_TAG);
|
|
35
|
-
#define LOGSIMPLE(...) \
|
|
36
|
-
printf(" "); \
|
|
37
|
-
printf(__VA_ARGS__);
|
|
38
|
-
#endif // ANDROID
|
package/cpp/Utils/node.h
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 25/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#include "MGLPbkdf2HostObject.h"
|
|
6
|
-
|
|
7
|
-
#ifdef ANDROID
|
|
8
|
-
#include "JSIUtils/MGLTypedArray.h"
|
|
9
|
-
#else
|
|
10
|
-
#include "MGLTypedArray.h"
|
|
11
|
-
#endif
|
|
12
|
-
#include <openssl/dsa.h>
|
|
13
|
-
#include <openssl/ec.h>
|
|
14
|
-
#include <openssl/err.h>
|
|
15
|
-
#include <openssl/evp.h>
|
|
16
|
-
#include <openssl/kdf.h>
|
|
17
|
-
#include <openssl/rsa.h>
|
|
18
|
-
#include <openssl/ssl.h>
|
|
19
|
-
|
|
20
|
-
#include <memory>
|
|
21
|
-
#include <utility>
|
|
22
|
-
|
|
23
|
-
#include "fastpbkdf2.h"
|
|
24
|
-
|
|
25
|
-
namespace margelo {
|
|
26
|
-
namespace jsi = facebook::jsi;
|
|
27
|
-
namespace react = facebook::react;
|
|
28
|
-
|
|
29
|
-
MGLPbkdf2HostObject::MGLPbkdf2HostObject(
|
|
30
|
-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
31
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
|
|
32
|
-
: MGLSmartHostObject(jsCallInvoker, workerQueue) {
|
|
33
|
-
this->fields.push_back(buildPair(
|
|
34
|
-
"pbkdf2", JSIF([this]) {
|
|
35
|
-
if (count != 5) {
|
|
36
|
-
throw jsi::JSError(runtime,
|
|
37
|
-
"fastpbkdf2(..) expects exactly 5 arguments!");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
auto password = arguments[0].asObject(runtime).getArrayBuffer(runtime);
|
|
41
|
-
auto passwordSize = password.size(runtime);
|
|
42
|
-
auto *passwordData = password.data(runtime);
|
|
43
|
-
auto passwordPreventGC =
|
|
44
|
-
std::make_shared<jsi::ArrayBuffer>(std::move(password));
|
|
45
|
-
|
|
46
|
-
auto salt = arguments[1].asObject(runtime).getArrayBuffer(runtime);
|
|
47
|
-
auto saltSize = salt.size(runtime);
|
|
48
|
-
auto *saltData = salt.data(runtime);
|
|
49
|
-
auto saltPreventGC =
|
|
50
|
-
std::make_shared<jsi::ArrayBuffer>(std::move(salt));
|
|
51
|
-
|
|
52
|
-
auto iterations = arguments[2].asNumber();
|
|
53
|
-
auto keyLength = arguments[3].asNumber();
|
|
54
|
-
auto hashAlgorithm = arguments[4].asString(runtime).utf8(runtime);
|
|
55
|
-
|
|
56
|
-
MGLTypedArray<MGLTypedArrayKind::Uint8Array> resultArray(
|
|
57
|
-
runtime, static_cast<size_t>(keyLength));
|
|
58
|
-
auto result = resultArray.getBuffer(runtime);
|
|
59
|
-
auto resultSize = result.size(runtime);
|
|
60
|
-
auto *resultData = result.data(runtime);
|
|
61
|
-
auto resultPreventGC =
|
|
62
|
-
std::make_shared<jsi::ArrayBuffer>(std::move(result));
|
|
63
|
-
|
|
64
|
-
return react::createPromiseAsJSIValue(
|
|
65
|
-
runtime, [=](jsi::Runtime &runtime,
|
|
66
|
-
std::shared_ptr<react::Promise> promise) {
|
|
67
|
-
// TODO(Szymon) implement proper errors
|
|
68
|
-
this->runOnWorkerThread([=]() {
|
|
69
|
-
if (hashAlgorithm == "sha1") {
|
|
70
|
-
fastpbkdf2_hmac_sha1(passwordData, passwordSize, saltData,
|
|
71
|
-
saltSize,
|
|
72
|
-
static_cast<uint32_t>(iterations),
|
|
73
|
-
resultData, resultSize);
|
|
74
|
-
} else if (hashAlgorithm == "sha256") {
|
|
75
|
-
fastpbkdf2_hmac_sha256(passwordData, passwordSize, saltData,
|
|
76
|
-
saltSize,
|
|
77
|
-
static_cast<uint32_t>(iterations),
|
|
78
|
-
resultData, resultSize);
|
|
79
|
-
} else if (hashAlgorithm == "sha512") {
|
|
80
|
-
fastpbkdf2_hmac_sha512(passwordData, passwordSize, saltData,
|
|
81
|
-
saltSize,
|
|
82
|
-
static_cast<uint32_t>(iterations),
|
|
83
|
-
resultData, resultSize);
|
|
84
|
-
} else {
|
|
85
|
-
auto *digest = EVP_get_digestbyname(hashAlgorithm.c_str());
|
|
86
|
-
if (digest == nullptr) {
|
|
87
|
-
this->runOnJSThread([=]() {
|
|
88
|
-
promise->reject("Invalid hash-algorithm!");
|
|
89
|
-
auto preventGC = passwordPreventGC;
|
|
90
|
-
auto preventGC2 = saltPreventGC;
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
char *passAsCharA = reinterpret_cast<char *>(passwordData);
|
|
94
|
-
const unsigned char *saltAsCharA =
|
|
95
|
-
reinterpret_cast<const unsigned char *>(saltData);
|
|
96
|
-
unsigned char *resultAsCharA =
|
|
97
|
-
reinterpret_cast<unsigned char *>(resultData);
|
|
98
|
-
PKCS5_PBKDF2_HMAC(passAsCharA, passwordSize, saltAsCharA,
|
|
99
|
-
saltSize, static_cast<uint32_t>(iterations),
|
|
100
|
-
digest, resultSize, resultAsCharA);
|
|
101
|
-
}
|
|
102
|
-
this->runOnJSThread([=]() {
|
|
103
|
-
promise->resolve(
|
|
104
|
-
jsi::ArrayBuffer(std::move(*resultPreventGC)));
|
|
105
|
-
auto preventGC = passwordPreventGC;
|
|
106
|
-
auto preventGC2 = saltPreventGC;
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
return resultArray;
|
|
112
|
-
}));
|
|
113
|
-
|
|
114
|
-
this->fields.push_back(HOST_LAMBDA("pbkdf2Sync", {
|
|
115
|
-
if (count != 5) {
|
|
116
|
-
throw jsi::JSError(runtime,
|
|
117
|
-
"fastpbkdf2Sync(..) expects exactly 5 arguments!");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
auto password = arguments[0].asObject(runtime).getArrayBuffer(runtime);
|
|
121
|
-
auto salt = arguments[1].asObject(runtime).getArrayBuffer(runtime);
|
|
122
|
-
auto iterations = arguments[2].asNumber();
|
|
123
|
-
auto keyLength = arguments[3].asNumber();
|
|
124
|
-
auto hashAlgorithm = arguments[4].asString(runtime).utf8(runtime);
|
|
125
|
-
|
|
126
|
-
MGLTypedArray<MGLTypedArrayKind::Uint8Array> resultArray(
|
|
127
|
-
runtime, static_cast<size_t>(keyLength));
|
|
128
|
-
auto result = resultArray.getBuffer(runtime);
|
|
129
|
-
|
|
130
|
-
if (hashAlgorithm == "sha1") {
|
|
131
|
-
fastpbkdf2_hmac_sha1(password.data(runtime), password.size(runtime),
|
|
132
|
-
salt.data(runtime), salt.size(runtime),
|
|
133
|
-
static_cast<uint32_t>(iterations),
|
|
134
|
-
result.data(runtime), result.size(runtime));
|
|
135
|
-
} else if (hashAlgorithm == "sha256") {
|
|
136
|
-
fastpbkdf2_hmac_sha256(password.data(runtime), password.size(runtime),
|
|
137
|
-
salt.data(runtime), salt.size(runtime),
|
|
138
|
-
static_cast<uint32_t>(iterations),
|
|
139
|
-
result.data(runtime), result.size(runtime));
|
|
140
|
-
} else if (hashAlgorithm == "sha512") {
|
|
141
|
-
fastpbkdf2_hmac_sha512(password.data(runtime), password.size(runtime),
|
|
142
|
-
salt.data(runtime), salt.size(runtime),
|
|
143
|
-
static_cast<uint32_t>(iterations),
|
|
144
|
-
result.data(runtime), result.size(runtime));
|
|
145
|
-
} else {
|
|
146
|
-
auto *digest = EVP_get_digestbyname(hashAlgorithm.c_str());
|
|
147
|
-
if (digest == nullptr) {
|
|
148
|
-
throw jsi::JSError(runtime, "Invalid hash-algorithm!");
|
|
149
|
-
}
|
|
150
|
-
char *passAsCharA = reinterpret_cast<char *>(password.data(runtime));
|
|
151
|
-
const unsigned char *saltAsCharA =
|
|
152
|
-
reinterpret_cast<const unsigned char *>(salt.data(runtime));
|
|
153
|
-
unsigned char *resultAsCharA =
|
|
154
|
-
reinterpret_cast<unsigned char *>(result.data(runtime));
|
|
155
|
-
PKCS5_PBKDF2_HMAC(passAsCharA, password.size(runtime), saltAsCharA,
|
|
156
|
-
salt.size(runtime), static_cast<uint32_t>(iterations),
|
|
157
|
-
digest, result.size(runtime), resultAsCharA);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return resultArray;
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
} // namespace margelo
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 25/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#ifndef MGL_PBKDF2HOSTOBJECT_H
|
|
6
|
-
#define MGL_PBKDF2HOSTOBJECT_H
|
|
7
|
-
|
|
8
|
-
#include <memory>
|
|
9
|
-
|
|
10
|
-
#ifdef ANDROID
|
|
11
|
-
#include "JSIUtils/MGLSmartHostObject.h"
|
|
12
|
-
#include "fastpbkdf2/fastpbkdf2.h"
|
|
13
|
-
#else
|
|
14
|
-
#include "MGLSmartHostObject.h"
|
|
15
|
-
#include "fastpbkdf2.h"
|
|
16
|
-
#endif
|
|
17
|
-
|
|
18
|
-
namespace margelo {
|
|
19
|
-
namespace jsi = facebook::jsi;
|
|
20
|
-
|
|
21
|
-
class MGLPbkdf2HostObject : public MGLSmartHostObject {
|
|
22
|
-
public:
|
|
23
|
-
MGLPbkdf2HostObject(
|
|
24
|
-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
25
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
} // namespace margelo
|
|
29
|
-
#endif // MGL_PBKDF2HOSTOBJECT_H
|
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* fast-pbkdf2 - Optimal PBKDF2-HMAC calculation
|
|
3
|
-
* Written in 2015 by Joseph Birr-Pixton <jpixton@gmail.com>
|
|
4
|
-
*
|
|
5
|
-
* To the extent possible under law, the author(s) have dedicated all
|
|
6
|
-
* copyright and related and neighboring rights to this software to the
|
|
7
|
-
* public domain worldwide. This software is distributed without any
|
|
8
|
-
* warranty.
|
|
9
|
-
*
|
|
10
|
-
* You should have received a copy of the CC0 Public Domain Dedication
|
|
11
|
-
* along with this software. If not, see
|
|
12
|
-
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
#include "fastpbkdf2.h"
|
|
16
|
-
|
|
17
|
-
#include <assert.h>
|
|
18
|
-
#include <string.h>
|
|
19
|
-
#if defined(__GNUC__)
|
|
20
|
-
#include <endian.h>
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
#include <openssl/sha.h>
|
|
24
|
-
|
|
25
|
-
/* --- MSVC doesn't support C99 --- */
|
|
26
|
-
#ifdef _MSC_VER
|
|
27
|
-
#define restrict
|
|
28
|
-
#define _Pragma __pragma
|
|
29
|
-
#endif
|
|
30
|
-
|
|
31
|
-
/* --- Common useful things --- */
|
|
32
|
-
#define MIN(a, b) ((a) > (b)) ? (b) : (a)
|
|
33
|
-
|
|
34
|
-
static inline void write32_be(uint32_t n, uint8_t out[4]) {
|
|
35
|
-
#if defined(__GNUC__) && __GNUC__ >= 4 && __BYTE_ORDER == __LITTLE_ENDIAN
|
|
36
|
-
*(uint32_t *)(out) = __builtin_bswap32(n);
|
|
37
|
-
#else
|
|
38
|
-
out[0] = (n >> 24) & 0xff;
|
|
39
|
-
out[1] = (n >> 16) & 0xff;
|
|
40
|
-
out[2] = (n >> 8) & 0xff;
|
|
41
|
-
out[3] = n & 0xff;
|
|
42
|
-
#endif
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static inline void write64_be(uint64_t n, uint8_t out[8]) {
|
|
46
|
-
#if defined(__GNUC__) && __GNUC__ >= 4 && __BYTE_ORDER == __LITTLE_ENDIAN
|
|
47
|
-
*(uint64_t *)(out) = __builtin_bswap64(n);
|
|
48
|
-
#else
|
|
49
|
-
write32_be((n >> 32) & 0xffffffff, out);
|
|
50
|
-
write32_be(n & 0xffffffff, out + 4);
|
|
51
|
-
#endif
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/* --- Optional OpenMP parallelisation of consecutive blocks --- */
|
|
55
|
-
#ifdef WITH_OPENMP
|
|
56
|
-
#define OPENMP_PARALLEL_FOR _Pragma("omp parallel for")
|
|
57
|
-
#else
|
|
58
|
-
#define OPENMP_PARALLEL_FOR
|
|
59
|
-
#endif
|
|
60
|
-
|
|
61
|
-
/* Prepare block (of blocksz bytes) to contain md padding denoting a msg-size
|
|
62
|
-
* message (in bytes). block has a prefix of used bytes.
|
|
63
|
-
*
|
|
64
|
-
* Message length is expressed in 32 bits (so suitable for sha1, sha256,
|
|
65
|
-
* sha512). */
|
|
66
|
-
static inline void md_pad(uint8_t *block, size_t blocksz, size_t used,
|
|
67
|
-
size_t msg) {
|
|
68
|
-
memset(block + used, 0, blocksz - used - 4);
|
|
69
|
-
block[used] = 0x80;
|
|
70
|
-
block += blocksz - 4;
|
|
71
|
-
write32_be((uint32_t)(msg * 8), block);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/* Internal function/type names for hash-specific things. */
|
|
75
|
-
#define HMAC_CTX(_name) HMAC_ ## _name ## _ctx
|
|
76
|
-
#define HMAC_INIT(_name) HMAC_ ## _name ## _init
|
|
77
|
-
#define HMAC_UPDATE(_name) HMAC_ ## _name ## _update
|
|
78
|
-
#define HMAC_FINAL(_name) HMAC_ ## _name ## _final
|
|
79
|
-
|
|
80
|
-
#define PBKDF2_F(_name) pbkdf2_f_ ## _name
|
|
81
|
-
#define PBKDF2(_name) pbkdf2_ ## _name
|
|
82
|
-
|
|
83
|
-
/* This macro expands to decls for the whole implementation for a given
|
|
84
|
-
* hash function. Arguments are:
|
|
85
|
-
*
|
|
86
|
-
* _name like 'sha1', added to symbol names
|
|
87
|
-
* _blocksz block size, in bytes
|
|
88
|
-
* _hashsz digest output, in bytes
|
|
89
|
-
* _ctx hash context type
|
|
90
|
-
* _init hash context initialisation function
|
|
91
|
-
* args: (_ctx *c)
|
|
92
|
-
* _update hash context update function
|
|
93
|
-
* args: (_ctx *c, const void *data, size_t ndata)
|
|
94
|
-
* _final hash context finish function
|
|
95
|
-
* args: (void *out, _ctx *c)
|
|
96
|
-
* _xform hash context raw block update function
|
|
97
|
-
* args: (_ctx *c, const void *data)
|
|
98
|
-
* _xcpy hash context raw copy function (only need copy hash state)
|
|
99
|
-
* args: (_ctx * restrict out, const _ctx *restrict in)
|
|
100
|
-
* _xtract hash context state extraction
|
|
101
|
-
* args: args (_ctx *restrict c, uint8_t *restrict out)
|
|
102
|
-
* _xxor hash context xor function (only need xor hash state)
|
|
103
|
-
* args: (_ctx *restrict out, const _ctx *restrict in)
|
|
104
|
-
*
|
|
105
|
-
* The resulting function is named PBKDF2(_name).
|
|
106
|
-
*/
|
|
107
|
-
#define DECL_PBKDF2(_name, _blocksz, _hashsz, _ctx, _init, _update, _xform, \
|
|
108
|
-
_final, _xcpy, _xtract, _xxor) \
|
|
109
|
-
typedef struct { \
|
|
110
|
-
_ctx inner; \
|
|
111
|
-
_ctx outer; \
|
|
112
|
-
} HMAC_CTX(_name); \
|
|
113
|
-
\
|
|
114
|
-
static inline void HMAC_INIT(_name)(HMAC_CTX(_name) * ctx, \
|
|
115
|
-
const uint8_t *key, size_t nkey) { \
|
|
116
|
-
/* Prepare key: */ \
|
|
117
|
-
uint8_t k[_blocksz]; \
|
|
118
|
-
\
|
|
119
|
-
/* Shorten long keys. */ \
|
|
120
|
-
if (nkey > _blocksz) { \
|
|
121
|
-
_init(&ctx->inner); \
|
|
122
|
-
_update(&ctx->inner, key, nkey); \
|
|
123
|
-
_final(k, &ctx->inner); \
|
|
124
|
-
\
|
|
125
|
-
key = k; \
|
|
126
|
-
nkey = _hashsz; \
|
|
127
|
-
} \
|
|
128
|
-
\
|
|
129
|
-
/* Standard doesn't cover case where blocksz < hashsz. */ \
|
|
130
|
-
assert(nkey <= _blocksz); \
|
|
131
|
-
\
|
|
132
|
-
/* Right zero-pad short keys. */ \
|
|
133
|
-
if (k != key) memcpy(k, key, nkey); \
|
|
134
|
-
if (_blocksz > nkey) memset(k + nkey, 0, _blocksz - nkey); \
|
|
135
|
-
\
|
|
136
|
-
/* Start inner hash computation */ \
|
|
137
|
-
uint8_t blk_inner[_blocksz]; \
|
|
138
|
-
uint8_t blk_outer[_blocksz]; \
|
|
139
|
-
\
|
|
140
|
-
for (size_t i = 0; i < _blocksz; i++) { \
|
|
141
|
-
blk_inner[i] = 0x36 ^ k[i]; \
|
|
142
|
-
blk_outer[i] = 0x5c ^ k[i]; \
|
|
143
|
-
} \
|
|
144
|
-
\
|
|
145
|
-
_init(&ctx->inner); \
|
|
146
|
-
_update(&ctx->inner, blk_inner, sizeof blk_inner); \
|
|
147
|
-
\
|
|
148
|
-
/* And outer. */ \
|
|
149
|
-
_init(&ctx->outer); \
|
|
150
|
-
_update(&ctx->outer, blk_outer, sizeof blk_outer); \
|
|
151
|
-
} \
|
|
152
|
-
\
|
|
153
|
-
static inline void HMAC_UPDATE(_name)(HMAC_CTX(_name) * ctx, \
|
|
154
|
-
const void *data, size_t ndata) { \
|
|
155
|
-
_update(&ctx->inner, data, ndata); \
|
|
156
|
-
} \
|
|
157
|
-
\
|
|
158
|
-
static inline void HMAC_FINAL(_name)(HMAC_CTX(_name) * ctx, \
|
|
159
|
-
uint8_t out[_hashsz]) { \
|
|
160
|
-
_final(out, &ctx->inner); \
|
|
161
|
-
_update(&ctx->outer, out, _hashsz); \
|
|
162
|
-
_final(out, &ctx->outer); \
|
|
163
|
-
} \
|
|
164
|
-
\
|
|
165
|
-
/* --- PBKDF2 --- */ \
|
|
166
|
-
static inline void PBKDF2_F(_name)( \
|
|
167
|
-
const HMAC_CTX(_name) * startctx, uint32_t counter, const uint8_t *salt, \
|
|
168
|
-
size_t nsalt, uint32_t iterations, uint8_t *out) { \
|
|
169
|
-
uint8_t countbuf[4]; \
|
|
170
|
-
write32_be(counter, countbuf); \
|
|
171
|
-
\
|
|
172
|
-
/* Prepare loop-invariant padding block. */ \
|
|
173
|
-
uint8_t Ublock[_blocksz]; \
|
|
174
|
-
md_pad(Ublock, _blocksz, _hashsz, _blocksz + _hashsz); \
|
|
175
|
-
\
|
|
176
|
-
/* First iteration: \
|
|
177
|
-
* U_1 = PRF(P, S || INT_32_BE(i)) \
|
|
178
|
-
*/ \
|
|
179
|
-
HMAC_CTX(_name) ctx = *startctx; \
|
|
180
|
-
HMAC_UPDATE(_name)(&ctx, salt, nsalt); \
|
|
181
|
-
HMAC_UPDATE(_name)(&ctx, countbuf, sizeof countbuf); \
|
|
182
|
-
HMAC_FINAL(_name)(&ctx, Ublock); \
|
|
183
|
-
_ctx result = ctx.outer; \
|
|
184
|
-
\
|
|
185
|
-
/* Subsequent iterations: \
|
|
186
|
-
* U_c = PRF(P, U_{c-1}) \
|
|
187
|
-
*/ \
|
|
188
|
-
for (uint32_t i = 1; i < iterations; i++) { \
|
|
189
|
-
/* Complete inner hash with previous U */ \
|
|
190
|
-
_xcpy(&ctx.inner, &startctx->inner); \
|
|
191
|
-
_xform(&ctx.inner, Ublock); \
|
|
192
|
-
_xtract(&ctx.inner, Ublock); \
|
|
193
|
-
/* Complete outer hash with inner output */ \
|
|
194
|
-
_xcpy(&ctx.outer, &startctx->outer); \
|
|
195
|
-
_xform(&ctx.outer, Ublock); \
|
|
196
|
-
_xtract(&ctx.outer, Ublock); \
|
|
197
|
-
_xxor(&result, &ctx.outer); \
|
|
198
|
-
} \
|
|
199
|
-
\
|
|
200
|
-
/* Reform result into output buffer. */ \
|
|
201
|
-
_xtract(&result, out); \
|
|
202
|
-
} \
|
|
203
|
-
\
|
|
204
|
-
static inline void PBKDF2(_name)( \
|
|
205
|
-
const uint8_t *pw, size_t npw, const uint8_t *salt, size_t nsalt, \
|
|
206
|
-
uint32_t iterations, uint8_t *out, size_t nout) { \
|
|
207
|
-
assert(iterations); \
|
|
208
|
-
assert(out &&nout); \
|
|
209
|
-
\
|
|
210
|
-
/* Starting point for inner loop. */ \
|
|
211
|
-
HMAC_CTX(_name) ctx; \
|
|
212
|
-
HMAC_INIT(_name)(&ctx, pw, npw); \
|
|
213
|
-
\
|
|
214
|
-
/* How many blocks do we need? */ \
|
|
215
|
-
uint32_t blocks_needed = (uint32_t)(nout + _hashsz - 1) / _hashsz; \
|
|
216
|
-
\
|
|
217
|
-
OPENMP_PARALLEL_FOR \
|
|
218
|
-
for (uint32_t counter = 1; counter <= blocks_needed; counter++) { \
|
|
219
|
-
uint8_t block[_hashsz]; \
|
|
220
|
-
PBKDF2_F(_name)(&ctx, counter, salt, nsalt, iterations, block); \
|
|
221
|
-
\
|
|
222
|
-
size_t offset = (counter - 1) * _hashsz; \
|
|
223
|
-
size_t taken = MIN(nout - offset, _hashsz); \
|
|
224
|
-
memcpy(out + offset, block, taken); \
|
|
225
|
-
} \
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
static inline void sha1_extract(SHA_CTX *restrict ctx, uint8_t *restrict out) {
|
|
229
|
-
write32_be(ctx->h0, out);
|
|
230
|
-
write32_be(ctx->h1, out + 4);
|
|
231
|
-
write32_be(ctx->h2, out + 8);
|
|
232
|
-
write32_be(ctx->h3, out + 12);
|
|
233
|
-
write32_be(ctx->h4, out + 16);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
static inline void sha1_cpy(SHA_CTX *restrict out, const SHA_CTX *restrict in) {
|
|
237
|
-
out->h0 = in->h0;
|
|
238
|
-
out->h1 = in->h1;
|
|
239
|
-
out->h2 = in->h2;
|
|
240
|
-
out->h3 = in->h3;
|
|
241
|
-
out->h4 = in->h4;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
static inline void sha1_xor(SHA_CTX *restrict out, const SHA_CTX *restrict in) {
|
|
245
|
-
out->h0 ^= in->h0;
|
|
246
|
-
out->h1 ^= in->h1;
|
|
247
|
-
out->h2 ^= in->h2;
|
|
248
|
-
out->h3 ^= in->h3;
|
|
249
|
-
out->h4 ^= in->h4;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
DECL_PBKDF2(sha1, SHA_CBLOCK, SHA_DIGEST_LENGTH, SHA_CTX, SHA1_Init,
|
|
253
|
-
SHA1_Update, SHA1_Transform, SHA1_Final, sha1_cpy, sha1_extract,
|
|
254
|
-
sha1_xor)
|
|
255
|
-
|
|
256
|
-
static inline void sha256_extract(SHA256_CTX *restrict ctx,
|
|
257
|
-
uint8_t *restrict out) {
|
|
258
|
-
write32_be(ctx->h[0], out);
|
|
259
|
-
write32_be(ctx->h[1], out + 4);
|
|
260
|
-
write32_be(ctx->h[2], out + 8);
|
|
261
|
-
write32_be(ctx->h[3], out + 12);
|
|
262
|
-
write32_be(ctx->h[4], out + 16);
|
|
263
|
-
write32_be(ctx->h[5], out + 20);
|
|
264
|
-
write32_be(ctx->h[6], out + 24);
|
|
265
|
-
write32_be(ctx->h[7], out + 28);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
static inline void sha256_cpy(SHA256_CTX *restrict out,
|
|
269
|
-
const SHA256_CTX *restrict in) {
|
|
270
|
-
out->h[0] = in->h[0];
|
|
271
|
-
out->h[1] = in->h[1];
|
|
272
|
-
out->h[2] = in->h[2];
|
|
273
|
-
out->h[3] = in->h[3];
|
|
274
|
-
out->h[4] = in->h[4];
|
|
275
|
-
out->h[5] = in->h[5];
|
|
276
|
-
out->h[6] = in->h[6];
|
|
277
|
-
out->h[7] = in->h[7];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
static inline void sha256_xor(SHA256_CTX *restrict out,
|
|
281
|
-
const SHA256_CTX *restrict in) {
|
|
282
|
-
out->h[0] ^= in->h[0];
|
|
283
|
-
out->h[1] ^= in->h[1];
|
|
284
|
-
out->h[2] ^= in->h[2];
|
|
285
|
-
out->h[3] ^= in->h[3];
|
|
286
|
-
out->h[4] ^= in->h[4];
|
|
287
|
-
out->h[5] ^= in->h[5];
|
|
288
|
-
out->h[6] ^= in->h[6];
|
|
289
|
-
out->h[7] ^= in->h[7];
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
DECL_PBKDF2(sha256, SHA256_CBLOCK, SHA256_DIGEST_LENGTH, SHA256_CTX,
|
|
293
|
-
SHA256_Init, SHA256_Update, SHA256_Transform, SHA256_Final,
|
|
294
|
-
sha256_cpy, sha256_extract, sha256_xor)
|
|
295
|
-
|
|
296
|
-
static inline void sha512_extract(SHA512_CTX *restrict ctx,
|
|
297
|
-
uint8_t *restrict out) {
|
|
298
|
-
write64_be(ctx->h[0], out);
|
|
299
|
-
write64_be(ctx->h[1], out + 8);
|
|
300
|
-
write64_be(ctx->h[2], out + 16);
|
|
301
|
-
write64_be(ctx->h[3], out + 24);
|
|
302
|
-
write64_be(ctx->h[4], out + 32);
|
|
303
|
-
write64_be(ctx->h[5], out + 40);
|
|
304
|
-
write64_be(ctx->h[6], out + 48);
|
|
305
|
-
write64_be(ctx->h[7], out + 56);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
static inline void sha512_cpy(SHA512_CTX *restrict out,
|
|
309
|
-
const SHA512_CTX *restrict in) {
|
|
310
|
-
out->h[0] = in->h[0];
|
|
311
|
-
out->h[1] = in->h[1];
|
|
312
|
-
out->h[2] = in->h[2];
|
|
313
|
-
out->h[3] = in->h[3];
|
|
314
|
-
out->h[4] = in->h[4];
|
|
315
|
-
out->h[5] = in->h[5];
|
|
316
|
-
out->h[6] = in->h[6];
|
|
317
|
-
out->h[7] = in->h[7];
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
static inline void sha512_xor(SHA512_CTX *restrict out,
|
|
321
|
-
const SHA512_CTX *restrict in) {
|
|
322
|
-
out->h[0] ^= in->h[0];
|
|
323
|
-
out->h[1] ^= in->h[1];
|
|
324
|
-
out->h[2] ^= in->h[2];
|
|
325
|
-
out->h[3] ^= in->h[3];
|
|
326
|
-
out->h[4] ^= in->h[4];
|
|
327
|
-
out->h[5] ^= in->h[5];
|
|
328
|
-
out->h[6] ^= in->h[6];
|
|
329
|
-
out->h[7] ^= in->h[7];
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
DECL_PBKDF2(sha512, SHA512_CBLOCK, SHA512_DIGEST_LENGTH, SHA512_CTX,
|
|
333
|
-
SHA512_Init, SHA512_Update, SHA512_Transform, SHA512_Final,
|
|
334
|
-
sha512_cpy, sha512_extract, sha512_xor)
|
|
335
|
-
|
|
336
|
-
void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw, const uint8_t *salt,
|
|
337
|
-
size_t nsalt, uint32_t iterations, uint8_t *out,
|
|
338
|
-
size_t nout) {
|
|
339
|
-
PBKDF2(sha1)(pw, npw, salt, nsalt, iterations, out, nout);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
void fastpbkdf2_hmac_sha256(const uint8_t *pw, size_t npw, const uint8_t *salt,
|
|
343
|
-
size_t nsalt, uint32_t iterations, uint8_t *out,
|
|
344
|
-
size_t nout) {
|
|
345
|
-
PBKDF2(sha256)(pw, npw, salt, nsalt, iterations, out, nout);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
void fastpbkdf2_hmac_sha512(const uint8_t *pw, size_t npw, const uint8_t *salt,
|
|
349
|
-
size_t nsalt, uint32_t iterations, uint8_t *out,
|
|
350
|
-
size_t nout) {
|
|
351
|
-
PBKDF2(sha512)(pw, npw, salt, nsalt, iterations, out, nout);
|
|
352
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* fastpbkdf2 - Faster PBKDF2-HMAC calculation
|
|
3
|
-
* Written in 2015 by Joseph Birr-Pixton <jpixton@gmail.com>
|
|
4
|
-
*
|
|
5
|
-
* To the extent possible under law, the author(s) have dedicated all
|
|
6
|
-
* copyright and related and neighboring rights to this software to the
|
|
7
|
-
* public domain worldwide. This software is distributed without any
|
|
8
|
-
* warranty.
|
|
9
|
-
*
|
|
10
|
-
* You should have received a copy of the CC0 Public Domain Dedication
|
|
11
|
-
* along with this software. If not, see
|
|
12
|
-
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
#ifndef FASTPBKDF2_H
|
|
16
|
-
#define FASTPBKDF2_H
|
|
17
|
-
|
|
18
|
-
#include <stdint.h>
|
|
19
|
-
#include <stdlib.h>
|
|
20
|
-
|
|
21
|
-
#ifdef __cplusplus
|
|
22
|
-
extern "C" {
|
|
23
|
-
#endif
|
|
24
|
-
|
|
25
|
-
/** Calculates PBKDF2-HMAC-SHA1.
|
|
26
|
-
*
|
|
27
|
-
* @p npw bytes at @p pw are the password input.
|
|
28
|
-
* @p nsalt bytes at @p salt are the salt input.
|
|
29
|
-
* @p iterations is the PBKDF2 iteration count and must be non-zero.
|
|
30
|
-
* @p nout bytes of output are written to @p out. @p nout must be non-zero.
|
|
31
|
-
*
|
|
32
|
-
* This function cannot fail; it does not report errors.
|
|
33
|
-
*/
|
|
34
|
-
void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw, const uint8_t *salt,
|
|
35
|
-
size_t nsalt, uint32_t iterations, uint8_t *out,
|
|
36
|
-
size_t nout);
|
|
37
|
-
|
|
38
|
-
/** Calculates PBKDF2-HMAC-SHA256.
|
|
39
|
-
*
|
|
40
|
-
* @p npw bytes at @p pw are the password input.
|
|
41
|
-
* @p nsalt bytes at @p salt are the salt input.
|
|
42
|
-
* @p iterations is the PBKDF2 iteration count and must be non-zero.
|
|
43
|
-
* @p nout bytes of output are written to @p out. @p nout must be non-zero.
|
|
44
|
-
*
|
|
45
|
-
* This function cannot fail; it does not report errors.
|
|
46
|
-
*/
|
|
47
|
-
void fastpbkdf2_hmac_sha256(const uint8_t *pw, size_t npw, const uint8_t *salt,
|
|
48
|
-
size_t nsalt, uint32_t iterations, uint8_t *out,
|
|
49
|
-
size_t nout);
|
|
50
|
-
|
|
51
|
-
/** Calculates PBKDF2-HMAC-SHA512.
|
|
52
|
-
*
|
|
53
|
-
* @p npw bytes at @p pw are the password input.
|
|
54
|
-
* @p nsalt bytes at @p salt are the salt input.
|
|
55
|
-
* @p iterations is the PBKDF2 iteration count and must be non-zero.
|
|
56
|
-
* @p nout bytes of output are written to @p out. @p nout must be non-zero.
|
|
57
|
-
*
|
|
58
|
-
* This function cannot fail; it does not report errors.
|
|
59
|
-
*/
|
|
60
|
-
void fastpbkdf2_hmac_sha512(const uint8_t *pw, size_t npw, const uint8_t *salt,
|
|
61
|
-
size_t nsalt, uint32_t iterations, uint8_t *out,
|
|
62
|
-
size_t nout);
|
|
63
|
-
|
|
64
|
-
#ifdef __cplusplus
|
|
65
|
-
}
|
|
66
|
-
#endif
|
|
67
|
-
|
|
68
|
-
#endif
|