Botan  2.7.0
Crypto and TLS for C++11
sm2_enc.h
Go to the documentation of this file.
1 /*
2 * SM2 Encryption
3 * (C) 2017 Ribose Inc
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_SM2_ENC_KEY_H_
9 #define BOTAN_SM2_ENC_KEY_H_
10 
11 #include <botan/ecc_key.h>
12 
13 namespace Botan {
14 
15 /**
16 * This class represents a public key used for SM2 encryption
17 */
19  {
20  public:
21 
22  /**
23  * Create a public key from a given public point.
24  * @param dom_par the domain parameters associated with this key
25  * @param public_point the public point defining this key
26  */
28  const PointGFp& public_point) :
29  EC_PublicKey(dom_par, public_point) {}
30 
31  /**
32  * Load a public key.
33  * @param alg_id the X.509 algorithm identifier
34  * @param key_bits DER encoded public key bits
35  */
37  const std::vector<uint8_t>& key_bits) :
38  EC_PublicKey(alg_id, key_bits) {}
39 
40  /**
41  * Get this keys algorithm name.
42  * @result this keys algorithm name
43  */
44  std::string algo_name() const override { return "SM2_Enc"; }
45 
46  std::unique_ptr<PK_Ops::Encryption>
47  create_encryption_op(RandomNumberGenerator& rng,
48  const std::string& params,
49  const std::string& provider) const override;
50  protected:
51  SM2_Encryption_PublicKey() = default;
52  };
53 
54 /**
55 * This class represents a private key used for SM2 encryption
56 */
59  {
60  public:
61 
62  /**
63  * Load a private key
64  * @param alg_id the X.509 algorithm identifier
65  * @param key_bits ECPrivateKey bits
66  */
68  const secure_vector<uint8_t>& key_bits);
69 
70  /**
71  * Create a private key.
72  * @param rng a random number generator
73  * @param domain parameters to used for this key
74  * @param x the private key (if zero, generate a new random key)
75  */
77  const EC_Group& domain,
78  const BigInt& x = 0);
79 
80  bool check_key(RandomNumberGenerator& rng, bool) const override;
81 
82  std::unique_ptr<PK_Ops::Decryption>
83  create_decryption_op(RandomNumberGenerator& rng,
84  const std::string& params,
85  const std::string& provider) const override;
86  };
87 
88 }
89 
90 #endif
SM2_Encryption_PublicKey(const AlgorithmIdentifier &alg_id, const std::vector< uint8_t > &key_bits)
Definition: sm2_enc.h:36
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
SM2_Encryption_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: sm2_enc.h:27
std::string algo_name() const override
Definition: sm2_enc.h:44
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88