Coverage Report

Created: 2020-11-21 08:34

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