monotone

monotone Mtn Source Tree

Root/botan/mgf1.cpp

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

Archive Download this file

Branches

Tags

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