Coverage Report

Created: 2022-05-14 06:06

/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
7.37k
      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 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
      */
71
      virtual secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>& msg,
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
* Factory method for EMSA (message-encoding methods for signatures
110
* with appendix) objects
111
* @param algo_spec the name of the EMSA to create
112
* @return pointer to newly allocated object of that type
113
*/
114
BOTAN_TEST_API EMSA* get_emsa(const std::string& algo_spec);
115
116
/**
117
* Returns the hash function used in the given EMSA scheme
118
* If the hash function is not specified or not understood,
119
* returns "SHA-512"
120
* @param algo_spec the name of the EMSA
121
* @return hash function used in the given EMSA scheme
122
*/
123
BOTAN_TEST_API std::string hash_for_emsa(const std::string& algo_spec);
124
125
}
126
127
#endif