react-native-quick-crypto 1.0.8 → 1.0.10
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 +56 -6
- package/README.md +17 -11
- package/android/CMakeLists.txt +4 -0
- package/android/build.gradle +3 -0
- package/cpp/cipher/HybridCipherFactory.hpp +15 -1
- package/cpp/cipher/OCBCipher.cpp +4 -4
- package/cpp/cipher/XChaCha20Poly1305Cipher.cpp +161 -0
- package/cpp/cipher/XChaCha20Poly1305Cipher.hpp +43 -0
- package/cpp/cipher/XSalsa20Poly1305Cipher.cpp +145 -0
- package/cpp/cipher/XSalsa20Poly1305Cipher.hpp +42 -0
- package/cpp/dh/HybridDiffieHellman.cpp +10 -0
- package/cpp/dh/HybridDiffieHellman.hpp +1 -0
- package/cpp/ec/HybridEcKeyPair.cpp +21 -0
- package/cpp/ec/HybridEcKeyPair.hpp +1 -0
- package/cpp/hash/HybridHash.cpp +1 -1
- package/cpp/hash/HybridHash.hpp +1 -1
- package/cpp/hmac/HybridHmac.cpp +1 -1
- package/cpp/hmac/HybridHmac.hpp +1 -1
- package/cpp/keys/HybridKeyObjectHandle.cpp +112 -1
- package/cpp/keys/HybridKeyObjectHandle.hpp +5 -1
- package/deps/ncrypto/.bazelrc +0 -1
- package/deps/ncrypto/.bazelversion +1 -1
- package/deps/ncrypto/.github/workflows/commitlint.yml +16 -0
- package/deps/ncrypto/.github/workflows/linter.yml +2 -2
- package/deps/ncrypto/.github/workflows/release-please.yml +16 -0
- package/deps/ncrypto/.github/workflows/ubuntu.yml +82 -0
- package/deps/ncrypto/.release-please-manifest.json +3 -0
- package/deps/ncrypto/BUILD.bazel +9 -1
- package/deps/ncrypto/CHANGELOG.md +37 -0
- package/deps/ncrypto/CMakeLists.txt +35 -11
- package/deps/ncrypto/MODULE.bazel +16 -1
- package/deps/ncrypto/MODULE.bazel.lock +299 -118
- package/deps/ncrypto/cmake/ncrypto-flags.cmake +1 -0
- package/deps/ncrypto/include/ncrypto/aead.h +137 -0
- package/deps/ncrypto/include/ncrypto/version.h +14 -0
- package/deps/ncrypto/include/ncrypto.h +85 -230
- package/deps/ncrypto/ncrypto.pc.in +10 -0
- package/deps/ncrypto/release-please-config.json +11 -0
- package/deps/ncrypto/src/CMakeLists.txt +31 -6
- package/deps/ncrypto/src/aead.cpp +302 -0
- package/deps/ncrypto/src/ncrypto.cpp +274 -556
- package/deps/ncrypto/tests/BUILD.bazel +2 -0
- package/deps/ncrypto/tests/basic.cpp +772 -2
- package/deps/ncrypto/tools/run-clang-format.sh +5 -5
- package/lib/commonjs/diffie-hellman.js +4 -1
- package/lib/commonjs/diffie-hellman.js.map +1 -1
- package/lib/commonjs/ec.js +20 -25
- package/lib/commonjs/ec.js.map +1 -1
- package/lib/commonjs/ed.js +1 -2
- package/lib/commonjs/ed.js.map +1 -1
- package/lib/commonjs/hash.js +7 -0
- package/lib/commonjs/hash.js.map +1 -1
- package/lib/commonjs/index.js +24 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/classes.js +9 -5
- package/lib/commonjs/keys/classes.js.map +1 -1
- package/lib/commonjs/subtle.js +82 -31
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/module/diffie-hellman.js +4 -0
- package/lib/module/diffie-hellman.js.map +1 -1
- package/lib/module/ec.js +19 -25
- package/lib/module/ec.js.map +1 -1
- package/lib/module/ed.js +1 -2
- package/lib/module/ed.js.map +1 -1
- package/lib/module/hash.js +6 -0
- package/lib/module/hash.js.map +1 -1
- package/lib/module/index.js +10 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/classes.js +9 -5
- package/lib/module/keys/classes.js.map +1 -1
- package/lib/module/subtle.js +83 -32
- package/lib/module/subtle.js.map +1 -1
- package/lib/module/utils/types.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/diffie-hellman.d.ts +2 -0
- package/lib/typescript/diffie-hellman.d.ts.map +1 -1
- package/lib/typescript/ec.d.ts +1 -0
- package/lib/typescript/ec.d.ts.map +1 -1
- package/lib/typescript/ed.d.ts.map +1 -1
- package/lib/typescript/hash.d.ts +2 -0
- package/lib/typescript/hash.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +7 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/classes.d.ts +2 -0
- package/lib/typescript/keys/classes.d.ts.map +1 -1
- package/lib/typescript/specs/diffie-hellman.nitro.d.ts +1 -0
- package/lib/typescript/specs/diffie-hellman.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/ecKeyPair.nitro.d.ts +1 -0
- package/lib/typescript/specs/ecKeyPair.nitro.d.ts.map +1 -1
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +2 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -1
- package/lib/typescript/subtle.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +12 -5
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +8 -5
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +1 -1
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +54 -54
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +1 -1
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +2 -2
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +54 -54
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +5 -1
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +1 -1
- package/nitrogen/generated/shared/c++/CipherArgs.hpp +34 -19
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridHashSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridHashSpec.hpp +2 -4
- package/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridHkdfSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridHmacSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +3 -4
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +3 -1
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +8 -4
- package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridScryptSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridScryptSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp +2 -3
- package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp +1 -3
- package/nitrogen/generated/shared/c++/JWK.hpp +84 -68
- package/nitrogen/generated/shared/c++/JWKkty.hpp +5 -1
- package/nitrogen/generated/shared/c++/JWKuse.hpp +1 -1
- package/nitrogen/generated/shared/c++/KFormatType.hpp +1 -1
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +39 -23
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +1 -1
- package/nitrogen/generated/shared/c++/KeyObject.hpp +21 -5
- package/nitrogen/generated/shared/c++/KeyType.hpp +1 -1
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +1 -1
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +1 -1
- package/package.json +10 -7
- package/src/diffie-hellman.ts +6 -0
- package/src/ec.ts +23 -19
- package/src/ed.ts +1 -2
- package/src/hash.ts +11 -0
- package/src/index.ts +9 -0
- package/src/keys/classes.ts +10 -3
- package/src/specs/diffie-hellman.nitro.ts +1 -0
- package/src/specs/ecKeyPair.nitro.ts +2 -0
- package/src/specs/keyObjectHandle.nitro.ts +2 -0
- package/src/subtle.ts +131 -32
- package/src/utils/types.ts +18 -3
- package/deps/ncrypto/WORKSPACE +0 -15
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include <ncrypto.h>
|
|
2
|
+
#include <ncrypto/aead.h>
|
|
2
3
|
|
|
3
4
|
#include <gtest/gtest.h>
|
|
4
5
|
#include <string>
|
|
@@ -37,8 +38,493 @@ TEST(basic, cipher_foreach) {
|
|
|
37
38
|
// as that depends on openssl vs boringssl, versions, configuration, etc.
|
|
38
39
|
// Instead, we look for a couple of very common ciphers that should always be
|
|
39
40
|
// present.
|
|
40
|
-
ASSERT_TRUE(foundCiphers.count("
|
|
41
|
-
|
|
41
|
+
ASSERT_TRUE(foundCiphers.count("aes-128-ctr") ||
|
|
42
|
+
foundCiphers.count("AES-128-CTR"));
|
|
43
|
+
ASSERT_TRUE(foundCiphers.count("aes-256-cbc") ||
|
|
44
|
+
foundCiphers.count("AES-256-CBC"));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
TEST(BignumPointer, bitLength) {
|
|
48
|
+
// Test empty/null BignumPointer
|
|
49
|
+
BignumPointer empty;
|
|
50
|
+
ASSERT_EQ(empty.bitLength(), 0);
|
|
51
|
+
|
|
52
|
+
// Test zero value
|
|
53
|
+
auto zero = BignumPointer::New();
|
|
54
|
+
ASSERT_TRUE(zero);
|
|
55
|
+
ASSERT_TRUE(zero.setWord(0));
|
|
56
|
+
ASSERT_EQ(zero.bitLength(), 0);
|
|
57
|
+
|
|
58
|
+
// Test value 1 (1 bit)
|
|
59
|
+
auto one = BignumPointer::New();
|
|
60
|
+
ASSERT_TRUE(one);
|
|
61
|
+
ASSERT_TRUE(one.setWord(1));
|
|
62
|
+
ASSERT_EQ(one.bitLength(), 1);
|
|
63
|
+
|
|
64
|
+
// Test value 2 (2 bits: 10 in binary)
|
|
65
|
+
auto two = BignumPointer::New();
|
|
66
|
+
ASSERT_TRUE(two);
|
|
67
|
+
ASSERT_TRUE(two.setWord(2));
|
|
68
|
+
ASSERT_EQ(two.bitLength(), 2);
|
|
69
|
+
|
|
70
|
+
// Test value 255 (8 bits: 11111111 in binary)
|
|
71
|
+
auto byte = BignumPointer::New();
|
|
72
|
+
ASSERT_TRUE(byte);
|
|
73
|
+
ASSERT_TRUE(byte.setWord(255));
|
|
74
|
+
ASSERT_EQ(byte.bitLength(), 8);
|
|
75
|
+
|
|
76
|
+
// Test value 256 (9 bits: 100000000 in binary)
|
|
77
|
+
auto nineBits = BignumPointer::New();
|
|
78
|
+
ASSERT_TRUE(nineBits);
|
|
79
|
+
ASSERT_TRUE(nineBits.setWord(256));
|
|
80
|
+
ASSERT_EQ(nineBits.bitLength(), 9);
|
|
81
|
+
|
|
82
|
+
// Test larger value (0xFFFFFFFF = 32 bits)
|
|
83
|
+
auto thirtyTwoBits = BignumPointer::New();
|
|
84
|
+
ASSERT_TRUE(thirtyTwoBits);
|
|
85
|
+
ASSERT_TRUE(thirtyTwoBits.setWord(0xFFFFFFFF));
|
|
86
|
+
ASSERT_EQ(thirtyTwoBits.bitLength(), 32);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
TEST(BignumPointer, byteLength) {
|
|
90
|
+
// Test empty/null BignumPointer
|
|
91
|
+
BignumPointer empty;
|
|
92
|
+
ASSERT_EQ(empty.byteLength(), 0);
|
|
93
|
+
|
|
94
|
+
// Test zero value
|
|
95
|
+
auto zero = BignumPointer::New();
|
|
96
|
+
ASSERT_TRUE(zero);
|
|
97
|
+
ASSERT_TRUE(zero.setWord(0));
|
|
98
|
+
ASSERT_EQ(zero.byteLength(), 0);
|
|
99
|
+
|
|
100
|
+
// Test value 1 (1 byte)
|
|
101
|
+
auto one = BignumPointer::New();
|
|
102
|
+
ASSERT_TRUE(one);
|
|
103
|
+
ASSERT_TRUE(one.setWord(1));
|
|
104
|
+
ASSERT_EQ(one.byteLength(), 1);
|
|
105
|
+
|
|
106
|
+
// Test value 255 (1 byte)
|
|
107
|
+
auto byte = BignumPointer::New();
|
|
108
|
+
ASSERT_TRUE(byte);
|
|
109
|
+
ASSERT_TRUE(byte.setWord(255));
|
|
110
|
+
ASSERT_EQ(byte.byteLength(), 1);
|
|
111
|
+
|
|
112
|
+
// Test value 256 (2 bytes)
|
|
113
|
+
auto twoBytes = BignumPointer::New();
|
|
114
|
+
ASSERT_TRUE(twoBytes);
|
|
115
|
+
ASSERT_TRUE(twoBytes.setWord(256));
|
|
116
|
+
ASSERT_EQ(twoBytes.byteLength(), 2);
|
|
117
|
+
|
|
118
|
+
// Test larger value (0xFFFFFFFF = 4 bytes)
|
|
119
|
+
auto fourBytes = BignumPointer::New();
|
|
120
|
+
ASSERT_TRUE(fourBytes);
|
|
121
|
+
ASSERT_TRUE(fourBytes.setWord(0xFFFFFFFF));
|
|
122
|
+
ASSERT_EQ(fourBytes.byteLength(), 4);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ============================================================================
|
|
126
|
+
// Ec class tests
|
|
127
|
+
|
|
128
|
+
// Helper to create an EC key for testing
|
|
129
|
+
static ECKeyPointer createTestEcKey() {
|
|
130
|
+
// NID_X9_62_prime256v1 is P-256
|
|
131
|
+
auto key = ECKeyPointer::NewByCurveName(NID_X9_62_prime256v1);
|
|
132
|
+
if (key && EC_KEY_generate_key(key.get())) {
|
|
133
|
+
return key;
|
|
134
|
+
}
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
TEST(Ec, getDegree) {
|
|
139
|
+
auto ecKey = createTestEcKey();
|
|
140
|
+
ASSERT_TRUE(ecKey);
|
|
141
|
+
|
|
142
|
+
Ec ec(ecKey.get());
|
|
143
|
+
ASSERT_TRUE(ec);
|
|
144
|
+
|
|
145
|
+
// P-256 has degree 256
|
|
146
|
+
ASSERT_EQ(ec.getDegree(), 256u);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
TEST(Ec, getCurveName) {
|
|
150
|
+
auto ecKey = createTestEcKey();
|
|
151
|
+
ASSERT_TRUE(ecKey);
|
|
152
|
+
|
|
153
|
+
Ec ec(ecKey.get());
|
|
154
|
+
ASSERT_TRUE(ec);
|
|
155
|
+
|
|
156
|
+
// P-256 is also known as prime256v1
|
|
157
|
+
std::string name = ec.getCurveName();
|
|
158
|
+
ASSERT_TRUE(name == "prime256v1" || name == "P-256");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
TEST(Ec, getPublicKey) {
|
|
162
|
+
auto ecKey = createTestEcKey();
|
|
163
|
+
ASSERT_TRUE(ecKey);
|
|
164
|
+
|
|
165
|
+
Ec ec(ecKey.get());
|
|
166
|
+
ASSERT_TRUE(ec);
|
|
167
|
+
|
|
168
|
+
// Public key should exist
|
|
169
|
+
const EC_POINT* pubKey = ec.getPublicKey();
|
|
170
|
+
ASSERT_NE(pubKey, nullptr);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
TEST(Ec, getPrivateKey) {
|
|
174
|
+
auto ecKey = createTestEcKey();
|
|
175
|
+
ASSERT_TRUE(ecKey);
|
|
176
|
+
|
|
177
|
+
Ec ec(ecKey.get());
|
|
178
|
+
ASSERT_TRUE(ec);
|
|
179
|
+
|
|
180
|
+
// Private key should exist for a generated key
|
|
181
|
+
const BIGNUM* privKey = ec.getPrivateKey();
|
|
182
|
+
ASSERT_NE(privKey, nullptr);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
TEST(Ec, getXYCoordinates) {
|
|
186
|
+
auto ecKey = createTestEcKey();
|
|
187
|
+
ASSERT_TRUE(ecKey);
|
|
188
|
+
|
|
189
|
+
Ec ec(ecKey.get());
|
|
190
|
+
ASSERT_TRUE(ec);
|
|
191
|
+
|
|
192
|
+
// X and Y coordinates should be populated
|
|
193
|
+
const BignumPointer& x = ec.getX();
|
|
194
|
+
const BignumPointer& y = ec.getY();
|
|
195
|
+
|
|
196
|
+
ASSERT_TRUE(x);
|
|
197
|
+
ASSERT_TRUE(y);
|
|
198
|
+
|
|
199
|
+
// For P-256, coordinates should be 256 bits (32 bytes)
|
|
200
|
+
ASSERT_GT(x.byteLength(), 0u);
|
|
201
|
+
ASSERT_LE(x.byteLength(), 32u);
|
|
202
|
+
ASSERT_GT(y.byteLength(), 0u);
|
|
203
|
+
ASSERT_LE(y.byteLength(), 32u);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
TEST(Ec, getCurve) {
|
|
207
|
+
auto ecKey = createTestEcKey();
|
|
208
|
+
ASSERT_TRUE(ecKey);
|
|
209
|
+
|
|
210
|
+
Ec ec(ecKey.get());
|
|
211
|
+
ASSERT_TRUE(ec);
|
|
212
|
+
|
|
213
|
+
// getCurve should return the NID for P-256
|
|
214
|
+
int curve = ec.getCurve();
|
|
215
|
+
ASSERT_EQ(curve, NID_X9_62_prime256v1);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
TEST(Ec, GetCurves) {
|
|
219
|
+
std::vector<std::string> curves;
|
|
220
|
+
|
|
221
|
+
bool result = Ec::GetCurves([&](const char* name) {
|
|
222
|
+
curves.push_back(name);
|
|
223
|
+
return true;
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
ASSERT_TRUE(result);
|
|
227
|
+
// Should have at least some built-in curves
|
|
228
|
+
ASSERT_GT(curves.size(), 0u);
|
|
229
|
+
|
|
230
|
+
// Check that common curves are present
|
|
231
|
+
bool hasP256 = false;
|
|
232
|
+
bool hasP384 = false;
|
|
233
|
+
for (const auto& curve : curves) {
|
|
234
|
+
if (curve == "prime256v1" || curve == "P-256") hasP256 = true;
|
|
235
|
+
if (curve == "secp384r1" || curve == "P-384") hasP384 = true;
|
|
236
|
+
}
|
|
237
|
+
ASSERT_TRUE(hasP256);
|
|
238
|
+
ASSERT_TRUE(hasP384);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
TEST(Ec, GetCurves_early_exit) {
|
|
242
|
+
int count = 0;
|
|
243
|
+
|
|
244
|
+
// Test that returning false stops iteration
|
|
245
|
+
bool result = Ec::GetCurves([&](const char* name) {
|
|
246
|
+
count++;
|
|
247
|
+
return count < 3; // Stop after 2 curves
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
ASSERT_FALSE(result);
|
|
251
|
+
ASSERT_EQ(count, 3);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// ============================================================================
|
|
255
|
+
// EVPKeyPointer tests
|
|
256
|
+
|
|
257
|
+
TEST(EVPKeyPointer, operatorEc) {
|
|
258
|
+
auto ecKey = createTestEcKey();
|
|
259
|
+
ASSERT_TRUE(ecKey);
|
|
260
|
+
|
|
261
|
+
// Create EVPKeyPointer from EC_KEY
|
|
262
|
+
EVPKeyPointer key(EVP_PKEY_new());
|
|
263
|
+
ASSERT_TRUE(key);
|
|
264
|
+
ASSERT_TRUE(EVP_PKEY_set1_EC_KEY(key.get(), ecKey.get()));
|
|
265
|
+
|
|
266
|
+
// Convert to Ec
|
|
267
|
+
Ec ec = key;
|
|
268
|
+
ASSERT_TRUE(ec);
|
|
269
|
+
ASSERT_EQ(ec.getDegree(), 256u);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
TEST(EVPKeyPointer, clone) {
|
|
273
|
+
auto ecKey = createTestEcKey();
|
|
274
|
+
ASSERT_TRUE(ecKey);
|
|
275
|
+
|
|
276
|
+
// Create EVPKeyPointer from EC_KEY
|
|
277
|
+
EVPKeyPointer key(EVP_PKEY_new());
|
|
278
|
+
ASSERT_TRUE(key);
|
|
279
|
+
ASSERT_TRUE(EVP_PKEY_set1_EC_KEY(key.get(), ecKey.get()));
|
|
280
|
+
|
|
281
|
+
// Clone the key
|
|
282
|
+
auto cloned = key.clone();
|
|
283
|
+
ASSERT_TRUE(cloned);
|
|
284
|
+
|
|
285
|
+
// Both should be valid
|
|
286
|
+
ASSERT_TRUE(key);
|
|
287
|
+
ASSERT_TRUE(cloned);
|
|
288
|
+
|
|
289
|
+
// Both should have the same key type
|
|
290
|
+
ASSERT_EQ(key.id(), cloned.id());
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
TEST(EVPKeyPointer, cloneEmpty) {
|
|
294
|
+
EVPKeyPointer empty;
|
|
295
|
+
ASSERT_FALSE(empty);
|
|
296
|
+
|
|
297
|
+
// Clone of empty should be empty
|
|
298
|
+
auto cloned = empty.clone();
|
|
299
|
+
ASSERT_FALSE(cloned);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ============================================================================
|
|
303
|
+
// KDF tests
|
|
304
|
+
|
|
305
|
+
TEST(KDF, pbkdf2Into) {
|
|
306
|
+
const char* password = "password";
|
|
307
|
+
const unsigned char salt[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
|
308
|
+
const size_t length = 32;
|
|
309
|
+
|
|
310
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
311
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
312
|
+
|
|
313
|
+
unsigned char output[32];
|
|
314
|
+
Buffer<unsigned char> outBuf{output, length};
|
|
315
|
+
|
|
316
|
+
Digest md(EVP_sha256());
|
|
317
|
+
ASSERT_TRUE(md);
|
|
318
|
+
|
|
319
|
+
bool result = pbkdf2Into(md, passBuf, saltBuf, 1000, length, &outBuf);
|
|
320
|
+
ASSERT_TRUE(result);
|
|
321
|
+
|
|
322
|
+
// Verify output is not all zeros
|
|
323
|
+
bool allZeros = true;
|
|
324
|
+
for (size_t i = 0; i < length; i++) {
|
|
325
|
+
if (output[i] != 0) {
|
|
326
|
+
allZeros = false;
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
ASSERT_FALSE(allZeros);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
TEST(KDF, pbkdf2) {
|
|
334
|
+
const char* password = "password";
|
|
335
|
+
const unsigned char salt[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
|
336
|
+
const size_t length = 32;
|
|
337
|
+
|
|
338
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
339
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
340
|
+
|
|
341
|
+
Digest md(EVP_sha256());
|
|
342
|
+
ASSERT_TRUE(md);
|
|
343
|
+
|
|
344
|
+
auto result = pbkdf2(md, passBuf, saltBuf, 1000, length);
|
|
345
|
+
ASSERT_TRUE(result);
|
|
346
|
+
ASSERT_EQ(result.size(), length);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
TEST(KDF, scryptInto) {
|
|
350
|
+
const char* password = "password";
|
|
351
|
+
const unsigned char salt[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
|
352
|
+
const size_t length = 32;
|
|
353
|
+
|
|
354
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
355
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
356
|
+
|
|
357
|
+
unsigned char output[32];
|
|
358
|
+
Buffer<unsigned char> outBuf{output, length};
|
|
359
|
+
|
|
360
|
+
// Use small parameters for testing
|
|
361
|
+
bool result = scryptInto(passBuf, saltBuf, 16, 1, 1, 0, length, &outBuf);
|
|
362
|
+
ASSERT_TRUE(result);
|
|
363
|
+
|
|
364
|
+
// Verify output is not all zeros
|
|
365
|
+
bool allZeros = true;
|
|
366
|
+
for (size_t i = 0; i < length; i++) {
|
|
367
|
+
if (output[i] != 0) {
|
|
368
|
+
allZeros = false;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
ASSERT_FALSE(allZeros);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
TEST(KDF, scrypt) {
|
|
376
|
+
const char* password = "password";
|
|
377
|
+
const unsigned char salt[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
|
378
|
+
const size_t length = 32;
|
|
379
|
+
|
|
380
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
381
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
382
|
+
|
|
383
|
+
// Use small parameters for testing
|
|
384
|
+
auto result = scrypt(passBuf, saltBuf, 16, 1, 1, 0, length);
|
|
385
|
+
ASSERT_TRUE(result);
|
|
386
|
+
ASSERT_EQ(result.size(), length);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
TEST(KDF, hkdfInfo) {
|
|
390
|
+
const unsigned char key[] = {0x0b,
|
|
391
|
+
0x0b,
|
|
392
|
+
0x0b,
|
|
393
|
+
0x0b,
|
|
394
|
+
0x0b,
|
|
395
|
+
0x0b,
|
|
396
|
+
0x0b,
|
|
397
|
+
0x0b,
|
|
398
|
+
0x0b,
|
|
399
|
+
0x0b,
|
|
400
|
+
0x0b,
|
|
401
|
+
0x0b,
|
|
402
|
+
0x0b,
|
|
403
|
+
0x0b,
|
|
404
|
+
0x0b,
|
|
405
|
+
0x0b};
|
|
406
|
+
const unsigned char salt[] = {
|
|
407
|
+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
|
|
408
|
+
const unsigned char info[] = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7};
|
|
409
|
+
const size_t length = 42;
|
|
410
|
+
|
|
411
|
+
Buffer<const unsigned char> keyBuf{key, sizeof(key)};
|
|
412
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
413
|
+
Buffer<const unsigned char> infoBuf{info, sizeof(info)};
|
|
414
|
+
|
|
415
|
+
unsigned char output[42];
|
|
416
|
+
Buffer<unsigned char> outBuf{output, length};
|
|
417
|
+
|
|
418
|
+
Digest md(EVP_sha256());
|
|
419
|
+
ASSERT_TRUE(md);
|
|
420
|
+
|
|
421
|
+
bool result = hkdfInfo(md, keyBuf, infoBuf, saltBuf, length, &outBuf);
|
|
422
|
+
ASSERT_TRUE(result);
|
|
423
|
+
|
|
424
|
+
// Verify output is not all zeros
|
|
425
|
+
bool allZeros = true;
|
|
426
|
+
for (size_t i = 0; i < length; i++) {
|
|
427
|
+
if (output[i] != 0) {
|
|
428
|
+
allZeros = false;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
ASSERT_FALSE(allZeros);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
TEST(KDF, hkdf) {
|
|
436
|
+
const unsigned char key[] = {0x0b,
|
|
437
|
+
0x0b,
|
|
438
|
+
0x0b,
|
|
439
|
+
0x0b,
|
|
440
|
+
0x0b,
|
|
441
|
+
0x0b,
|
|
442
|
+
0x0b,
|
|
443
|
+
0x0b,
|
|
444
|
+
0x0b,
|
|
445
|
+
0x0b,
|
|
446
|
+
0x0b,
|
|
447
|
+
0x0b,
|
|
448
|
+
0x0b,
|
|
449
|
+
0x0b,
|
|
450
|
+
0x0b,
|
|
451
|
+
0x0b};
|
|
452
|
+
const unsigned char salt[] = {
|
|
453
|
+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
|
|
454
|
+
const unsigned char info[] = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7};
|
|
455
|
+
const size_t length = 42;
|
|
456
|
+
|
|
457
|
+
Buffer<const unsigned char> keyBuf{key, sizeof(key)};
|
|
458
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
459
|
+
Buffer<const unsigned char> infoBuf{info, sizeof(info)};
|
|
460
|
+
|
|
461
|
+
Digest md(EVP_sha256());
|
|
462
|
+
ASSERT_TRUE(md);
|
|
463
|
+
|
|
464
|
+
auto result = hkdf(md, keyBuf, infoBuf, saltBuf, length);
|
|
465
|
+
ASSERT_TRUE(result);
|
|
466
|
+
ASSERT_EQ(result.size(), length);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// ============================================================================
|
|
470
|
+
// SPKAC tests
|
|
471
|
+
|
|
472
|
+
TEST(SPKAC, VerifySpkacBuffer) {
|
|
473
|
+
// A valid SPKAC string (base64 encoded)
|
|
474
|
+
// This is a test SPKAC - in real use, you'd have a properly generated one
|
|
475
|
+
const char* spkac =
|
|
476
|
+
"MIIBQDCBqjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2L3lR6VHBxKBZGnr"
|
|
477
|
+
"5R9AmJwcQPePMHl7X1tj0n5PKMXwXHLqD/xHtqWFN9aSWfZhCYVOYMPLsIEZvtsJ"
|
|
478
|
+
"qFCJzJXB7lYlLqcLLVJ5sDlT0fM8QiJR6CnBlWgaXEozL5XdKJdQ7UVlL1qqoLJP"
|
|
479
|
+
"8wLJ0PhXFaNvlNBaXx1lAx0CAwEAARYAMA0GCSqGSIb3DQEBBQUAA4GBAKMzhfqX"
|
|
480
|
+
"MvWRBfL+VNVX/3rE9IahSMPl/Dz0P4UO0MtDgYFR4N0tPPqg1EMH7HJRxPJQDUlf"
|
|
481
|
+
"M9TsMI8e8KfJX0VdPmmjvNy3LcboJqmqQ8TViV2U0K0mTgg3kEWdKl25QcleVQry"
|
|
482
|
+
"CqU2ThYNnK3QEbFwuTS4MHk4MHk2WHJoYzlk";
|
|
483
|
+
|
|
484
|
+
Buffer<const char> buf{spkac, strlen(spkac)};
|
|
485
|
+
|
|
486
|
+
// Note: This specific SPKAC may not verify correctly due to signature issues,
|
|
487
|
+
// but we're testing that the function runs without crashing and accepts the
|
|
488
|
+
// buffer interface
|
|
489
|
+
bool result = VerifySpkac(buf);
|
|
490
|
+
// The result depends on the validity of the SPKAC
|
|
491
|
+
(void)result;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
TEST(SPKAC, ExportPublicKeyBuffer) {
|
|
495
|
+
const char* spkac =
|
|
496
|
+
"MIIBQDCBqjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2L3lR6VHBxKBZGnr"
|
|
497
|
+
"5R9AmJwcQPePMHl7X1tj0n5PKMXwXHLqD/xHtqWFN9aSWfZhCYVOYMPLsIEZvtsJ"
|
|
498
|
+
"qFCJzJXB7lYlLqcLLVJ5sDlT0fM8QiJR6CnBlWgaXEozL5XdKJdQ7UVlL1qqoLJP"
|
|
499
|
+
"8wLJ0PhXFaNvlNBaXx1lAx0CAwEAARYAMA0GCSqGSIb3DQEBBQUAA4GBAKMzhfqX"
|
|
500
|
+
"MvWRBfL+VNVX/3rE9IahSMPl/Dz0P4UO0MtDgYFR4N0tPPqg1EMH7HJRxPJQDUlf"
|
|
501
|
+
"M9TsMI8e8KfJX0VdPmmjvNy3LcboJqmqQ8TViV2U0K0mTgg3kEWdKl25QcleVQry"
|
|
502
|
+
"CqU2ThYNnK3QEbFwuTS4MHk4MHk2WHJoYzlk";
|
|
503
|
+
|
|
504
|
+
Buffer<const char> buf{spkac, strlen(spkac)};
|
|
505
|
+
|
|
506
|
+
// Test that the buffer version works
|
|
507
|
+
auto bio = ExportPublicKey(buf);
|
|
508
|
+
// Result depends on SPKAC validity
|
|
509
|
+
(void)bio;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
TEST(SPKAC, ExportChallengeBuffer) {
|
|
513
|
+
const char* spkac =
|
|
514
|
+
"MIIBQDCBqjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2L3lR6VHBxKBZGnr"
|
|
515
|
+
"5R9AmJwcQPePMHl7X1tj0n5PKMXwXHLqD/xHtqWFN9aSWfZhCYVOYMPLsIEZvtsJ"
|
|
516
|
+
"qFCJzJXB7lYlLqcLLVJ5sDlT0fM8QiJR6CnBlWgaXEozL5XdKJdQ7UVlL1qqoLJP"
|
|
517
|
+
"8wLJ0PhXFaNvlNBaXx1lAx0CAwEAARYAMA0GCSqGSIb3DQEBBQUAA4GBAKMzhfqX"
|
|
518
|
+
"MvWRBfL+VNVX/3rE9IahSMPl/Dz0P4UO0MtDgYFR4N0tPPqg1EMH7HJRxPJQDUlf"
|
|
519
|
+
"M9TsMI8e8KfJX0VdPmmjvNy3LcboJqmqQ8TViV2U0K0mTgg3kEWdKl25QcleVQry"
|
|
520
|
+
"CqU2ThYNnK3QEbFwuTS4MHk4MHk2WHJoYzlk";
|
|
521
|
+
|
|
522
|
+
Buffer<const char> buf{spkac, strlen(spkac)};
|
|
523
|
+
|
|
524
|
+
// Test that the buffer version works and returns DataPointer
|
|
525
|
+
auto challenge = ExportChallenge(buf);
|
|
526
|
+
// Result depends on SPKAC validity
|
|
527
|
+
(void)challenge;
|
|
42
528
|
}
|
|
43
529
|
|
|
44
530
|
#ifdef OPENSSL_IS_BORINGSSL
|
|
@@ -84,3 +570,287 @@ TEST(basic, aead_info) {
|
|
|
84
570
|
ASSERT_EQ(aead.getMaxTagLength(), 16);
|
|
85
571
|
}
|
|
86
572
|
#endif
|
|
573
|
+
|
|
574
|
+
// ============================================================================
|
|
575
|
+
// Argon2 KDF tests (OpenSSL 3.2.0+ only)
|
|
576
|
+
|
|
577
|
+
#if OPENSSL_VERSION_NUMBER >= 0x30200000L
|
|
578
|
+
#ifndef OPENSSL_NO_ARGON2
|
|
579
|
+
|
|
580
|
+
TEST(KDF, argon2i) {
|
|
581
|
+
const char* password = "password";
|
|
582
|
+
const unsigned char salt[] = {0x01,
|
|
583
|
+
0x02,
|
|
584
|
+
0x03,
|
|
585
|
+
0x04,
|
|
586
|
+
0x05,
|
|
587
|
+
0x06,
|
|
588
|
+
0x07,
|
|
589
|
+
0x08,
|
|
590
|
+
0x09,
|
|
591
|
+
0x0a,
|
|
592
|
+
0x0b,
|
|
593
|
+
0x0c,
|
|
594
|
+
0x0d,
|
|
595
|
+
0x0e,
|
|
596
|
+
0x0f,
|
|
597
|
+
0x10};
|
|
598
|
+
const size_t length = 32;
|
|
599
|
+
|
|
600
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
601
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
602
|
+
Buffer<const unsigned char> secret{nullptr, 0};
|
|
603
|
+
Buffer<const unsigned char> ad{nullptr, 0};
|
|
604
|
+
|
|
605
|
+
// Use small parameters for testing
|
|
606
|
+
// lanes=1, memcost=16 (KB), iter=3, version=0x13 (1.3)
|
|
607
|
+
auto result = argon2(passBuf,
|
|
608
|
+
saltBuf,
|
|
609
|
+
1,
|
|
610
|
+
length,
|
|
611
|
+
16,
|
|
612
|
+
3,
|
|
613
|
+
0x13,
|
|
614
|
+
secret,
|
|
615
|
+
ad,
|
|
616
|
+
Argon2Type::ARGON2I);
|
|
617
|
+
ASSERT_TRUE(result);
|
|
618
|
+
ASSERT_EQ(result.size(), length);
|
|
619
|
+
|
|
620
|
+
// Verify output is not all zeros
|
|
621
|
+
bool allZeros = true;
|
|
622
|
+
for (size_t i = 0; i < length; i++) {
|
|
623
|
+
if (reinterpret_cast<unsigned char*>(result.get())[i] != 0) {
|
|
624
|
+
allZeros = false;
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
ASSERT_FALSE(allZeros);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
TEST(KDF, argon2d) {
|
|
632
|
+
const char* password = "password";
|
|
633
|
+
const unsigned char salt[] = {0x01,
|
|
634
|
+
0x02,
|
|
635
|
+
0x03,
|
|
636
|
+
0x04,
|
|
637
|
+
0x05,
|
|
638
|
+
0x06,
|
|
639
|
+
0x07,
|
|
640
|
+
0x08,
|
|
641
|
+
0x09,
|
|
642
|
+
0x0a,
|
|
643
|
+
0x0b,
|
|
644
|
+
0x0c,
|
|
645
|
+
0x0d,
|
|
646
|
+
0x0e,
|
|
647
|
+
0x0f,
|
|
648
|
+
0x10};
|
|
649
|
+
const size_t length = 32;
|
|
650
|
+
|
|
651
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
652
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
653
|
+
Buffer<const unsigned char> secret{nullptr, 0};
|
|
654
|
+
Buffer<const unsigned char> ad{nullptr, 0};
|
|
655
|
+
|
|
656
|
+
auto result = argon2(passBuf,
|
|
657
|
+
saltBuf,
|
|
658
|
+
1,
|
|
659
|
+
length,
|
|
660
|
+
16,
|
|
661
|
+
3,
|
|
662
|
+
0x13,
|
|
663
|
+
secret,
|
|
664
|
+
ad,
|
|
665
|
+
Argon2Type::ARGON2D);
|
|
666
|
+
ASSERT_TRUE(result);
|
|
667
|
+
ASSERT_EQ(result.size(), length);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
TEST(KDF, argon2id) {
|
|
671
|
+
const char* password = "password";
|
|
672
|
+
const unsigned char salt[] = {0x01,
|
|
673
|
+
0x02,
|
|
674
|
+
0x03,
|
|
675
|
+
0x04,
|
|
676
|
+
0x05,
|
|
677
|
+
0x06,
|
|
678
|
+
0x07,
|
|
679
|
+
0x08,
|
|
680
|
+
0x09,
|
|
681
|
+
0x0a,
|
|
682
|
+
0x0b,
|
|
683
|
+
0x0c,
|
|
684
|
+
0x0d,
|
|
685
|
+
0x0e,
|
|
686
|
+
0x0f,
|
|
687
|
+
0x10};
|
|
688
|
+
const size_t length = 32;
|
|
689
|
+
|
|
690
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
691
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
692
|
+
Buffer<const unsigned char> secret{nullptr, 0};
|
|
693
|
+
Buffer<const unsigned char> ad{nullptr, 0};
|
|
694
|
+
|
|
695
|
+
auto result = argon2(passBuf,
|
|
696
|
+
saltBuf,
|
|
697
|
+
1,
|
|
698
|
+
length,
|
|
699
|
+
16,
|
|
700
|
+
3,
|
|
701
|
+
0x13,
|
|
702
|
+
secret,
|
|
703
|
+
ad,
|
|
704
|
+
Argon2Type::ARGON2ID);
|
|
705
|
+
ASSERT_TRUE(result);
|
|
706
|
+
ASSERT_EQ(result.size(), length);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
TEST(KDF, argon2_with_secret_and_ad) {
|
|
710
|
+
const char* password = "password";
|
|
711
|
+
const unsigned char salt[] = {0x01,
|
|
712
|
+
0x02,
|
|
713
|
+
0x03,
|
|
714
|
+
0x04,
|
|
715
|
+
0x05,
|
|
716
|
+
0x06,
|
|
717
|
+
0x07,
|
|
718
|
+
0x08,
|
|
719
|
+
0x09,
|
|
720
|
+
0x0a,
|
|
721
|
+
0x0b,
|
|
722
|
+
0x0c,
|
|
723
|
+
0x0d,
|
|
724
|
+
0x0e,
|
|
725
|
+
0x0f,
|
|
726
|
+
0x10};
|
|
727
|
+
const unsigned char secretData[] = {0xaa, 0xbb, 0xcc, 0xdd};
|
|
728
|
+
const unsigned char adData[] = {0x11, 0x22, 0x33, 0x44, 0x55};
|
|
729
|
+
const size_t length = 32;
|
|
730
|
+
|
|
731
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
732
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
733
|
+
Buffer<const unsigned char> secret{secretData, sizeof(secretData)};
|
|
734
|
+
Buffer<const unsigned char> ad{adData, sizeof(adData)};
|
|
735
|
+
|
|
736
|
+
auto result = argon2(passBuf,
|
|
737
|
+
saltBuf,
|
|
738
|
+
1,
|
|
739
|
+
length,
|
|
740
|
+
16,
|
|
741
|
+
3,
|
|
742
|
+
0x13,
|
|
743
|
+
secret,
|
|
744
|
+
ad,
|
|
745
|
+
Argon2Type::ARGON2ID);
|
|
746
|
+
ASSERT_TRUE(result);
|
|
747
|
+
ASSERT_EQ(result.size(), length);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
TEST(KDF, argon2_empty_password) {
|
|
751
|
+
const unsigned char salt[] = {0x01,
|
|
752
|
+
0x02,
|
|
753
|
+
0x03,
|
|
754
|
+
0x04,
|
|
755
|
+
0x05,
|
|
756
|
+
0x06,
|
|
757
|
+
0x07,
|
|
758
|
+
0x08,
|
|
759
|
+
0x09,
|
|
760
|
+
0x0a,
|
|
761
|
+
0x0b,
|
|
762
|
+
0x0c,
|
|
763
|
+
0x0d,
|
|
764
|
+
0x0e,
|
|
765
|
+
0x0f,
|
|
766
|
+
0x10};
|
|
767
|
+
const size_t length = 32;
|
|
768
|
+
|
|
769
|
+
Buffer<const char> passBuf{"", 0};
|
|
770
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
771
|
+
Buffer<const unsigned char> secret{nullptr, 0};
|
|
772
|
+
Buffer<const unsigned char> ad{nullptr, 0};
|
|
773
|
+
|
|
774
|
+
// Empty password should still work
|
|
775
|
+
auto result = argon2(passBuf,
|
|
776
|
+
saltBuf,
|
|
777
|
+
1,
|
|
778
|
+
length,
|
|
779
|
+
16,
|
|
780
|
+
3,
|
|
781
|
+
0x13,
|
|
782
|
+
secret,
|
|
783
|
+
ad,
|
|
784
|
+
Argon2Type::ARGON2ID);
|
|
785
|
+
ASSERT_TRUE(result);
|
|
786
|
+
ASSERT_EQ(result.size(), length);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
TEST(KDF, argon2_different_types_produce_different_output) {
|
|
790
|
+
const char* password = "password";
|
|
791
|
+
const unsigned char salt[] = {0x01,
|
|
792
|
+
0x02,
|
|
793
|
+
0x03,
|
|
794
|
+
0x04,
|
|
795
|
+
0x05,
|
|
796
|
+
0x06,
|
|
797
|
+
0x07,
|
|
798
|
+
0x08,
|
|
799
|
+
0x09,
|
|
800
|
+
0x0a,
|
|
801
|
+
0x0b,
|
|
802
|
+
0x0c,
|
|
803
|
+
0x0d,
|
|
804
|
+
0x0e,
|
|
805
|
+
0x0f,
|
|
806
|
+
0x10};
|
|
807
|
+
const size_t length = 32;
|
|
808
|
+
|
|
809
|
+
Buffer<const char> passBuf{password, strlen(password)};
|
|
810
|
+
Buffer<const unsigned char> saltBuf{salt, sizeof(salt)};
|
|
811
|
+
Buffer<const unsigned char> secret{nullptr, 0};
|
|
812
|
+
Buffer<const unsigned char> ad{nullptr, 0};
|
|
813
|
+
|
|
814
|
+
auto resultI = argon2(passBuf,
|
|
815
|
+
saltBuf,
|
|
816
|
+
1,
|
|
817
|
+
length,
|
|
818
|
+
16,
|
|
819
|
+
3,
|
|
820
|
+
0x13,
|
|
821
|
+
secret,
|
|
822
|
+
ad,
|
|
823
|
+
Argon2Type::ARGON2I);
|
|
824
|
+
auto resultD = argon2(passBuf,
|
|
825
|
+
saltBuf,
|
|
826
|
+
1,
|
|
827
|
+
length,
|
|
828
|
+
16,
|
|
829
|
+
3,
|
|
830
|
+
0x13,
|
|
831
|
+
secret,
|
|
832
|
+
ad,
|
|
833
|
+
Argon2Type::ARGON2D);
|
|
834
|
+
auto resultID = argon2(passBuf,
|
|
835
|
+
saltBuf,
|
|
836
|
+
1,
|
|
837
|
+
length,
|
|
838
|
+
16,
|
|
839
|
+
3,
|
|
840
|
+
0x13,
|
|
841
|
+
secret,
|
|
842
|
+
ad,
|
|
843
|
+
Argon2Type::ARGON2ID);
|
|
844
|
+
|
|
845
|
+
ASSERT_TRUE(resultI);
|
|
846
|
+
ASSERT_TRUE(resultD);
|
|
847
|
+
ASSERT_TRUE(resultID);
|
|
848
|
+
|
|
849
|
+
// All three types should produce different outputs
|
|
850
|
+
ASSERT_NE(memcmp(resultI.get(), resultD.get(), length), 0);
|
|
851
|
+
ASSERT_NE(memcmp(resultI.get(), resultID.get(), length), 0);
|
|
852
|
+
ASSERT_NE(memcmp(resultD.get(), resultID.get(), length), 0);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
#endif // OPENSSL_NO_ARGON2
|
|
856
|
+
#endif // OPENSSL_VERSION_NUMBER >= 0x30200000L
|