aboutsummaryrefslogtreecommitdiffstats
path: root/src/pbe/pbes2/pbes2.h
blob: 4c9eb9b8ac5ca6efadd9e67b741cfa3e1631d798 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* PKCS #5 v2.0 PBE
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_PBE_PKCS_v20_H__
#define BOTAN_PBE_PKCS_v20_H__

#include <botan/pbe.h>
#include <botan/block_cipher.h>
#include <botan/mac.h>
#include <botan/pipe.h>

namespace Botan {

/**
* PKCS #5 v2.0 PBE
*/
class BOTAN_DLL PBE_PKCS5v20 : public PBE
   {
   public:
      OID get_oid() const;

      std::vector<byte> encode_params() const;

      std::string name() const;

      void write(const byte[], size_t);
      void start_msg();
      void end_msg();

      /**
      * Load a PKCS #5 v2.0 encrypted stream
      * @param input is the input source
      */
      PBE_PKCS5v20(const std::vector<byte>& params,
                   const std::string& passphrase);

      /**
      * @param cipher the block cipher to use
      * @param hash the hash function to use
      */
      PBE_PKCS5v20(BlockCipher* cipher,
                   MessageAuthenticationCode* mac,
                   const std::string& passphrase,
                   std::chrono::milliseconds msec,
                   RandomNumberGenerator& rng);

      ~PBE_PKCS5v20();
   private:
      void flush_pipe(bool);

      Cipher_Dir direction;
      BlockCipher* block_cipher;
      MessageAuthenticationCode* m_prf;
      secure_vector<byte> salt, key, iv;
      size_t iterations, key_length;
      Pipe pipe;
   };

}

#endif