Botan 2.19.5 Crypto and TLS for C&

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 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 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 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;
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
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 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 const BigInt& get_da_inv() const { return m_da_inv; }
103 private:
104 BigInt m_da_inv;
105 };
106
107 class HashFunction;
108
109std::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
116typedef SM2_PublicKey SM2_Signature_PublicKey;
117typedef SM2_PublicKey SM2_Encryption_PublicKey;
118
119typedef SM2_PrivateKey SM2_Signature_PrivateKey;
120typedef SM2_PrivateKey SM2_Encryption_PrivateKey;
121
122}
123
124#endif
Botan::AlgorithmIdentifier
Definition: asn1_obj.h:430
Botan::BigInt
Definition: bigint.h:25
Botan::EC_Group
Definition: ec_group.h:46
Botan::EC_PrivateKey
Definition: ecc_key.h:125
Botan::EC_PublicKey
Definition: ecc_key.h:29
Botan::PointGFp
Definition: point_gfp.h:48
Botan::RandomNumberGenerator
Definition: rng.h:26
Botan::SM2_PrivateKey
Definition: sm2.h:69
Botan::SM2_PrivateKey::get_da_inv
const BigInt & get_da_inv() const
Definition: sm2.h:102
Botan::SM2_PublicKey
Definition: sm2.h:19
Botan::SM2_PublicKey::SM2_PublicKey
SM2_PublicKey()=default
Botan::SM2_PublicKey::message_part_size
size_t message_part_size() const override
Definition: sm2.h:48
Botan::SM2_PublicKey::SM2_PublicKey
SM2_PublicKey(const AlgorithmIdentifier &alg_id, const std::vector< uint8_t > &key_bits)
Definition: sm2.h:36
Botan::SM2_PublicKey::message_parts
size_t message_parts() const override
Definition: sm2.h:46
Botan::SM2_PublicKey::SM2_PublicKey
SM2_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: sm2.h:27
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
Definition: alg_id.cpp:13
Botan::sm2_compute_za
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, const std::string &user_id, const EC_Group &domain, const PointGFp &pubkey)
Definition: sm2.cpp:52
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
std
Definition: bigint.h:1155
hash
MechanismType hash
Definition: p11_mechanism.cpp:64