Botan 3.5.0
Crypto and TLS for C&
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/ecdsa.h>
18 #include <botan/p11_ecc_key.h>
19
20 #include <string>
21
22namespace Botan::PKCS11 {
23class Session;
24
25/// Represents a PKCS#11 ECDSA public key
26
29
30class BOTAN_PUBLIC_API(2, 0) PKCS11_ECDSA_PublicKey final : public PKCS11_EC_PublicKey,
31 public virtual ECDSA_PublicKey {
32 public:
33 /**
34 * Creates a PKCS11_ECDSA_PublicKey object from an existing PKCS#11 ECDSA public key
35 * @param session the session to use
36 * @param handle the handle of the ECDSA public key
37 */
38 PKCS11_ECDSA_PublicKey(Session& session, ObjectHandle handle) :
39 EC_PublicKey(), PKCS11_EC_PublicKey(session, handle) {}
40
41 /**
42 * Imports an ECDSA public key
43 * @param session the session to use
44 * @param props the attributes of the public key
45 */
46 PKCS11_ECDSA_PublicKey(Session& session, const EC_PublicKeyImportProperties& props) :
47 EC_PublicKey(), PKCS11_EC_PublicKey(session, props) {}
48
49 inline std::string algo_name() const override { return "ECDSA"; }
50
51 /// @return the exported ECDSA public key
52 ECDSA_PublicKey export_key() const;
53
54 /**
55 * @throws Not_Implemented
56 */
57 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator&) const final {
58 throw Not_Implemented("Cannot generate a new PKCS#11 ECDSA keypair from this public key");
59 }
60
61 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
62 std::string_view provider) const override;
63};
64
66
67/// Represents a PKCS#11 ECDSA private key
68class BOTAN_PUBLIC_API(2, 0) PKCS11_ECDSA_PrivateKey final : public PKCS11_EC_PrivateKey {
69 public:
70 /**
71 * Creates a PKCS11_ECDSA_PrivateKey object from an existing PKCS#11 ECDSA private key
72 * @param session the session to use
73 * @param handle the handle of the ECDSA private key
74 */
75 PKCS11_ECDSA_PrivateKey(Session& session, ObjectHandle handle) : PKCS11_EC_PrivateKey(session, handle) {}
76
77 /**
78 * Imports a ECDSA private key
79 * @param session the session to use
80 * @param props the attributes of the private key
81 */
82 PKCS11_ECDSA_PrivateKey(Session& session, const EC_PrivateKeyImportProperties& props) :
83 PKCS11_EC_PrivateKey(session, props) {}
84
85 /**
86 * Generates a PKCS#11 ECDSA private key
87 * @param session the session to use
88 * @param ec_params DER-encoding of an ANSI X9.62 Parameters value
89 * @param props the attributes of the private key
90 * @note no persistent public key object will be created
91 */
92 PKCS11_ECDSA_PrivateKey(Session& session,
93 const std::vector<uint8_t>& ec_params,
94 const EC_PrivateKeyGenerationProperties& props) :
95 PKCS11_EC_PrivateKey(session, ec_params, props) {}
96
97 inline std::string algo_name() const override { return "ECDSA"; }
98
99 /**
100 * @throws Not_Implemented
101 */
102 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator&) const override {
103 throw Not_Implemented("Cannot generate a new PKCS#11 ECDSA keypair from this private key");
104 }
105
106 bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
107
108 size_t message_parts() const override { return 2; }
109
110 size_t message_part_size() const override { return domain().get_order_bytes(); }
111
112 /// @return the exported ECDSA private key
113 ECDSA_PrivateKey export_key() const;
114
115 std::unique_ptr<Public_Key> public_key() const override;
116
117 secure_vector<uint8_t> private_key_bits() const override;
118
119 bool check_key(RandomNumberGenerator&, bool) const override;
120
121 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
122 std::string_view params,
123 std::string_view provider) const override;
124};
125
126using PKCS11_ECDSA_KeyPair = std::pair<PKCS11_ECDSA_PublicKey, PKCS11_ECDSA_PrivateKey>;
127
128/**
129* ECDSA key pair generation
130* @param session the session that should be used for the key generation
131* @param pub_props the properties of the public key
132* @param priv_props the properties of the private key
133*/
135PKCS11_ECDSA_KeyPair generate_ecdsa_keypair(Session& session,
136 const EC_PublicKeyGenerationProperties& pub_props,
137 const EC_PrivateKeyGenerationProperties& priv_props);
138} // namespace Botan::PKCS11
139
140#endif
141#endif
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition compiler.h:191
#define BOTAN_DIAGNOSTIC_PUSH
Definition compiler.h:188
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition compiler.h:190
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31