monotone

monotone Mtn Source Tree

Root/botan/mgf1.cpp

1/*************************************************
2* MGF1 Source File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/mgf1.h>
7#include <botan/lookup.h>
8#include <botan/bit_ops.h>
9#include <algorithm>
10#include <memory>
11
12namespace Botan {
13
14/*************************************************
15* MGF1 Mask Generation Function *
16*************************************************/
17void MGF1::mask(const byte in[], u32bit in_len, byte out[],
18 u32bit out_len) const
19 {
20 u32bit counter = 0;
21
22 std::auto_ptr<HashFunction> hash(get_hash(hash_name));
23
24 while(out_len)
25 {
26 hash->update(in, in_len);
27 for(u32bit j = 0; j != 4; ++j)
28 hash->update(get_byte(j, counter));
29 SecureVector<byte> buffer = hash->final();
30
31 u32bit xored = std::min(buffer.size(), out_len);
32 xor_buf(out, buffer.begin(), xored);
33 out += xored;
34 out_len -= xored;
35
36 ++counter;
37 }
38 }
39
40/*************************************************
41* MGF1 Constructor *
42*************************************************/
43MGF1::MGF1(const std::string& h_name) : hash_name(h_name)
44 {
45 if(!have_hash(hash_name))
46 throw Algorithm_Not_Found(hash_name);
47 }
48
49}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status