Botan 3.0.0-alpha0
Crypto and TLS for C&
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/asn1_obj.h>
13#include <string>
14
15namespace Botan {
16
17class Private_Key;
18class RandomNumberGenerator;
19
20/**
21* EMSA, from IEEE 1363s Encoding Method for Signatures, Appendix
22*
23* Any way of encoding/padding signatures
24*/
26 {
27 public:
28 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 */
57
58 /**
59 * Return true if using this EMSA correctly requires a signature scheme
60 * with message recovery
61 */
62 virtual bool requires_message_recovery() const = 0;
63
64 /**
65 * Return the encoding of a message
66 * @param msg the result of raw_data()
67 * @param output_bits the desired output bit size
68 * @param rng a random number generator
69 * @return encoded signature
70 */
72 size_t output_bits,
73 RandomNumberGenerator& rng) = 0;
74
75 /**
76 * Verify the encoding
77 * @param coded the received (coded) message representative
78 * @param raw the computed (local, uncoded) message representative
79 * @param key_bits the size of the key in bits
80 * @return true if coded is a valid encoding of raw, otherwise false
81 */
82 virtual bool verify(const secure_vector<uint8_t>& coded,
83 const secure_vector<uint8_t>& raw,
84 size_t key_bits) = 0;
85
86 /**
87 * Prepare sig_algo for use in choose_sig_format for x509 certs
88 *
89 * @param key used for checking compatibility with the encoding scheme
90 * @param cert_hash_name is checked to equal the hash for the encoding
91 * @return algorithm identifier to signatures created using this key,
92 * padding method and hash.
93 */
94 virtual AlgorithmIdentifier config_for_x509(const Private_Key& key,
95 const std::string& cert_hash_name) const;
96
97 /**
98 * @return a new object representing the same encoding method as *this
99 */
100 virtual std::unique_ptr<EMSA> new_object() = 0;
101
102 /**
103 * @return the SCAN name of the encoding/padding scheme
104 */
105 virtual std::string name() const = 0;
106 };
107
108/**
109* Returns the hash function used in the given EMSA scheme
110* If the hash function is not specified or not understood,
111* returns "SHA-512"
112* @param algo_spec the name of the EMSA
113* @return hash function used in the given EMSA scheme
114*/
115BOTAN_TEST_API std::string hash_for_emsa(const std::string& algo_spec);
116
117}
118
119#endif
virtual bool requires_message_recovery() const =0
virtual secure_vector< uint8_t > encoding_of(const secure_vector< uint8_t > &msg, size_t output_bits, RandomNumberGenerator &rng)=0
virtual std::unique_ptr< EMSA > new_object()=0
virtual bool verify(const secure_vector< uint8_t > &coded, const secure_vector< uint8_t > &raw, size_t key_bits)=0
virtual ~EMSA()=default
virtual secure_vector< uint8_t > raw_data()=0
virtual std::string name() const =0
virtual void update(const uint8_t input[], size_t length)=0
#define BOTAN_TEST_API
Definition: compiler.h:51
Definition: alg_id.cpp:13
std::string hash_for_emsa(const std::string &algo_spec)
Definition: emsa.cpp:197
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65