Botan  1.10.9
pk_keys.h
Go to the documentation of this file.
1 /*
2 * PK Key Types
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #ifndef BOTAN_PK_KEYS_H__
9 #define BOTAN_PK_KEYS_H__
10 
11 #include <botan/secmem.h>
12 #include <botan/asn1_oid.h>
13 #include <botan/alg_id.h>
14 #include <botan/rng.h>
15 
16 namespace Botan {
17 
18 /**
19 * Public Key Base Class.
20 */
21 class BOTAN_DLL Public_Key
22  {
23  public:
24  /**
25  * Get the name of the underlying public key scheme.
26  * @return name of the public key scheme
27  */
28  virtual std::string algo_name() const = 0;
29 
30  /**
31  * Get the OID of the underlying public key scheme.
32  * @return OID of the public key scheme
33  */
34  virtual OID get_oid() const;
35 
36  /**
37  * Test the key values for consistency.
38  * @param rng rng to use
39  * @param strong whether to perform strong and lengthy version
40  * of the test
41  * @return true if the test is passed
42  */
43  virtual bool check_key(RandomNumberGenerator& rng,
44  bool strong) const = 0;
45 
46  /**
47  * Find out the number of message parts supported by this scheme.
48  * @return number of message parts
49  */
50  virtual size_t message_parts() const { return 1; }
51 
52  /**
53  * Find out the message part size supported by this scheme/key.
54  * @return size of the message parts in bits
55  */
56  virtual size_t message_part_size() const { return 0; }
57 
58  /**
59  * Get the maximum message size in bits supported by this public key.
60  * @return maximum message size in bits
61  */
62  virtual size_t max_input_bits() const = 0;
63 
64  /**
65  * @return X.509 AlgorithmIdentifier for this key
66  */
67  virtual AlgorithmIdentifier algorithm_identifier() const = 0;
68 
69  /**
70  * @return X.509 subject key encoding for this key object
71  */
72  virtual MemoryVector<byte> x509_subject_public_key() const = 0;
73 
74  virtual ~Public_Key() {}
75  protected:
76  /**
77  * Self-test after loading a key
78  * @param rng a random number generator
79  */
80  virtual void load_check(RandomNumberGenerator& rng) const;
81  };
82 
83 /**
84 * Private Key Base Class
85 */
86 class BOTAN_DLL Private_Key : public virtual Public_Key
87  {
88  public:
89  /**
90  * @return PKCS #8 private key encoding for this key object
91  */
92  virtual MemoryVector<byte> pkcs8_private_key() const = 0;
93 
94  /**
95  * @return PKCS #8 AlgorithmIdentifier for this key
96  * Might be different from the X.509 identifier, but normally is not
97  */
99  { return algorithm_identifier(); }
100 
101  protected:
102  /**
103  * Self-test after loading a key
104  * @param rng a random number generator
105  */
106  void load_check(RandomNumberGenerator& rng) const;
107 
108  /**
109  * Self-test after generating a key
110  * @param rng a random number generator
111  */
112  void gen_check(RandomNumberGenerator& rng) const;
113  };
114 
115 /**
116 * PK Secret Value Derivation Key
117 */
118 class BOTAN_DLL PK_Key_Agreement_Key : public virtual Private_Key
119  {
120  public:
121  /*
122  * @return public component of this key
123  */
124  virtual MemoryVector<byte> public_value() const = 0;
125 
127  };
128 
129 /*
130 * Typedefs
131 */
135 
136 }
137 
138 #endif
virtual ~Public_Key()
Definition: pk_keys.h:74
virtual size_t message_part_size() const
Definition: pk_keys.h:56
Private_Key PKCS8_PrivateKey
Definition: pk_keys.h:134
Public_Key X509_PublicKey
Definition: pk_keys.h:133
PK_Key_Agreement_Key PK_KA_Key
Definition: pk_keys.h:132
std::string algo_name
Definition: ossl_md.cpp:42
RandomNumberGenerator * rng
Definition: global_rng.cpp:165
virtual size_t message_parts() const
Definition: pk_keys.h:50
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition: pk_keys.h:98
virtual ~PK_Key_Agreement_Key()
Definition: pk_keys.h:126