/src/botan/build/include/botan/sm2.h
Line | Count | Source (jump to first uncovered line) |
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 public keys |
17 | | */ |
18 | | class BOTAN_PUBLIC_API(2,2) SM2_PublicKey : public virtual EC_PublicKey |
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 | | */ |
27 | | SM2_PublicKey(const EC_Group& dom_par, |
28 | | const PointGFp& public_point) : |
29 | 0 | 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 | | */ |
36 | | SM2_PublicKey(const AlgorithmIdentifier& alg_id, |
37 | | const std::vector<uint8_t>& key_bits) : |
38 | 0 | EC_PublicKey(alg_id, key_bits) {} Unexecuted instantiation: Botan::SM2_PublicKey::SM2_PublicKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&) Unexecuted instantiation: Botan::SM2_PublicKey::SM2_PublicKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&) |
39 | | |
40 | | /** |
41 | | * Get this keys algorithm name. |
42 | | * @result this keys algorithm name |
43 | | */ |
44 | | std::string algo_name() const override; |
45 | | |
46 | 0 | size_t message_parts() const override { return 2; } |
47 | | |
48 | | size_t message_part_size() const override |
49 | 0 | { 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 | | |
55 | | std::unique_ptr<PK_Ops::Encryption> |
56 | | create_encryption_op(RandomNumberGenerator& rng, |
57 | | const std::string& params, |
58 | | const std::string& provider) const override; |
59 | | |
60 | | protected: |
61 | 0 | SM2_PublicKey() = default; |
62 | | }; |
63 | | |
64 | | /** |
65 | | * This class represents SM2 private keys |
66 | | */ |
67 | | class BOTAN_PUBLIC_API(2,2) SM2_PrivateKey final : |
68 | | public SM2_PublicKey, public EC_PrivateKey |
69 | | { |
70 | | public: |
71 | | |
72 | | /** |
73 | | * Load a private key |
74 | | * @param alg_id the X.509 algorithm identifier |
75 | | * @param key_bits ECPrivateKey bits |
76 | | */ |
77 | | SM2_PrivateKey(const AlgorithmIdentifier& alg_id, |
78 | | const secure_vector<uint8_t>& key_bits); |
79 | | |
80 | | /** |
81 | | * Create a private key. |
82 | | * @param rng a random number generator |
83 | | * @param domain parameters to used for this key |
84 | | * @param x the private key (if zero, generate a new random key) |
85 | | */ |
86 | | SM2_PrivateKey(RandomNumberGenerator& rng, |
87 | | const EC_Group& domain, |
88 | | const BigInt& x = 0); |
89 | | |
90 | | bool check_key(RandomNumberGenerator& rng, bool) const override; |
91 | | |
92 | | std::unique_ptr<PK_Ops::Signature> |
93 | | create_signature_op(RandomNumberGenerator& rng, |
94 | | const std::string& params, |
95 | | const std::string& provider) const override; |
96 | | |
97 | | std::unique_ptr<PK_Ops::Decryption> |
98 | | create_decryption_op(RandomNumberGenerator& rng, |
99 | | const std::string& params, |
100 | | const std::string& provider) const override; |
101 | | |
102 | 0 | const BigInt& get_da_inv() const { return m_da_inv; } |
103 | | private: |
104 | | BigInt m_da_inv; |
105 | | }; |
106 | | |
107 | | class HashFunction; |
108 | | |
109 | | std::vector<uint8_t> |
110 | | BOTAN_PUBLIC_API(2,5) sm2_compute_za(HashFunction& hash, |
111 | | const std::string& user_id, |
112 | | const EC_Group& domain, |
113 | | const PointGFp& pubkey); |
114 | | |
115 | | // For compat with versions 2.2 - 2.7 |
116 | | typedef SM2_PublicKey SM2_Signature_PublicKey; |
117 | | typedef SM2_PublicKey SM2_Encryption_PublicKey; |
118 | | |
119 | | typedef SM2_PrivateKey SM2_Signature_PrivateKey; |
120 | | typedef SM2_PrivateKey SM2_Encryption_PrivateKey; |
121 | | |
122 | | } |
123 | | |
124 | | #endif |