• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/tests/test_entropy.cpp
1
/*
2
* (C) 2015 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "test_rng.h"
8
#include "tests.h"
9
#include <botan/entropy_src.h>
10

11
#if defined(BOTAN_HAS_COMPRESSION)
12
   #include <botan/compression.h>
13
#endif
14

15
namespace Botan_Tests {
16

17
namespace {
18

19
class Entropy_Source_Tests final : public Test {
×
20
   public:
21
      std::vector<Test::Result> run() override {
1✔
22
         Botan::Entropy_Sources& srcs = Botan::Entropy_Sources::global_sources();
1✔
23

24
         std::vector<std::string> src_names = srcs.enabled_sources();
1✔
25

26
         std::vector<Test::Result> results;
1✔
27

28
         for(const auto& src_name : src_names) {
5✔
29
            Test::Result result("Entropy source " + src_name);
4✔
30

31
            result.start_timer();
4✔
32

33
            try {
4✔
34
               SeedCapturing_RNG rng;
4✔
35

36
               size_t bits = srcs.poll_just(rng, src_name);
4✔
37

38
               result.test_gte("Entropy estimate", rng.seed_material().size() * 8, bits);
4✔
39

40
               if(rng.samples() > 0) {
4✔
41
                  result.test_gte("Seed material bytes", rng.seed_material().size(), 1);
4✔
42
                  result.test_gte("Samples", rng.samples(), 1);
8✔
43
               }
44

45
               result.test_note("poll result", rng.seed_material());
4✔
46

47
#if defined(BOTAN_HAS_COMPRESSION)
48
               if(!rng.seed_material().empty()) {
4✔
49
                  /*
50
                  * Skip bzip2 both due to OS X problem (GH #394) and because bzip2's
51
                  * large blocks cause the entropy differential test to fail sometimes.
52
                  */
53
                  for(const std::string comp_algo : {"zlib", "lzma"}) {
12✔
54
                     auto comp = Botan::Compression_Algorithm::create(comp_algo);
8✔
55

56
                     if(comp) {
8✔
57
                        size_t comp1_size = 0;
8✔
58

59
                        try {
8✔
60
                           Botan::secure_vector<uint8_t> compressed;
8✔
61
                           compressed.assign(rng.seed_material().begin(), rng.seed_material().end());
8✔
62
                           comp->start(9);
8✔
63
                           comp->finish(compressed);
8✔
64

65
                           comp1_size = compressed.size();
8✔
66

67
                           result.test_gte(
8✔
68
                              comp_algo + " compressed entropy better than advertised", compressed.size() * 8, bits);
16✔
69
                        } catch(std::exception& e) {
8✔
70
                           result.test_failure(comp_algo + " exception while compressing", e.what());
×
71
                        }
×
72

73
                        SeedCapturing_RNG rng2;
8✔
74

75
                        size_t bits2 = srcs.poll_just(rng2, src_name);
8✔
76

77
                        result.test_note("poll 2 result", rng2.seed_material());
8✔
78

79
                        if(rng.seed_material().size() > 0 && rng2.seed_material().size() > 0) {
8✔
80
                           try {
8✔
81
                              Botan::secure_vector<uint8_t> compressed;
8✔
82
                              compressed.insert(
16✔
83
                                 compressed.end(), rng.seed_material().begin(), rng.seed_material().end());
8✔
84
                              compressed.insert(
16✔
85
                                 compressed.end(), rng2.seed_material().begin(), rng2.seed_material().end());
8✔
86

87
                              comp->start();
8✔
88
                              comp->finish(compressed);
8✔
89

90
                              size_t comp2_size = compressed.size();
8✔
91

92
                              result.test_lt("Two blocks of entropy are larger than one", comp1_size, comp2_size);
8✔
93

94
                              size_t comp_diff = comp2_size - comp1_size;
8✔
95

96
                              result.test_gte(
8✔
97
                                 comp_algo + " diff compressed entropy better than advertised", comp_diff * 8, bits2);
16✔
98
                           } catch(std::exception& e) {
8✔
99
                              result.test_failure(comp_algo + " exception while compressing", e.what());
×
100
                           }
×
101
                        }
102
                     }
8✔
103
                  }
8✔
104
               }
105
#endif
106
            } catch(std::exception& e) { result.test_failure("during entropy collection test", e.what()); }
4✔
107

108
            result.end_timer();
4✔
109
            results.push_back(result);
4✔
110
         }
4✔
111

112
         return results;
1✔
113
      }
1✔
114
};
115

116
BOTAN_REGISTER_TEST("rng", "entropy", Entropy_Source_Tests);
117

118
}
119

120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc