Botan 1.10.17

pk_filts.cpp
Go to the documentation of this file.
1 /*
2 * PK Filters
3 * (C) 1999-2009 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/pk_filts.h>
9
10 namespace Botan {
11
12 /*
13 * Append to the buffer
14 */
15 void PK_Encryptor_Filter::write(const byte input[], size_t length)
16 {
17 buffer += std::make_pair(input, length);
18 }
19
20 /*
21 * Encrypt the message
22 */
23 void PK_Encryptor_Filter::end_msg()
24 {
25 send(cipher->encrypt(buffer, rng));
26 buffer.clear();
27 }
28
29 /*
30 * Append to the buffer
31 */
32 void PK_Decryptor_Filter::write(const byte input[], size_t length)
33 {
34 buffer += std::make_pair(input, length);
35 }
36
37 /*
38 * Decrypt the message
39 */
40 void PK_Decryptor_Filter::end_msg()
41 {
42 send(cipher->decrypt(buffer));
43 buffer.clear();
44 }
45
46 /*
47 * Add more data
48 */
49 void PK_Signer_Filter::write(const byte input[], size_t length)
50 {
51 signer->update(input, length);
52 }
53
54 /*
55 * Sign the message
56 */
57 void PK_Signer_Filter::end_msg()
58 {
59 send(signer->signature(rng));
60 }
61
62 /*
63 * Add more data
64 */
65 void PK_Verifier_Filter::write(const byte input[], size_t length)
66 {
67 verifier->update(input, length);
68 }
69
70 /*
71 * Verify the message
72 */
73 void PK_Verifier_Filter::end_msg()
74 {
75 if(signature.empty())
76 throw Invalid_State("PK_Verifier_Filter: No signature to check against");
77 bool is_valid = verifier->check_signature(signature);
78 send((is_valid ? 1 : 0));
79 }
80
81 /*
82 * Set the signature to check
83 */
84 void PK_Verifier_Filter::set_signature(const byte sig[], size_t length)
85 {
86 signature.resize(length);
87 copy_mem(&signature[0], sig, length);
88 }
89
90 /*
91 * Set the signature to check
92 */
93 void PK_Verifier_Filter::set_signature(const MemoryRegion<byte>& sig)
94 {
95 signature = sig;
96 }
97
98 /*
99 * PK_Verifier_Filter Constructor
100 */
101 PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v, const byte sig[],
102 size_t length) :
103 verifier(v), signature(sig, length)
104 {
105 }
106
107 /*
108 * PK_Verifier_Filter Constructor
109 */
110 PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v,
111 const MemoryRegion<byte>& sig) :
112 verifier(v), signature(sig)
113 {
114 }
115
116 }
Botan::PK_Verifier::check_signature
bool check_signature(const byte sig[], size_t length)
Definition: pubkey.cpp:301
Botan::MemoryRegion::resize
void resize(size_t n)
Definition: secmem.h:217
Botan::PK_Verifier_Filter::PK_Verifier_Filter
PK_Verifier_Filter(PK_Verifier *v)
Definition: pk_filts.h:88
Botan::PK_Verifier_Filter::set_signature
void set_signature(const byte[], size_t)
Definition: pk_filts.cpp:84
Botan::PK_Encryptor_Filter::write
void write(const byte[], size_t)
Definition: pk_filts.cpp:15
Botan::PK_Verifier_Filter::end_msg
void end_msg()
Definition: pk_filts.cpp:73
Botan::PK_Signer::signature
SecureVector< byte > signature(RandomNumberGenerator &rng)
Definition: pubkey.cpp:210
Botan::MemoryRegion::clear
void clear()
Definition: secmem.h:158
Botan::PK_Encryptor::encrypt
SecureVector< byte > encrypt(const byte in[], size_t length, RandomNumberGenerator &rng) const
Definition: pubkey.h:48
Botan::Invalid_State
Definition: exceptn.h:25
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::MemoryRegion::empty
bool empty() const
Definition: secmem.h:35
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28
Botan::PK_Decryptor::decrypt
SecureVector< byte > decrypt(const byte in[], size_t length) const
Definition: pubkey.h:94
Botan::MemoryRegion< byte >
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:22
Botan
Definition: algo_base.h:14
Botan::PK_Verifier
Definition: pubkey.h:211
Botan::PK_Decryptor_Filter::end_msg
void end_msg()
Definition: pk_filts.cpp:40
Botan::PK_Verifier_Filter::write
void write(const byte[], size_t)
Definition: pk_filts.cpp:65
Botan::PK_Signer_Filter::end_msg
void end_msg()
Definition: pk_filts.cpp:57
Botan::PK_Signer_Filter::write
void write(const byte[], size_t)
Definition: pk_filts.cpp:49
Botan::PK_Encryptor_Filter::end_msg
void end_msg()
Definition: pk_filts.cpp:23
Botan::PK_Verifier::update
void update(byte in)
Definition: pubkey.h:242
Botan::PK_Decryptor_Filter::write
void write(const byte[], size_t)
Definition: pk_filts.cpp:32
Botan::PK_Signer::update
void update(byte in)
Definition: pubkey.h:150