Botan 3.6.1
Crypto and TLS for C&
iso9796.h
Go to the documentation of this file.
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
14namespace Botan {
15
16/**
17* ISO-9796-2 - Digital signature scheme 2 (probabilistic)
18*/
19class 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 m_hash(std::move(hash)), m_implicit(implicit), m_SALT_SIZE(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 m_hash(std::move(hash)), m_implicit(implicit), m_SALT_SIZE(salt_size) {}
35
36 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(const std::vector<uint8_t>& msg,
46 size_t output_bits,
47 RandomNumberGenerator& rng) override;
48
49 bool verify(const std::vector<uint8_t>& coded, const std::vector<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_SIZE;
54 std::vector<uint8_t> m_msg_buffer;
55};
56
57/**
58* ISO-9796-2 - Digital signature scheme 3 (deterministic)
59*/
60class 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 m_hash(std::move(hash)), m_implicit(implicit) {}
68
69 std::string name() const override;
70
71 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(const std::vector<uint8_t>& msg,
79 size_t output_bits,
80 RandomNumberGenerator& rng) override;
81
82 bool verify(const std::vector<uint8_t>& coded, const std::vector<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
ISO_9796_DS2(std::unique_ptr< HashFunction > hash, bool implicit=false)
Definition iso9796.h:25
std::string name() const override
Definition iso9796.cpp:235
ISO_9796_DS2(std::unique_ptr< HashFunction > hash, bool implicit, size_t salt_size)
Definition iso9796.h:33
std::string hash_function() const override
Definition iso9796.h:36
std::string hash_function() const override
Definition iso9796.h:71
std::string name() const override
Definition iso9796.cpp:277
ISO_9796_DS3(std::unique_ptr< HashFunction > hash, bool implicit=false)
Definition iso9796.h:66
int(* update)(CTX *, const void *, CC_LONG len)
int(* final)(unsigned char *, CTX *)