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