aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/prf/hkdf/hkdf.h
blob: 6d1c41bec95d839a34bd0f999ea26e0042939f3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* HKDF
* (C) 2013 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_HKDF_H__
#define BOTAN_HKDF_H__

#include <botan/mac.h>
#include <botan/hash.h>

namespace Botan {

/**
* HKDF, see @rfc 5869 for details
*/
class BOTAN_DLL HKDF
   {
   public:
      HKDF(MessageAuthenticationCode* extractor,
           MessageAuthenticationCode* prf) :
         m_extractor(extractor), m_prf(prf) {}

      HKDF(MessageAuthenticationCode* prf) :
         m_extractor(prf), m_prf(m_extractor->clone()) {}

      void start_extract(const byte salt[], size_t salt_len);
      void extract(const byte input[], size_t input_len);
      void finish_extract();

      /**
      * Only call after extract
      * @param output_len must be less than 256*hashlen
      */
      void expand(byte output[], size_t output_len,
                  const byte info[], size_t info_len);

      std::string name() const;

      void clear();
   private:
      std::unique_ptr<MessageAuthenticationCode> m_extractor;
      std::unique_ptr<MessageAuthenticationCode> m_prf;
   };

}

#endif