Coverage Report

Created: 2021-02-21 07:20

/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
#include <botan/exceptn.h>
10
11
namespace Botan {
12
13
std::string KDF1::name() const
14
0
   {
15
0
   return "KDF1(" + m_hash->name() + ")";
16
0
   }
17
18
KDF* KDF1::clone() const
19
0
   {
20
0
   return new KDF1(m_hash->clone());
21
0
   }
22
23
void KDF1::kdf(uint8_t key[], size_t key_len,
24
               const uint8_t secret[], size_t secret_len,
25
               const uint8_t salt[], size_t salt_len,
26
               const uint8_t label[], size_t label_len) const
27
0
   {
28
0
   if(key_len == 0)
29
0
      return;
30
31
0
   if(key_len > m_hash->output_length())
32
0
      throw Invalid_Argument("KDF1 maximum output length exceeeded");
33
34
0
   m_hash->update(secret, secret_len);
35
0
   m_hash->update(label, label_len);
36
0
   m_hash->update(salt, salt_len);
37
38
0
   if(key_len == m_hash->output_length())
39
0
      {
40
      // In this case we can hash directly into the output buffer
41
0
      m_hash->final(key);
42
0
      }
43
0
   else
44
0
      {
45
      // Otherwise a copy is required
46
0
      secure_vector<uint8_t> v = m_hash->final();
47
0
      copy_mem(key, v.data(), key_len);
48
0
      }
49
0
   }
50
51
}