summaryrefslogtreecommitdiffstats
path: root/security/nss/gtests/pk11_gtest/pk11_prng_unittest.cc
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-02-06 11:46:26 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-02-06 11:46:26 +0100
commitf017b749ea9f1586d2308504553d40bf4cc5439d (patch)
treec6033924a0de9be1ab140596e305898c651bf57e /security/nss/gtests/pk11_gtest/pk11_prng_unittest.cc
parent7c728b3c7680662fc4e92b5d03697b8339560b08 (diff)
downloadUXP-f017b749ea9f1586d2308504553d40bf4cc5439d.tar
UXP-f017b749ea9f1586d2308504553d40bf4cc5439d.tar.gz
UXP-f017b749ea9f1586d2308504553d40bf4cc5439d.tar.lz
UXP-f017b749ea9f1586d2308504553d40bf4cc5439d.tar.xz
UXP-f017b749ea9f1586d2308504553d40bf4cc5439d.zip
Update NSS to 3.32.1-RTM
Diffstat (limited to 'security/nss/gtests/pk11_gtest/pk11_prng_unittest.cc')
-rw-r--r--security/nss/gtests/pk11_gtest/pk11_prng_unittest.cc51
1 files changed, 47 insertions, 4 deletions
diff --git a/security/nss/gtests/pk11_gtest/pk11_prng_unittest.cc b/security/nss/gtests/pk11_gtest/pk11_prng_unittest.cc
index fd2865169..ef05fe51c 100644
--- a/security/nss/gtests/pk11_gtest/pk11_prng_unittest.cc
+++ b/security/nss/gtests/pk11_gtest/pk11_prng_unittest.cc
@@ -36,12 +36,12 @@ TEST_F(PK11PrngTest, Fuzz_DetPRNG_Reset) {
std::vector<uint8_t> rnd1(2048, 0);
std::vector<uint8_t> rnd2(2048, 0);
- RNG_ResetForFuzzing();
+ EXPECT_EQ(SECSuccess, RNG_RandomUpdate(NULL, 0));
SECStatus rv = PK11_GenerateRandom(rnd1.data(), rnd1.size());
EXPECT_EQ(rv, SECSuccess);
- RNG_ResetForFuzzing();
+ EXPECT_EQ(SECSuccess, RNG_RandomUpdate(NULL, 0));
rv = PK11_GenerateRandom(rnd2.data(), rnd2.size());
EXPECT_EQ(rv, SECSuccess);
@@ -54,7 +54,7 @@ TEST_F(PK11PrngTest, Fuzz_DetPRNG_StatefulReset) {
std::vector<uint8_t> rnd1(2048, 0);
std::vector<uint8_t> rnd2(2048, 0);
- RNG_ResetForFuzzing();
+ EXPECT_EQ(SECSuccess, RNG_RandomUpdate(NULL, 0));
SECStatus rv = PK11_GenerateRandom(rnd1.data(), rnd1.size() - 1024);
EXPECT_EQ(rv, SECSuccess);
@@ -62,7 +62,50 @@ TEST_F(PK11PrngTest, Fuzz_DetPRNG_StatefulReset) {
rv = PK11_GenerateRandom(rnd1.data() + 1024, rnd1.size() - 1024);
EXPECT_EQ(rv, SECSuccess);
- RNG_ResetForFuzzing();
+ EXPECT_EQ(SECSuccess, RNG_RandomUpdate(NULL, 0));
+
+ rv = PK11_GenerateRandom(rnd2.data(), rnd2.size() - 1024);
+ EXPECT_EQ(rv, SECSuccess);
+
+ rv = PK11_GenerateRandom(rnd2.data() + 1024, rnd2.size() - 1024);
+ EXPECT_EQ(rv, SECSuccess);
+
+ EXPECT_EQ(rnd1, rnd2);
+}
+
+TEST_F(PK11PrngTest, Fuzz_DetPRNG_Seed) {
+ std::vector<uint8_t> rnd1(2048, 0);
+ std::vector<uint8_t> rnd2(2048, 0);
+ std::vector<uint8_t> seed = {0x01, 0x22, 0xAA, 0x45};
+
+ SECStatus rv = PK11_RandomUpdate(seed.data(), seed.size());
+ EXPECT_EQ(rv, SECSuccess);
+
+ rv = PK11_GenerateRandom(rnd1.data(), rnd1.size());
+ EXPECT_EQ(rv, SECSuccess);
+
+ rv = PK11_GenerateRandom(rnd2.data(), rnd2.size());
+ EXPECT_EQ(rv, SECSuccess);
+
+ EXPECT_NE(rnd1, rnd2);
+}
+
+TEST_F(PK11PrngTest, Fuzz_DetPRNG_StatefulReset_Seed) {
+ std::vector<uint8_t> rnd1(2048, 0);
+ std::vector<uint8_t> rnd2(2048, 0);
+ std::vector<uint8_t> seed = {0x01, 0x22, 0xAA, 0x45};
+
+ SECStatus rv = PK11_RandomUpdate(seed.data(), seed.size());
+ EXPECT_EQ(rv, SECSuccess);
+
+ rv = PK11_GenerateRandom(rnd1.data(), rnd1.size() - 1024);
+ EXPECT_EQ(rv, SECSuccess);
+
+ rv = PK11_GenerateRandom(rnd1.data() + 1024, rnd1.size() - 1024);
+ EXPECT_EQ(rv, SECSuccess);
+
+ rv = PK11_RandomUpdate(seed.data(), seed.size());
+ EXPECT_EQ(rv, SECSuccess);
rv = PK11_GenerateRandom(rnd2.data(), rnd2.size() - 1024);
EXPECT_EQ(rv, SECSuccess);