monotone

monotone Mtn Source Tree

Root/botan/mgf1.cpp

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

Archive Download this file

Branches

Tags

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