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