Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

p11_ecdh.h
Go to the documentation of this file.
1 /*
2 * PKCS#11 ECDH
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_ECDH_H__
10 #define BOTAN_P11_ECDH_H__
11
12 #include <botan/build.h>
13 #if defined(BOTAN_HAS_ECDH)
14
15 #include <botan/p11.h>
16 #include <botan/p11_ecc_key.h>
17 #include <botan/ecdh.h>
18
19 #include <string>
20 #include <vector>
21
22 namespace Botan {
23 namespace PKCS11 {
24 class Session;
25
26 /// Represents a PKCS#11 ECDH public key
27 class BOTAN_DLL PKCS11_ECDH_PublicKey final : public PKCS11_EC_PublicKey
28 {
29 public:
30 /**
31 * Create a PKCS11_ECDH_PublicKey object from an existing PKCS#11 ECDH public key
32 * @param session the session to use
33 * @param handle the handle of the ECDH public key
34 */
35 PKCS11_ECDH_PublicKey(Session& session, ObjectHandle handle)
36 : EC_PublicKey(), PKCS11_EC_PublicKey(session, handle)
37 {}
38
39 /**
40 * Imports a ECDH public key
41 * @param session the session to use
42 * @param props the attributes of the public key
43 */
44 PKCS11_ECDH_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 "ECDH";
51 }
52
53 /// @return the exported ECDH public key
54 ECDH_PublicKey export_key() const;
55 };
56
57 /// Represents a PKCS#11 ECDH private key
58 class BOTAN_DLL PKCS11_ECDH_PrivateKey final : public virtual PKCS11_EC_PrivateKey, public virtual PK_Key_Agreement_Key
59 {
60 public:
61 /**
62 * Creates a PKCS11_ECDH_PrivateKey object from an existing PKCS#11 ECDH private key
63 * @param session the session to use
64 * @param handle the handle of the ECDH private key
65 */
66 PKCS11_ECDH_PrivateKey(Session& session, ObjectHandle handle)
67 : PKCS11_EC_PrivateKey(session, handle)
68 {}
69
70 /**
71 * Imports an ECDH private key
72 * @param session the session to use
73 * @param props the attributes of the private key
74 */
75 PKCS11_ECDH_PrivateKey(Session& session, const EC_PrivateKeyImportProperties& props)
76 : PKCS11_EC_PrivateKey(session, props)
77 {}
78
79 /**
80 * Generates a PKCS#11 ECDH private key
81 * @param session the session to use
82 * @param ec_params DER-encoding of an ANSI X9.62 Parameters value
83 * @param props the attributes of the private key
84 * @note no persistent public key object will be created
85 */
86 PKCS11_ECDH_PrivateKey(Session& session, const std::vector<uint8_t>& ec_params,
87 const EC_PrivateKeyGenerationProperties& props)
88 : PKCS11_EC_PrivateKey(session, ec_params, props)
89 {}
90
91 inline std::string algo_name() const override
92 {
93 return "ECDH";
94 }
95
96 inline std::vector<uint8_t> public_value() const override
97 {
98 return unlock(EC2OSP(public_point(), PointGFp::UNCOMPRESSED));
99 }
100
101 /// @return the exported ECDH private key
102 ECDH_PrivateKey export_key() const;
103
104 secure_vector<uint8_t> private_key_bits() const override;
105
106 std::unique_ptr<PK_Ops::Key_Agreement>
107 create_key_agreement_op(RandomNumberGenerator& rng,
108 const std::string& params,
109 const std::string& provider) const override;
110 };
111
112 using PKCS11_ECDH_KeyPair = std::pair<PKCS11_ECDH_PublicKey, PKCS11_ECDH_PrivateKey>;
113
114 /**
115 * PKCS#11 ECDH 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_DLL PKCS11_ECDH_KeyPair generate_ecdh_keypair(Session& session, const EC_PublicKeyGenerationProperties& pub_props,
121 const EC_PrivateKeyGenerationProperties& priv_props);
122 }
123
124 }
125
126 #endif
127 #endif
Botan::PointGFp::UNCOMPRESSED
Definition: point_gfp.h:45
Botan::EC2OSP
secure_vector< uint8_t > EC2OSP(const PointGFp &point, uint8_t format)
Definition: point_gfp.cpp:470
Botan
Definition: alg_id.cpp:13
Botan::PKCS11::ObjectHandle
CK_OBJECT_HANDLE ObjectHandle
Definition: p11.h:846
Botan::unlock
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:125