Botan  2.6.0
Crypto and TLS for C++11
sm2.h
Go to the documentation of this file.
1 /*
2 * SM2
3 * (C) 2017 Ribose Inc
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_SM2_KEY_H_
9 #define BOTAN_SM2_KEY_H_
10 
11 #include <botan/ecc_key.h>
12 
13 namespace Botan {
14 
15 /**
16 * This class represents SM2 Signature public keys
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_Sig"; }
45 
46  size_t message_parts() const override { return 2; }
47 
48  size_t message_part_size() const override
49  { return domain().get_order().bytes(); }
50 
51  std::unique_ptr<PK_Ops::Verification>
52  create_verification_op(const std::string& params,
53  const std::string& provider) const override;
54  protected:
55  SM2_Signature_PublicKey() = default;
56  };
57 
58 /**
59 * This class represents SM2 Signature private keys
60 */
63  {
64  public:
65 
66  /**
67  * Load a private key
68  * @param alg_id the X.509 algorithm identifier
69  * @param key_bits ECPrivateKey bits
70  */
72  const secure_vector<uint8_t>& key_bits);
73 
74  /**
75  * Create a private key.
76  * @param rng a random number generator
77  * @param domain parameters to used for this key
78  * @param x the private key (if zero, generate a new random key)
79  */
81  const EC_Group& domain,
82  const BigInt& x = 0);
83 
84  bool check_key(RandomNumberGenerator& rng, bool) const override;
85 
86  std::unique_ptr<PK_Ops::Signature>
87  create_signature_op(RandomNumberGenerator& rng,
88  const std::string& params,
89  const std::string& provider) const override;
90 
91  const BigInt& get_da_inv() const { return m_da_inv; }
92  private:
93  BigInt m_da_inv;
94  };
95 
96 class HashFunction;
97 
98 std::vector<uint8_t>
99 BOTAN_PUBLIC_API(2,5) sm2_compute_za(HashFunction& hash,
100  const std::string& user_id,
101  const EC_Group& domain,
102  const PointGFp& pubkey);
103 
104 }
105 
106 #endif
std::string algo_name() const override
Definition: sm2.h:44
size_t message_parts() const override
Definition: sm2.h:46
size_t message_part_size() const override
Definition: sm2.h:48
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
const BigInt & get_da_inv() const
Definition: sm2.h:91
Definition: bigint.h:719
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, const std::string &user_id, const EC_Group &domain, const PointGFp &pubkey)
Definition: sm2.cpp:44
Definition: alg_id.cpp:13
SM2_Signature_PublicKey(const AlgorithmIdentifier &alg_id, const std::vector< uint8_t > &key_bits)
Definition: sm2.h:36
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
SM2_Signature_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: sm2.h:27
MechanismType hash