Botan: src/kdf/mgf1/mgf1.cpp Source File

Botan 1.10.16

mgf1.cpp
Go to the documentation of this file.
1 /*
2 * MGF1
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/mgf1.h>
9 #include <botan/exceptn.h>
10 #include <botan/internal/xor_buf.h>
11 #include <algorithm>
12 #include <memory>
13
14 namespace Botan {
15
16 /*
17 * MGF1 Mask Generation Function
18 */
19 void MGF1::mask(const byte in[], size_t in_len, byte out[],
20 size_t out_len) const
21 {
22 u32bit counter = 0;
23
24 while(out_len)
25 {
26 hash->update(in, in_len);
27 hash->update_be(counter);
28 SecureVector<byte> buffer = hash->final();
29
30 size_t xored = std::min<size_t>(buffer.size(), out_len);
31 xor_buf(out, &buffer[0], xored);
32 out += xored;
33 out_len -= xored;
34
35 ++counter;
36 }
37 }
38
39 /*
40 * MGF1 Constructor
41 */
42 MGF1::MGF1(HashFunction* h) : hash(h)
43 {
44 if(!hash)
45 throw Invalid_Argument("MGF1 given null hash object");
46 }
47
48 /*
49 * MGF1 Destructor
50 */
51 MGF1::~MGF1()
52 {
53 delete hash;
54 }
55
56 }
Botan::MGF1::MGF1
MGF1(HashFunction *hash)
Definition: mgf1.cpp:42
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Buffered_Computation::update
void update(const byte in[], size_t length)
Definition: buf_comp.h:33
Botan
Definition: algo_base.h:14
Botan::Buffered_Computation::final
void final(byte out[])
Definition: buf_comp.h:80
Botan::MGF1::mask
void mask(const byte[], size_t, byte[], size_t) const
Definition: mgf1.cpp:19
Botan::MGF1::~MGF1
~MGF1()
Definition: mgf1.cpp:51
Botan::HashFunction
Definition: hash.h:20
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::SecureVector< byte >
Botan::Buffered_Computation::update_be
void update_be(const T in)
Definition: buf_comp.h:48
Botan::xor_buf
void xor_buf(byte out[], const byte in[], size_t length)
Definition: xor_buf.h:21
Botan::u32bit
unsigned int u32bit
Definition: types.h:32