Botan  2.6.0
Crypto and TLS for C++11
emsa.h
Go to the documentation of this file.
1 /*
2 * EMSA Classes
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_PUBKEY_EMSA_H_
9 #define BOTAN_PUBKEY_EMSA_H_
10 
11 #include <botan/secmem.h>
12 #include <botan/alg_id.h>
13 
14 namespace Botan {
15 
16 class Private_Key;
17 class RandomNumberGenerator;
18 
19 /**
20 * EMSA, from IEEE 1363s Encoding Method for Signatures, Appendix
21 *
22 * Any way of encoding/padding signatures
23 */
25  {
26  public:
27  virtual ~EMSA() = default;
28 
29  /**
30  * Add more data to the signature computation
31  * @param input some data
32  * @param length length of input in bytes
33  */
34  virtual void update(const uint8_t input[], size_t length) = 0;
35 
36  /**
37  * @return raw hash
38  */
39  virtual secure_vector<uint8_t> raw_data() = 0;
40 
41  /**
42  * Return the encoding of a message
43  * @param msg the result of raw_data()
44  * @param output_bits the desired output bit size
45  * @param rng a random number generator
46  * @return encoded signature
47  */
48  virtual secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>& msg,
49  size_t output_bits,
50  RandomNumberGenerator& rng) = 0;
51 
52  /**
53  * Verify the encoding
54  * @param coded the received (coded) message representative
55  * @param raw the computed (local, uncoded) message representative
56  * @param key_bits the size of the key in bits
57  * @return true if coded is a valid encoding of raw, otherwise false
58  */
59  virtual bool verify(const secure_vector<uint8_t>& coded,
60  const secure_vector<uint8_t>& raw,
61  size_t key_bits) = 0;
62 
63  /**
64  * Prepare sig_algo for use in choose_sig_format for x509 certs
65  *
66  * @param key used for checking compatibility with the encoding scheme
67  * @param cert_hash_name is checked to equal the hash for the encoding
68  * @return algorithm identifier to signatures created using this key,
69  * padding method and hash.
70  */
71  virtual AlgorithmIdentifier config_for_x509(const Private_Key& key,
72  const std::string& cert_hash_name) const;
73 
74  /**
75  * @return a new object representing the same encoding method as *this
76  */
77  virtual EMSA* clone() = 0;
78 
79  /**
80  * @return the SCAN name of the encoding/padding scheme
81  */
82  virtual std::string name() const = 0;
83  };
84 
85 /**
86 * Factory method for EMSA (message-encoding methods for signatures
87 * with appendix) objects
88 * @param algo_spec the name of the EMSA to create
89 * @return pointer to newly allocated object of that type
90 */
91 BOTAN_PUBLIC_API(2,0) EMSA* get_emsa(const std::string& algo_spec);
92 
93 /**
94 * Returns the hash function used in the given EMSA scheme
95 * If the hash function is not specified or not understood,
96 * returns "SHA-512"
97 * @param algo_spec the name of the EMSA
98 * @return hash function used in the given EMSA scheme
99 */
100 BOTAN_PUBLIC_API(2,0) std::string hash_for_emsa(const std::string& algo_spec);
101 
102 }
103 
104 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: bigint.h:719
std::string hash_for_emsa(const std::string &algo_spec)
Definition: emsa.cpp:168
Definition: alg_id.cpp:13
EMSA * get_emsa(const std::string &algo_spec)
Definition: emsa.cpp:44
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88