• 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

88.89
/src/lib/kdf/prf_tls/prf_tls.cpp
1
/*
2
* TLSv1.2 PRF
3
* (C) 2004-2010 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/prf_tls.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12

13
namespace Botan {
14

15
namespace {
16

17
/*
18
* TLS PRF P_hash function
19
*/
20
void P_hash(uint8_t out[],
7,106✔
21
            size_t out_len,
22
            MessageAuthenticationCode& mac,
23
            const uint8_t secret[],
24
            size_t secret_len,
25
            const uint8_t salt[],
26
            size_t salt_len) {
27
   try {
7,106✔
28
      mac.set_key(secret, secret_len);
7,106✔
29
   } catch(Invalid_Key_Length&) {
×
30
      throw Internal_Error(fmt("The premaster secret of {} bytes is too long for TLS-PRF", secret_len));
×
31
   }
×
32

33
   secure_vector<uint8_t> A(salt, salt + salt_len);
7,106✔
34
   secure_vector<uint8_t> h;
7,106✔
35

36
   size_t offset = 0;
7,106✔
37

38
   while(offset != out_len) {
24,002✔
39
      A = mac.process(A);
33,792✔
40

41
      mac.update(A);
16,896✔
42
      mac.update(salt, salt_len);
16,896✔
43
      mac.final(h);
16,896✔
44

45
      const size_t writing = std::min(h.size(), out_len - offset);
16,896✔
46
      xor_buf(&out[offset], h.data(), writing);
16,896✔
47
      offset += writing;
16,896✔
48
   }
49
}
14,212✔
50

51
}
52

53
std::string TLS_12_PRF::name() const { return fmt("TLS-12-PRF({})", m_mac->name()); }
12✔
54

55
std::unique_ptr<KDF> TLS_12_PRF::new_object() const { return std::make_unique<TLS_12_PRF>(m_mac->new_object()); }
4✔
56

57
void TLS_12_PRF::kdf(uint8_t key[],
7,106✔
58
                     size_t key_len,
59
                     const uint8_t secret[],
60
                     size_t secret_len,
61
                     const uint8_t salt[],
62
                     size_t salt_len,
63
                     const uint8_t label[],
64
                     size_t label_len) const {
65
   secure_vector<uint8_t> msg;
7,106✔
66

67
   msg.reserve(label_len + salt_len);
7,106✔
68
   msg += std::make_pair(label, label_len);
7,106✔
69
   msg += std::make_pair(salt, salt_len);
7,106✔
70

71
   P_hash(key, key_len, *m_mac, secret, secret_len, msg.data(), msg.size());
7,106✔
72
}
7,106✔
73

74
}
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