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