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

randombit / botan / 12370093224

17 Dec 2024 09:27AM UTC coverage: 91.262% (+0.003%) from 91.259%
12370093224

Pull #4478

github

web-flow
Merge b307ce8bd into 694344901
Pull Request #4478: Fix msvc warnings

93398 of 102340 relevant lines covered (91.26%)

11403200.06 hits per line

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

96.0
/src/lib/prov/tpm2/tpm2_rng.cpp
1
/*
2
* TPM 2 RNG interface
3
* (C) 2024 Jack Lloyd
4
* (C) 2024 René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity GmbH, financed by LANCOM Systems GmbH
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8

9
#include <botan/tpm2_rng.h>
10

11
#include <botan/internal/stl_util.h>
12
#include <botan/internal/tpm2_util.h>
13

14
#include <tss2/tss2_esys.h>
15

16
namespace Botan::TPM2 {
17

18
RandomNumberGenerator::RandomNumberGenerator(std::shared_ptr<Context> ctx, SessionBundle sessions) :
8✔
19
      m_ctx(std::move(ctx)), m_sessions(std::move(sessions)) {
8✔
20
   BOTAN_ASSERT_NONNULL(m_ctx);
8✔
21
   m_max_tpm2_rng_bytes = m_ctx->max_random_bytes_per_request();
8✔
22
}
8✔
23

24
void RandomNumberGenerator::fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> input) {
27✔
25
   constexpr size_t MAX_STIR_RANDOM_SIZE = 128;  // From specification of tpm2-tool's tpm2_stirrandom
27✔
26

27
   BufferSlicer in(input);
27✔
28
   while(!in.empty()) {
44✔
29
      const size_t chunk = std::min(in.remaining(), MAX_STIR_RANDOM_SIZE);
17✔
30
      const auto data = copy_into<TPM2B_SENSITIVE_DATA>(in.take(chunk));
17✔
31

32
      check_rc("Esys_StirRandom", Esys_StirRandom(*m_ctx, m_sessions[0], m_sessions[1], m_sessions[2], &data));
79✔
33
   }
34
   BOTAN_ASSERT_NOMSG(in.empty());
27✔
35

36
   BufferStuffer out(output);
27✔
37
   while(!out.full()) {
76✔
38
      unique_esys_ptr<TPM2B_DIGEST> digest = nullptr;
49✔
39
      const auto requested_bytes = std::min(out.remaining_capacity(), m_max_tpm2_rng_bytes);
49✔
40
      check_rc("Esys_GetRandom",
278✔
41
               Esys_GetRandom(*m_ctx,
98✔
42
                              m_sessions[0],
43
                              m_sessions[1],
44
                              m_sessions[2],
45
                              static_cast<uint16_t>(requested_bytes),
46
                              out_ptr(digest)));
×
47

48
      BOTAN_ASSERT_NOMSG(digest->size == requested_bytes);
49✔
49
      out.append(as_span(*digest));
49✔
50
   }
49✔
51
   BOTAN_ASSERT_NOMSG(out.full());
27✔
52
}
27✔
53

54
}  // namespace Botan::TPM2
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