Botan
1.10.17
src
kdf
mgf1
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::HashFunction
Definition
hash.h:22
Botan::MGF1::MGF1
MGF1(HashFunction *hash)
Definition
mgf1.cpp:42
Botan::MGF1::~MGF1
~MGF1()
Definition
mgf1.cpp:51
Botan::MGF1::mask
void mask(const byte[], size_t, byte[], size_t) const
Definition
mgf1.cpp:19
Botan::MemoryRegion::size
size_t size() const
Definition
secmem.h:29
Botan::SecureVector
Definition
secmem.h:329
Botan
Definition
algo_base.h:14
Botan::xor_buf
void xor_buf(byte out[], const byte in[], size_t length)
Definition
xor_buf.h:21
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition
exceptn.h:20
Botan::u32bit
unsigned int u32bit
Definition
types.h:32
Generated by
1.18.0