| 1 | #include "test.h" |
| 2 | |
| 3 | #include <base/system.h> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | TEST(SecureRandom, Fill) |
| 8 | { |
| 9 | unsigned int Bits = 0; |
| 10 | while(~Bits) |
| 11 | { |
| 12 | unsigned int Random; |
| 13 | secure_random_fill(bytes: &Random, length: sizeof(Random)); |
| 14 | Bits |= Random; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | TEST(SecureRandom, Below1) |
| 19 | { |
| 20 | EXPECT_EQ(secure_rand_below(1), 0); |
| 21 | } |
| 22 | |
| 23 | TEST(SecureRandom, Below) |
| 24 | { |
| 25 | const int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129}; |
| 26 | for(auto Below : BOUNDS) |
| 27 | { |
| 28 | for(int j = 0; j < 10; j++) |
| 29 | { |
| 30 | int Random = secure_rand_below(below: Below); |
| 31 | EXPECT_GE(Random, 0); |
| 32 | EXPECT_LT(Random, Below); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |