Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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