Coverage Report

Created: 2025-04-11 06:34

/src/botan/build/include/internal/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/hash.h>
12
#include <botan/internal/emsa.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
   public:
21
      /**
22
       * @param hash function to use
23
       * @param implicit whether or not the trailer is implicit
24
       */
25
      explicit ISO_9796_DS2(std::unique_ptr<HashFunction> hash, bool implicit = false) :
26
0
            m_hash(std::move(hash)), m_implicit(implicit), m_salt_len(hash->output_length()) {}
27
28
      /**
29
       * @param hash function to use
30
       * @param implicit whether or not the trailer is implicit
31
       * @param salt_size size of the salt to use in bytes
32
       */
33
      ISO_9796_DS2(std::unique_ptr<HashFunction> hash, bool implicit, size_t salt_size) :
34
0
            m_hash(std::move(hash)), m_implicit(implicit), m_salt_len(salt_size) {}
35
36
0
      std::string hash_function() const override { return m_hash->name(); }
37
38
      std::string name() const override;
39
40
   private:
41
      void update(const uint8_t input[], size_t length) override;
42
43
      std::vector<uint8_t> raw_data() override;
44
45
      std::vector<uint8_t> encoding_of(std::span<const uint8_t> msg,
46
                                       size_t output_bits,
47
                                       RandomNumberGenerator& rng) override;
48
49
      bool verify(std::span<const uint8_t> coded, std::span<const uint8_t> raw, size_t key_bits) override;
50
51
      std::unique_ptr<HashFunction> m_hash;
52
      bool m_implicit;
53
      size_t m_salt_len;
54
      std::vector<uint8_t> m_msg_buffer;
55
};
56
57
/**
58
* ISO-9796-2 - Digital signature scheme 3 (deterministic)
59
*/
60
class ISO_9796_DS3 final : public EMSA {
61
   public:
62
      /**
63
       * @param hash function to use
64
       * @param implicit whether or not the trailer is implicit
65
       */
66
      ISO_9796_DS3(std::unique_ptr<HashFunction> hash, bool implicit = false) :
67
0
            m_hash(std::move(hash)), m_implicit(implicit) {}
68
69
      std::string name() const override;
70
71
0
      std::string hash_function() const override { return m_hash->name(); }
72
73
   private:
74
      void update(const uint8_t input[], size_t length) override;
75
76
      std::vector<uint8_t> raw_data() override;
77
78
      std::vector<uint8_t> encoding_of(std::span<const uint8_t> msg,
79
                                       size_t output_bits,
80
                                       RandomNumberGenerator& rng) override;
81
82
      bool verify(std::span<const uint8_t> coded, std::span<const uint8_t> raw, size_t key_bits) override;
83
84
      std::unique_ptr<HashFunction> m_hash;
85
      bool m_implicit;
86
      std::vector<uint8_t> m_msg_buffer;
87
};
88
89
}  // namespace Botan
90
91
#endif