Botan 1.10.17
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
14namespace Botan {
15
16/*
17* MGF1 Mask Generation Function
18*/
19void 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*/
43 {
44 if(!hash)
45 throw Invalid_Argument("MGF1 given null hash object");
46 }
47
48/*
49* MGF1 Destructor
50*/
52 {
53 delete hash;
54 }
55
56}
MGF1(HashFunction *hash)
Definition mgf1.cpp:42
void mask(const byte[], size_t, byte[], size_t) const
Definition mgf1.cpp:19
size_t size() const
Definition secmem.h:29
void xor_buf(byte out[], const byte in[], size_t length)
Definition xor_buf.h:21
std::invalid_argument Invalid_Argument
Definition exceptn.h:20
unsigned int u32bit
Definition types.h:32