mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-27 02:47:31 +09:00
re-introduce old nss im too tired for this
This commit is contained in:
parent
3c46be320d
commit
3a838106b9
2871 changed files with 1374431 additions and 1762417 deletions
|
|
@ -1,43 +0,0 @@
|
|||
#! gmake
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
include ../common/gtest.mk
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
|
@ -56,10 +56,10 @@ TEST_P(Blake2BKATKeyed, Keyed) {
|
|||
EXPECT_EQ(values, std::get<1>(GetParam()));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(UnkeyedKAT, Blake2BKATUnkeyed,
|
||||
::testing::ValuesIn(TestcasesUnkeyed));
|
||||
INSTANTIATE_TEST_SUITE_P(KeyedKAT, Blake2BKATKeyed,
|
||||
::testing::ValuesIn(TestcasesKeyed));
|
||||
INSTANTIATE_TEST_CASE_P(UnkeyedKAT, Blake2BKATUnkeyed,
|
||||
::testing::ValuesIn(TestcasesUnkeyed));
|
||||
INSTANTIATE_TEST_CASE_P(KeyedKAT, Blake2BKATKeyed,
|
||||
::testing::ValuesIn(TestcasesKeyed));
|
||||
|
||||
TEST_F(Blake2BTests, ContextTest) {
|
||||
ScopedBLAKE2BContext ctx(BLAKE2B_NewContext());
|
||||
|
|
@ -271,3 +271,19 @@ TEST_F(Blake2BTests, EmptyKeyTest) {
|
|||
EXPECT_EQ(SECFailure, rv);
|
||||
EXPECT_EQ(SEC_ERROR_INVALID_ARGS, PORT_GetError());
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
if (NSS_NoDB_Init(nullptr) != SECSuccess) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
|
||||
if (NSS_Shutdown() != SECSuccess) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,4 @@ TEST_F(DHTest, DhGenParamSuccessTest16) { TestGenParamSuccess(16); }
|
|||
TEST_F(DHTest, DhGenParamSuccessTest224) { TestGenParamSuccess(224); }
|
||||
TEST_F(DHTest, DhGenParamSuccessTest256) { TestGenParamSuccess(256); }
|
||||
|
||||
} // namespace nss_test
|
||||
} // nss_test
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace nss_test {
|
|||
|
||||
class ECLTest : public ::testing::Test {
|
||||
protected:
|
||||
ECCurveName GetCurveName(std::string name) {
|
||||
const ECCurveName GetCurveName(std::string name) {
|
||||
if (name == "P256") return ECCurve_NIST_P256;
|
||||
if (name == "P384") return ECCurve_NIST_P384;
|
||||
if (name == "P521") return ECCurve_NIST_P521;
|
||||
|
|
@ -121,4 +121,4 @@ TEST_F(ECLTest, TestECDH_DeriveP521) {
|
|||
SECSuccess);
|
||||
}
|
||||
|
||||
} // namespace nss_test
|
||||
} // nss_test
|
||||
|
|
|
|||
|
|
@ -30,14 +30,12 @@
|
|||
'target_name': 'freebl_gtest',
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'blake2b_unittest.cc',
|
||||
'cmac_unittests.cc',
|
||||
'mpi_unittest.cc',
|
||||
'dh_unittest.cc',
|
||||
'ecl_unittest.cc',
|
||||
'ghash_unittest.cc',
|
||||
'mpi_unittest.cc',
|
||||
'prng_kat_unittest.cc',
|
||||
'rsa_unittest.cc',
|
||||
'cmac_unittests.cc',
|
||||
'<(DEPTH)/gtests/common/gtests.cc'
|
||||
],
|
||||
'dependencies': [
|
||||
|
|
@ -52,6 +50,28 @@
|
|||
}],
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'prng_gtest',
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'prng_kat_unittest.cc',
|
||||
],
|
||||
'dependencies': [
|
||||
'freebl_gtest_deps',
|
||||
'<(DEPTH)/exports.gyp:nss_exports',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'blake2b_gtest',
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'blake2b_unittest.cc',
|
||||
],
|
||||
'dependencies': [
|
||||
'freebl_gtest_deps',
|
||||
'<(DEPTH)/exports.gyp:nss_exports',
|
||||
],
|
||||
},
|
||||
],
|
||||
'target_defaults': {
|
||||
'include_dirs': [
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
|
||||
namespace nss_test {
|
||||
|
||||
class GHashTest : public ::testing::TestWithParam<AesGcmKatValue> {
|
||||
class GHashTest : public ::testing::TestWithParam<gcm_kat_value> {
|
||||
protected:
|
||||
void TestGHash(const AesGcmKatValue val, bool sw) {
|
||||
void TestGHash(const gcm_kat_value val, bool sw) {
|
||||
// Read test data.
|
||||
std::vector<uint8_t> hash_key = hex_string_to_bytes(val.hash_key);
|
||||
ASSERT_EQ(16UL, hash_key.size());
|
||||
|
|
@ -49,7 +49,7 @@ TEST_P(GHashTest, KAT_X86_HW) { TestGHash(GetParam(), false); }
|
|||
#endif
|
||||
TEST_P(GHashTest, KAT_Sftw) { TestGHash(GetParam(), true); }
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(NISTTestVector, GHashTest,
|
||||
::testing::ValuesIn(kGcmKatValues));
|
||||
INSTANTIATE_TEST_CASE_P(NISTTestVector, GHashTest,
|
||||
::testing::ValuesIn(kGcmKatValues));
|
||||
|
||||
} // namespace nss_test
|
||||
} // nss_test
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
CORE_DEPTH = ../..
|
||||
DEPTH = ../..
|
||||
MODULE = nss
|
||||
|
||||
# we'll need to figure out how to get these symbols linked
|
||||
# in before we include these tests:
|
||||
# mpi_unittest.cc
|
||||
# ghash_unittest.cc
|
||||
CPPSRCS = \
|
||||
dh_unittest.cc \
|
||||
ecl_unittest.cc \
|
||||
rsa_unittest.cc \
|
||||
cmac_unittests.cc \
|
||||
$(NULL)
|
||||
|
||||
DEFINES += -DDLL_PREFIX=\"$(DLL_PREFIX)\" -DDLL_SUFFIX=\"$(DLL_SUFFIX)\"
|
||||
|
||||
INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
|
||||
-I$(CORE_DEPTH)/lib/freebl/ecl \
|
||||
-I$(CORE_DEPTH)/lib/freebl/mpi \
|
||||
-I$(CORE_DEPTH)/lib/freebl \
|
||||
-I$(CORE_DEPTH)/gtests/common \
|
||||
-I$(CORE_DEPTH)/cpputil
|
||||
|
||||
REQUIRES = nspr nss libdbm gtest cpputil
|
||||
|
||||
PROGRAM = freebl_gtest
|
||||
|
||||
EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)cpputil.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)gtestutil.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
USE_STATIC_LIBS=1
|
||||
|
|
@ -13,7 +13,6 @@
|
|||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
#include "mplogic.h"
|
||||
#include "mpi.h"
|
||||
namespace nss_test {
|
||||
|
||||
|
|
@ -192,39 +191,6 @@ TEST_F(MPITest, MpiFixlenOctetsZero) {
|
|||
TestToFixedOctets(zero, sizeof(mp_digit) + 1);
|
||||
}
|
||||
|
||||
TEST_F(MPITest, MpiRadixSizeNeg) {
|
||||
char* str;
|
||||
mp_int a;
|
||||
mp_err rv;
|
||||
const char* negative_edge =
|
||||
"-5400000000000000003000000002200020090919017007777777777870000090"
|
||||
"00000000007500443416610000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000000075049054"
|
||||
"18610000800555594485440016000031555550000000000000000220030200909"
|
||||
"19017007777777700000000000000000000000000000000000000000000000000"
|
||||
"00000000000500000000000000000000000000004668129841661000071000000"
|
||||
"00000000000000000000000000000000000000000000000007504434166100000"
|
||||
"00000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000075049054186100008005555944854400184572169555500000000000"
|
||||
"0000022003020090919017007777777700000000000000000000";
|
||||
|
||||
rv = mp_init(&a);
|
||||
ASSERT_EQ(MP_OKAY, rv);
|
||||
rv = mp_read_variable_radix(&a, negative_edge, 10);
|
||||
ASSERT_EQ(MP_OKAY, rv);
|
||||
|
||||
const int radixSize = mp_radix_size(&a, 10);
|
||||
ASSERT_LE(0, radixSize);
|
||||
|
||||
str = (char*)malloc(radixSize);
|
||||
ASSERT_NE(nullptr, str);
|
||||
rv = mp_toradix(&a, str, 10);
|
||||
ASSERT_EQ(MP_OKAY, rv);
|
||||
ASSERT_EQ(0, strcmp(negative_edge, str));
|
||||
free(str);
|
||||
mp_clear(&a);
|
||||
}
|
||||
|
||||
TEST_F(MPITest, MpiFixlenOctetsVarlen) {
|
||||
std::vector<uint8_t> packed;
|
||||
for (size_t i = 0; i < sizeof(mp_digit) * 2; ++i) {
|
||||
|
|
@ -258,92 +224,6 @@ TEST_F(MPITest, MpiFixlenOctetsTooSmall) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(MPITest, MpiSqrMulClamp) {
|
||||
mp_int a, r, expect;
|
||||
MP_DIGITS(&a) = 0;
|
||||
MP_DIGITS(&r) = 0;
|
||||
MP_DIGITS(&expect) = 0;
|
||||
|
||||
// Comba32 result is 64 mp_digits. *=2 as this is an ascii representation.
|
||||
std::string expect_str((64 * sizeof(mp_digit)) * 2, '0');
|
||||
|
||||
// Set second-highest bit (0x80...^2 == 0x4000...)
|
||||
expect_str.replace(0, 1, "4", 1);
|
||||
|
||||
// Test 32, 16, 8, and 4-1 mp_digit values. 32-4 (powers of two) use the comba
|
||||
// assembly implementation, if enabled and supported. 3-1 use non-comba.
|
||||
int n_digits = 32;
|
||||
while (n_digits > 0) {
|
||||
ASSERT_EQ(MP_OKAY, mp_init(&r));
|
||||
ASSERT_EQ(MP_OKAY, mp_init(&a));
|
||||
ASSERT_EQ(MP_OKAY, mp_init(&expect));
|
||||
ASSERT_EQ(MP_OKAY, mp_read_radix(&expect, expect_str.c_str(), 16));
|
||||
|
||||
ASSERT_EQ(MP_OKAY, mp_set_int(&a, 1));
|
||||
ASSERT_EQ(MP_OKAY, mpl_lsh(&a, &a, (n_digits * sizeof(mp_digit) * 8) - 1));
|
||||
|
||||
ASSERT_EQ(MP_OKAY, mp_sqr(&a, &r));
|
||||
EXPECT_EQ(MP_USED(&expect), MP_USED(&r));
|
||||
EXPECT_EQ(0, mp_cmp(&r, &expect));
|
||||
mp_clear(&r);
|
||||
|
||||
// Take the mul path...
|
||||
ASSERT_EQ(MP_OKAY, mp_init(&r));
|
||||
ASSERT_EQ(MP_OKAY, mp_mul(&a, &a, &r));
|
||||
EXPECT_EQ(MP_USED(&expect), MP_USED(&r));
|
||||
EXPECT_EQ(0, mp_cmp(&r, &expect));
|
||||
|
||||
mp_clear(&a);
|
||||
mp_clear(&r);
|
||||
mp_clear(&expect);
|
||||
|
||||
// Once we're down to 4, check non-powers of two.
|
||||
int sub = n_digits > 4 ? n_digits / 2 : 1;
|
||||
n_digits -= sub;
|
||||
|
||||
// "Shift right" the string (to avoid mutating |expect_str| with MPI).
|
||||
expect_str.resize(expect_str.size() - 2 * 2 * sizeof(mp_digit) * sub);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MPITest, MpiInvModLoop) {
|
||||
mp_int a;
|
||||
mp_int m;
|
||||
mp_int c_actual;
|
||||
mp_int c_expect;
|
||||
MP_DIGITS(&a) = 0;
|
||||
MP_DIGITS(&m) = 0;
|
||||
MP_DIGITS(&c_actual) = 0;
|
||||
MP_DIGITS(&c_expect) = 0;
|
||||
ASSERT_EQ(MP_OKAY, mp_init(&a));
|
||||
ASSERT_EQ(MP_OKAY, mp_init(&m));
|
||||
ASSERT_EQ(MP_OKAY, mp_init(&c_actual));
|
||||
ASSERT_EQ(MP_OKAY, mp_init(&c_expect));
|
||||
mp_read_radix(&a,
|
||||
"3e10b9f4859fb9e8150cc0d94e83ef428d655702a0b6fb1e684f4755eb6be6"
|
||||
"5ac6048cdfc533f73a9bad76125801051f",
|
||||
16);
|
||||
mp_read_radix(&m,
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372d"
|
||||
"df581a0db248b0a77aecec196accc52973",
|
||||
16);
|
||||
mp_read_radix(&c_expect,
|
||||
"12302214814361c15ab6c0f2131150af186099f8c22f6c9d6e77ad496b551c"
|
||||
"7c8039e61098bfe2af66474420659435c6",
|
||||
16);
|
||||
|
||||
int rv = mp_invmod(&a, &m, &c_actual);
|
||||
ASSERT_EQ(MP_OKAY, rv);
|
||||
|
||||
rv = mp_cmp(&c_actual, &c_expect);
|
||||
EXPECT_EQ(0, rv);
|
||||
|
||||
mp_clear(&a);
|
||||
mp_clear(&m);
|
||||
mp_clear(&c_actual);
|
||||
mp_clear(&c_expect);
|
||||
}
|
||||
|
||||
// This test is slow. Disable it by default so we can run these tests on CI.
|
||||
class DISABLED_MPITest : public ::testing::Test {};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,9 @@
|
|||
|
||||
#include "blapi.h"
|
||||
|
||||
extern std::string g_source_dir;
|
||||
|
||||
namespace nss_test {
|
||||
|
||||
struct PRNGTestValues {
|
||||
typedef struct PRNGTestValuesStr {
|
||||
std::vector<uint8_t> entropy;
|
||||
std::vector<uint8_t> nonce;
|
||||
std::vector<uint8_t> personal;
|
||||
|
|
@ -27,7 +25,9 @@ struct PRNGTestValues {
|
|||
std::vector<uint8_t> additional_entropy;
|
||||
std::vector<uint8_t> additional_input_reseed;
|
||||
std::vector<std::vector<uint8_t>> additional_input;
|
||||
};
|
||||
} PRNGTestValues;
|
||||
|
||||
std::vector<PRNGTestValues> test_vector;
|
||||
|
||||
bool contains(std::string& s, const char* to_find) {
|
||||
return s.find(to_find) != std::string::npos;
|
||||
|
|
@ -59,10 +59,8 @@ void print_bytes(std::vector<uint8_t> bytes, std::string name) {
|
|||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
static std::vector<PRNGTestValues> ReadFile(const std::string file_name) {
|
||||
std::vector<PRNGTestValues> test_vector;
|
||||
static void ReadFile(const std::string file_name) {
|
||||
std::ifstream infile(file_name);
|
||||
EXPECT_FALSE(infile.fail()) << "kat file: " << file_name;
|
||||
std::string line;
|
||||
|
||||
// Variables holding the input for each test.
|
||||
|
|
@ -125,17 +123,11 @@ static std::vector<PRNGTestValues> ReadFile(const std::string file_name) {
|
|||
test = {};
|
||||
infile.seekg(pos);
|
||||
}
|
||||
return test_vector;
|
||||
}
|
||||
|
||||
class PRNGTest : public ::testing::Test {
|
||||
class PRNGTest : public ::testing::TestWithParam<PRNGTestValues> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
test_vector_ = ReadFile(::g_source_dir + "/kat/Hash_DRBG.rsp");
|
||||
ASSERT_FALSE(test_vector_.empty());
|
||||
}
|
||||
|
||||
void RunTest(PRNGTestValues& test) {
|
||||
void RunTest(PRNGTestValues test) {
|
||||
ASSERT_EQ(2U, test.additional_input.size());
|
||||
SECStatus rv = PRNGTEST_Instantiate_Kat(
|
||||
test.entropy.data(), test.entropy.size(), test.nonce.data(),
|
||||
|
|
@ -162,15 +154,34 @@ class PRNGTest : public ::testing::Test {
|
|||
rv = PRNGTEST_Uninstantiate();
|
||||
ASSERT_EQ(SECSuccess, rv);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<PRNGTestValues> test_vector_;
|
||||
};
|
||||
|
||||
TEST_F(PRNGTest, HashDRBG) {
|
||||
for (auto& v : test_vector_) {
|
||||
RunTest(v);
|
||||
}
|
||||
}
|
||||
TEST_P(PRNGTest, HashDRBG) { RunTest(GetParam()); }
|
||||
|
||||
} // namespace nss_test
|
||||
INSTANTIATE_TEST_CASE_P(NISTTestVector, PRNGTest,
|
||||
::testing::ValuesIn(test_vector));
|
||||
|
||||
} // nss_test
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
std::cout << "usage: prng_gtest <.rsp file>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
nss_test::ReadFile(argv[1]);
|
||||
assert(!nss_test::test_vector.empty());
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
if (NSS_NoDB_Init(nullptr) != SECSuccess) {
|
||||
return 1;
|
||||
}
|
||||
int rv = RUN_ALL_TESTS();
|
||||
|
||||
if (NSS_Shutdown() != SECSuccess) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,23 +77,19 @@ TEST_F(RSATest, DecryptBlockTestErrors) {
|
|||
EXPECT_EQ(SECFailure, rv);
|
||||
|
||||
uint8_t in[256] = {0};
|
||||
// This should fail because the padding checks will fail,
|
||||
// however, mitigations for Bleichenbacher attacks transform failures
|
||||
// to a different output.
|
||||
// This should fail because the padding checks will fail.
|
||||
rv = RSA_DecryptBlock(key.get(), out, &outputLen, maxOutputLen, in,
|
||||
sizeof(in));
|
||||
EXPECT_EQ(SECSuccess, rv);
|
||||
// outputLen should <= 256-11=245.
|
||||
EXPECT_LE(outputLen, 245u);
|
||||
EXPECT_EQ(SECFailure, rv);
|
||||
// outputLen should be maxOutputLen.
|
||||
EXPECT_EQ(maxOutputLen, outputLen);
|
||||
|
||||
// This should fail because the padding checks will fail,
|
||||
// however, mitigations for Bleichenbacher attacks transform failures
|
||||
// to a different output.
|
||||
// This should fail because the padding checks will fail.
|
||||
uint8_t out_long[260] = {0};
|
||||
maxOutputLen = sizeof(out_long);
|
||||
rv = RSA_DecryptBlock(key.get(), out_long, &outputLen, maxOutputLen, in,
|
||||
sizeof(in));
|
||||
EXPECT_EQ(SECSuccess, rv);
|
||||
EXPECT_EQ(SECFailure, rv);
|
||||
// outputLen should <= 256-11=245.
|
||||
EXPECT_LE(outputLen, 245u);
|
||||
// Everything over 256 must be 0 in the output.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue