Botan  2.4.0
Crypto and TLS for C++11
p11_ecdsa.h
Go to the documentation of this file.
1 /*
2 * PKCS#11 ECDSA
3 * (C) 2016 Daniel Neus, Sirrix AG
4 * (C) 2016 Philipp Weber, Sirrix AG
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #ifndef BOTAN_P11_ECDSA_H_
10 #define BOTAN_P11_ECDSA_H_
11 
12 #include <botan/p11.h>
13 
14 #if defined(BOTAN_HAS_ECDSA)
15 
16 #include <botan/p11_ecc_key.h>
17 #include <botan/ecdsa.h>
18 
19 #include <string>
20 
21 namespace Botan {
22 namespace PKCS11 {
23 class Session;
24 
25 /// Represents a PKCS#11 ECDSA public key
26 class BOTAN_PUBLIC_API(2,0) PKCS11_ECDSA_PublicKey final : public PKCS11_EC_PublicKey, public virtual ECDSA_PublicKey
27  {
28  public:
29  /**
30  * Creates a PKCS11_ECDSA_PublicKey object from an existing PKCS#11 ECDSA public key
31  * @param session the session to use
32  * @param handle the handle of the ECDSA public key
33  */
34  PKCS11_ECDSA_PublicKey(Session& session, ObjectHandle handle)
35  : EC_PublicKey(), PKCS11_EC_PublicKey(session, handle)
36  {}
37 
38  /**
39  * Imports an ECDSA public key
40  * @param session the session to use
41  * @param props the attributes of the public key
42  */
43  PKCS11_ECDSA_PublicKey(Session& session, const EC_PublicKeyImportProperties& props)
44  : EC_PublicKey(), PKCS11_EC_PublicKey(session, props)
45  {}
46 
47  inline std::string algo_name() const override
48  {
49  return "ECDSA";
50  }
51 
52  /// @return the exported ECDSA public key
53  ECDSA_PublicKey export_key() const;
54 
55  std::unique_ptr<PK_Ops::Verification>
56  create_verification_op(const std::string& params,
57  const std::string& provider) const override;
58  };
59 
60 /// Represents a PKCS#11 ECDSA private key
61 class BOTAN_PUBLIC_API(2,0) PKCS11_ECDSA_PrivateKey final : public PKCS11_EC_PrivateKey
62  {
63  public:
64  /**
65  * Creates a PKCS11_ECDSA_PrivateKey object from an existing PKCS#11 ECDSA private key
66  * @param session the session to use
67  * @param handle the handle of the ECDSA private key
68  */
69  PKCS11_ECDSA_PrivateKey(Session& session, ObjectHandle handle)
70  : PKCS11_EC_PrivateKey(session, handle)
71  {}
72 
73  /**
74  * Imports a ECDSA private key
75  * @param session the session to use
76  * @param props the attributes of the private key
77  */
78  PKCS11_ECDSA_PrivateKey(Session& session, const EC_PrivateKeyImportProperties& props)
79  : PKCS11_EC_PrivateKey(session, props)
80  {}
81 
82  /**
83  * Generates a PKCS#11 ECDSA private key
84  * @param session the session to use
85  * @param ec_params DER-encoding of an ANSI X9.62 Parameters value
86  * @param props the attributes of the private key
87  * @note no persistent public key object will be created
88  */
89  PKCS11_ECDSA_PrivateKey(Session& session, const std::vector<uint8_t>& ec_params,
90  const EC_PrivateKeyGenerationProperties& props)
91  : PKCS11_EC_PrivateKey(session, ec_params, props)
92  {}
93 
94  inline std::string algo_name() const override
95  {
96  return "ECDSA";
97  }
98 
99  /// @return the exported ECDSA private key
100  ECDSA_PrivateKey export_key() const;
101 
102  secure_vector<uint8_t> private_key_bits() const override;
103 
104  bool check_key(RandomNumberGenerator&, bool) const override;
105 
106  std::unique_ptr<PK_Ops::Signature>
107  create_signature_op(RandomNumberGenerator& rng,
108  const std::string& params,
109  const std::string& provider) const override;
110  };
111 
112 using PKCS11_ECDSA_KeyPair = std::pair<PKCS11_ECDSA_PublicKey, PKCS11_ECDSA_PrivateKey>;
113 
114 /**
115 * ECDSA key pair generation
116 * @param session the session that should be used for the key generation
117 * @param pub_props the properties of the public key
118 * @param priv_props the properties of the private key
119 */
120 BOTAN_PUBLIC_API(2,0) PKCS11_ECDSA_KeyPair generate_ecdsa_keypair(Session& session,
121  const EC_PublicKeyGenerationProperties& pub_props, const EC_PrivateKeyGenerationProperties& priv_props);
122 }
123 
124 }
125 
126 #endif
127 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: alg_id.cpp:13
CK_OBJECT_HANDLE ObjectHandle
Definition: p11.h:846