Coverage Report

Created: 2021-11-25 09:31

/src/botan/build/include/botan/internal/iso9796.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * ISO-9796-2 - Digital signature schemes giving message recovery schemes 2 and 3
3
 * (C) 2016 Tobias Niemann, Hackmanit GmbH
4
 *
5
 * Botan is released under the Simplified BSD License (see license.txt)
6
 */
7
8
#ifndef BOTAN_ISO9796_H_
9
#define BOTAN_ISO9796_H_
10
11
#include <botan/internal/emsa.h>
12
#include <botan/hash.h>
13
14
namespace Botan {
15
16
/**
17
* ISO-9796-2 - Digital signature scheme 2 (probabilistic)
18
*/
19
class ISO_9796_DS2 final : public EMSA
20
   {
21
   public:
22
      /**
23
       * @param hash function to use
24
       * @param implicit whether or not the trailer is implicit
25
       */
26
      explicit ISO_9796_DS2(std::unique_ptr<HashFunction> hash, bool implicit = false) :
27
         m_hash(std::move(hash)),
28
         m_implicit(implicit),
29
         m_SALT_SIZE(hash->output_length())
30
0
         {}
31
32
      /**
33
       * @param hash function to use
34
       * @param implicit whether or not the trailer is implicit
35
       * @param salt_size size of the salt to use in bytes
36
       */
37
      ISO_9796_DS2(std::unique_ptr<HashFunction> hash, bool implicit, size_t salt_size) :
38
         m_hash(std::move(hash)),
39
         m_implicit(implicit),
40
         m_SALT_SIZE(salt_size)
41
0
         {}
42
43
      std::unique_ptr<EMSA> new_object() override;
44
45
      std::string name() const override;
46
47
0
      bool requires_message_recovery() const override { return true; }
48
   private:
49
      void update(const uint8_t input[], size_t length) override;
50
51
      secure_vector<uint8_t> raw_data() override;
52
53
      secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>& msg,
54
                                      size_t output_bits,
55
                                      RandomNumberGenerator& rng) override;
56
57
      bool verify(const secure_vector<uint8_t>& coded,
58
                  const secure_vector<uint8_t>& raw,
59
                  size_t key_bits) override;
60
61
      std::unique_ptr<HashFunction> m_hash;
62
      bool m_implicit;
63
      size_t m_SALT_SIZE;
64
      secure_vector<uint8_t> m_msg_buffer;
65
   };
66
67
/**
68
* ISO-9796-2 - Digital signature scheme 3 (deterministic)
69
*/
70
class ISO_9796_DS3 final : public EMSA
71
   {
72
   public:
73
      /**
74
       * @param hash function to use
75
       * @param implicit whether or not the trailer is implicit
76
       */
77
      ISO_9796_DS3(std::unique_ptr<HashFunction> hash, bool implicit = false) :
78
         m_hash(std::move(hash)),
79
         m_implicit(implicit)
80
0
         {}
81
82
      std::unique_ptr<EMSA> new_object() override;
83
84
      std::string name() const override;
85
86
0
      bool requires_message_recovery() const override { return true; }
87
88
   private:
89
      void update(const uint8_t input[], size_t length) override;
90
91
      secure_vector<uint8_t> raw_data() override;
92
93
      secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>& msg,
94
                                      size_t output_bits,
95
                                      RandomNumberGenerator& rng) override;
96
97
      bool verify(const secure_vector<uint8_t>& coded,
98
                  const secure_vector<uint8_t>& raw,
99
                  size_t key_bits) override;
100
101
      std::unique_ptr<HashFunction> m_hash;
102
      bool m_implicit;
103
      secure_vector<uint8_t> m_msg_buffer;
104
   };
105
106
}
107
108
#endif
109