Coverage Report

Created: 2021-05-04 09:02

/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
   private:
47
      void update(const uint8_t input[], size_t length) override;
48
49
      secure_vector<uint8_t> raw_data() override;
50
51
      secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>& msg,
52
                                      size_t output_bits,
53
                                      RandomNumberGenerator& rng) override;
54
55
      bool verify(const secure_vector<uint8_t>& coded,
56
                  const secure_vector<uint8_t>& raw,
57
                  size_t key_bits) override;
58
59
      std::unique_ptr<HashFunction> m_hash;
60
      bool m_implicit;
61
      size_t m_SALT_SIZE;
62
      secure_vector<uint8_t> m_msg_buffer;
63
   };
64
65
/**
66
* ISO-9796-2 - Digital signature scheme 3 (deterministic)
67
*/
68
class ISO_9796_DS3 final : public EMSA
69
   {
70
   public:
71
      /**
72
       * @param hash function to use
73
       * @param implicit whether or not the trailer is implicit
74
       */
75
      ISO_9796_DS3(std::unique_ptr<HashFunction> hash, bool implicit = false) :
76
         m_hash(std::move(hash)),
77
         m_implicit(implicit)
78
0
         {}
79
80
      std::unique_ptr<EMSA> new_object() override;
81
82
      std::string name() const override;
83
   private:
84
      void update(const uint8_t input[], size_t length) override;
85
86
      secure_vector<uint8_t> raw_data() override;
87
88
      secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>& msg,
89
                                      size_t output_bits,
90
                                      RandomNumberGenerator& rng) override;
91
92
      bool verify(const secure_vector<uint8_t>& coded,
93
                  const secure_vector<uint8_t>& raw,
94
                  size_t key_bits) override;
95
96
      std::unique_ptr<HashFunction> m_hash;
97
      bool m_implicit;
98
      secure_vector<uint8_t> m_msg_buffer;
99
   };
100
101
}
102
103
#endif
104