Botan 2.19.5 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/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 size_t message_parts() const override { return 2; }
101
102 size_t message_part_size() const override
103 { return domain().get_order().bytes(); }
104
105 /// @return the exported ECDSA private key
106 ECDSA_PrivateKey export_key() const;
107
108 secure_vector<uint8_t> private_key_bits() const override;
109
110 bool check_key(RandomNumberGenerator&, bool) const override;
111
112 std::unique_ptr<PK_Ops::Signature>
113 create_signature_op(RandomNumberGenerator& rng,
114 const std::string& params,
115 const std::string& provider) const override;
116 };
117
118 using PKCS11_ECDSA_KeyPair = std::pair<PKCS11_ECDSA_PublicKey, PKCS11_ECDSA_PrivateKey>;
119
120/**
121* ECDSA key pair generation
122* @param session the session that should be used for the key generation
123* @param pub_props the properties of the public key
124* @param priv_props the properties of the private key
125*/
126 BOTAN_PUBLIC_API(2,0) PKCS11_ECDSA_KeyPair generate_ecdsa_keypair(Session& session,
127 const EC_PublicKeyGenerationProperties& pub_props, const EC_PrivateKeyGenerationProperties& priv_props);
128}
129
130}
131
132#endif
133#endif
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::PKCS11::ObjectHandle
CK_OBJECT_HANDLE ObjectHandle
Definition: p11.h:848
Botan
Definition: alg_id.cpp:13