Coverage Report

Created: 2023-02-13 06:21

/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 RandomNumberGenerator;
18
19
/**
20
* EMSA, from IEEE 1363s Encoding Method for Signatures, Appendix
21
*
22
* Any way of encoding/padding signatures
23
*/
24
class BOTAN_TEST_API EMSA
25
   {
26
   public:
27
29.9k
      virtual ~EMSA() = default;
28
29
      /**
30
      * Factory method for EMSA (message-encoding methods for signatures
31
      * with appendix) objects
32
      * @param algo_spec the name of the EMSA to create
33
      * @return pointer to newly allocated object of that type, or nullptr
34
      */
35
      static std::unique_ptr<EMSA> create(const std::string& algo_spec);
36
37
      /**
38
      * Factory method for EMSA (message-encoding methods for signatures
39
      * with appendix) objects
40
      * @param algo_spec the name of the EMSA to create
41
      * @return pointer to newly allocated object of that type, or throws
42
      */
43
      static std::unique_ptr<EMSA> create_or_throw(const std::string& algo_spec);
44
45
      /**
46
      * Add more data to the signature computation
47
      * @param input some data
48
      * @param length length of input in bytes
49
      */
50
      virtual void update(const uint8_t input[], size_t length) = 0;
51
52
      /**
53
      * @return raw hash
54
      */
55
      virtual secure_vector<uint8_t> raw_data() = 0;
56
57
      /**
58
      * Return true if using this EMSA correctly requires a signature scheme
59
      * with message recovery
60
      */
61
      virtual bool requires_message_recovery() const = 0;
62
63
      /**
64
      * Return the encoding of a message
65
      * @param msg the result of raw_data()
66
      * @param output_bits the desired output bit size
67
      * @param rng a random number generator
68
      * @return encoded signature
69
      */
70
      virtual secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>& msg,
71
                                             size_t output_bits,
72
                                             RandomNumberGenerator& rng) = 0;
73
74
      /**
75
      * Verify the encoding
76
      * @param coded the received (coded) message representative
77
      * @param raw the computed (local, uncoded) message representative
78
      * @param key_bits the size of the key in bits
79
      * @return true if coded is a valid encoding of raw, otherwise false
80
      */
81
      virtual bool verify(const secure_vector<uint8_t>& coded,
82
                          const secure_vector<uint8_t>& raw,
83
                          size_t key_bits) = 0;
84
85
      /**
86
      * Prepare sig_algo for use in choose_sig_format for x509 certs
87
      *
88
      * @param algo_name used for checking compatibility with the encoding scheme
89
      *        this should match the canonical algorithm name eg "RSA", "ECDSA"
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 std::string& algo_name,
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
*/
115
BOTAN_TEST_API std::string hash_for_emsa(const std::string& algo_spec);
116
117
}
118
119
#endif