aboutsummaryrefslogtreecommitdiffstats
path: root/src/cms/cms_enc.h
blob: f3907cd7b4c2db23023b0376aae6188fd5829850 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*************************************************
* CMS Encoding Header File                       *
* (C) 1999-2007 Jack Lloyd                       *
*************************************************/

#ifndef BOTAN_CMS_ENCODER_H__
#define BOTAN_CMS_ENCODER_H__

#include <botan/x509cert.h>
#include <botan/x509stor.h>
#include <botan/pkcs8.h>

namespace Botan {

/*************************************************
* CMS Encoding Operation                         *
*************************************************/
class CMS_Encoder
   {
   public:

      void encrypt(RandomNumberGenerator&,
                   const X509_Certificate&, const std::string = "");

      void encrypt(RandomNumberGenerator& rng,
                   const std::string&, const std::string& = "");

      void encrypt(RandomNumberGenerator& rng,
                   const SymmetricKey&, const std::string& = "");

      void authenticate(const X509_Certificate&, const std::string& = "");
      void authenticate(const std::string&, const std::string& = "");
      void authenticate(const SymmetricKey&, const std::string& = "");

      void sign(const X509_Certificate& cert,
                const PKCS8_PrivateKey& key,
                RandomNumberGenerator& rng,
                const std::vector<X509_Certificate>& cert_chain,
                const std::string& hash,
                const std::string& padding);

      void digest(const std::string& = "");

      void compress(const std::string&);
      static bool can_compress_with(const std::string&);

      SecureVector<byte> get_contents();
      std::string PEM_contents();

      void set_data(const std::string&);
      void set_data(const byte[], u32bit);

      CMS_Encoder(const std::string& str) { set_data(str); }
      CMS_Encoder(const byte buf[], u32bit length) { set_data(buf, length); }
   private:
      void add_layer(const std::string&, DER_Encoder&);

      void encrypt_ktri(RandomNumberGenerator&,
                        const X509_Certificate&, PK_Encrypting_Key*,
                        const std::string&);
      void encrypt_kari(RandomNumberGenerator&,
                        const X509_Certificate&, X509_PublicKey*,
                        const std::string&);

      SecureVector<byte> do_encrypt(RandomNumberGenerator& rng,
                                    const SymmetricKey&, const std::string&);

      static SecureVector<byte> make_econtent(const SecureVector<byte>&,
                                              const std::string&);

      static SymmetricKey setup_key(RandomNumberGenerator& rng,
                                    const std::string&);

      static SecureVector<byte> wrap_key(RandomNumberGenerator& rng,
                                         const std::string&,
                                         const SymmetricKey&,
                                         const SymmetricKey&);

      static SecureVector<byte> encode_params(const std::string&,
                                              const SymmetricKey&,
                                              const InitializationVector&);

      SecureVector<byte> data;
      std::string type;
   };

}

#endif