Coverage Report

Created: 2024-11-21 07:03

/src/botan/src/lib/kdf/kdf1/kdf1.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* KDF1
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/internal/kdf1.h>
9
10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12
13
namespace Botan {
14
15
0
std::string KDF1::name() const {
16
0
   return fmt("KDF1({})", m_hash->name());
17
0
}
18
19
0
std::unique_ptr<KDF> KDF1::new_object() const {
20
0
   return std::make_unique<KDF1>(m_hash->new_object());
21
0
}
22
23
void KDF1::kdf(uint8_t key[],
24
               size_t key_len,
25
               const uint8_t secret[],
26
               size_t secret_len,
27
               const uint8_t salt[],
28
               size_t salt_len,
29
               const uint8_t label[],
30
0
               size_t label_len) const {
31
0
   if(key_len == 0) {
32
0
      return;
33
0
   }
34
35
0
   if(key_len > m_hash->output_length()) {
36
0
      throw Invalid_Argument("KDF1 maximum output length exceeeded");
37
0
   }
38
39
0
   m_hash->update(secret, secret_len);
40
0
   m_hash->update(label, label_len);
41
0
   m_hash->update(salt, salt_len);
42
43
0
   if(key_len == m_hash->output_length()) {
44
      // In this case we can hash directly into the output buffer
45
0
      m_hash->final(key);
46
0
   } else {
47
      // Otherwise a copy is required
48
0
      secure_vector<uint8_t> v = m_hash->final();
49
0
      copy_mem(key, v.data(), key_len);
50
0
   }
51
0
}
52
53
}  // namespace Botan