Botan  1.10.9
gost_3410.h
Go to the documentation of this file.
1 /*
2 * GOST 34.10-2001
3 * (C) 2007 Falko Strenzke, FlexSecure GmbH
4 * Manuel Hartl, FlexSecure GmbH
5 * (C) 2008-2010 Jack Lloyd
6 *
7 * Distributed under the terms of the Botan license
8 */
9 
10 #ifndef BOTAN_GOST_3410_KEY_H__
11 #define BOTAN_GOST_3410_KEY_H__
12 
13 #include <botan/ecc_key.h>
14 #include <botan/pk_ops.h>
15 
16 namespace Botan {
17 
18 /**
19 * GOST-34.10 Public Key
20 */
21 class BOTAN_DLL GOST_3410_PublicKey : public virtual EC_PublicKey
22  {
23  public:
24 
25  /**
26  * Construct a public key from a given public point.
27  * @param dom_par the domain parameters associated with this key
28  * @param public_point the public point defining this key
29  */
30  GOST_3410_PublicKey(const EC_Group& dom_par,
31  const PointGFp& public_point) :
32  EC_PublicKey(dom_par, public_point) {}
33 
34  /**
35  * Construct from X.509 algorithm id and subject public key bits
36  */
38  const MemoryRegion<byte>& key_bits);
39 
40  /**
41  * Get this keys algorithm name.
42  * @result this keys algorithm name
43  */
44  std::string algo_name() const { return "GOST-34.10"; }
45 
46  AlgorithmIdentifier algorithm_identifier() const;
47 
48  MemoryVector<byte> x509_subject_public_key() const;
49 
50  /**
51  * Get the maximum number of bits allowed to be fed to this key.
52  * This is the bitlength of the order of the base point.
53 
54  * @result the maximum number of input bits
55  */
56  size_t max_input_bits() const { return domain().get_order().bits(); }
57 
58  size_t message_parts() const { return 2; }
59 
60  size_t message_part_size() const
61  { return domain().get_order().bytes(); }
62 
63  protected:
65  };
66 
67 /**
68 * GOST-34.10 Private Key
69 */
70 class BOTAN_DLL GOST_3410_PrivateKey : public GOST_3410_PublicKey,
71  public EC_PrivateKey
72  {
73  public:
74 
76  const MemoryRegion<byte>& key_bits) :
77  EC_PrivateKey(alg_id, key_bits) {}
78 
79  /**
80  * Generate a new private key
81  * @param rng a random number generator
82  * @param domain parameters to used for this key
83  * @param x the private key; if zero, a new random key is generated
84  */
86  const EC_Group& domain,
87  const BigInt& x = 0) :
88  EC_PrivateKey(rng, domain, x) {}
89 
92  };
93 
94 /**
95 * GOST-34.10 signature operation
96 */
98  {
99  public:
101 
102  size_t message_parts() const { return 2; }
103  size_t message_part_size() const { return order.bytes(); }
104  size_t max_input_bits() const { return order.bits(); }
105 
106  SecureVector<byte> sign(const byte msg[], size_t msg_len,
108 
109  private:
110  const PointGFp& base_point;
111  const BigInt& order;
112  const BigInt& x;
113  };
114 
115 /**
116 * GOST-34.10 verification operation
117 */
119  {
120  public:
122 
123  size_t message_parts() const { return 2; }
124  size_t message_part_size() const { return order.bytes(); }
125  size_t max_input_bits() const { return order.bits(); }
126 
127  bool with_recovery() const { return false; }
128 
129  bool verify(const byte msg[], size_t msg_len,
130  const byte sig[], size_t sig_len);
131  private:
132  const PointGFp& base_point;
133  const PointGFp& public_point;
134  const BigInt& order;
135  };
136 
137 }
138 
139 #endif
GOST_3410_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition: gost_3410.h:85
unsigned char byte
Definition: types.h:22
RandomNumberGenerator * rng
Definition: global_rng.cpp:165
AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition: gost_3410.h:90
size_t message_part_size() const
Definition: gost_3410.h:60
std::string algo_name() const
Definition: gost_3410.h:44
size_t message_parts() const
Definition: gost_3410.h:58
GOST_3410_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition: gost_3410.h:30
GOST_3410_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: gost_3410.h:75
size_t max_input_bits() const
Definition: gost_3410.h:56
AlgorithmIdentifier algorithm_identifier() const
Definition: ecc_key.cpp:45