File: mgf1.cpp

package info (click to toggle)
monotone 0.31-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 20,680 kB
  • ctags: 14,801
  • sloc: cpp: 87,711; ansic: 64,862; sh: 5,691; lisp: 954; perl: 783; makefile: 509; python: 265; sql: 98; sed: 16
file content (48 lines) | stat: -rw-r--r-- 1,320 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*************************************************
* MGF1 Source File                               *
* (C) 1999-2005 The Botan Project                *
*************************************************/

#include <botan/mgf1.h>
#include <botan/lookup.h>
#include <botan/bit_ops.h>
#include <memory>

namespace Botan {

/*************************************************
* MGF1 Mask Generation Function                  *
*************************************************/
void MGF1::mask(const byte in[], u32bit in_len, byte out[],
                u32bit out_len) const
   {
   u32bit counter = 0;

   std::auto_ptr<HashFunction> hash(get_hash(hash_name));

   while(out_len)
      {
      hash->update(in, in_len);
      for(u32bit j = 0; j != 4; j++)
         hash->update(get_byte(j, counter));
      SecureVector<byte> buffer = hash->final();

      u32bit xored = std::min(buffer.size(), out_len);
      xor_buf(out, buffer.begin(), xored);
      out += xored;
      out_len -= xored;

      counter++;
      }
   }

/*************************************************
* MGF1 Constructor                               *
*************************************************/
MGF1::MGF1(const std::string& h_name) : hash_name(h_name)
   {
   if(!have_hash(hash_name))
      throw Algorithm_Not_Found(hash_name);
   }

}