/src/botan/src/lib/pk_pad/mgf1/mgf1.cpp
Line | Count | Source |
1 | | /* |
2 | | * MGF1 |
3 | | * (C) 1999-2007 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #include <botan/internal/mgf1.h> |
9 | | #include <botan/hash.h> |
10 | | #include <algorithm> |
11 | | |
12 | | namespace Botan { |
13 | | |
14 | | void mgf1_mask(HashFunction& hash, |
15 | | const uint8_t in[], size_t in_len, |
16 | | uint8_t out[], size_t out_len) |
17 | 57 | { |
18 | 57 | uint32_t counter = 0; |
19 | | |
20 | 57 | secure_vector<uint8_t> buffer(hash.output_length()); |
21 | 500 | while(out_len) |
22 | 443 | { |
23 | 443 | hash.update(in, in_len); |
24 | 443 | hash.update_be(counter); |
25 | 443 | hash.final(buffer.data()); |
26 | | |
27 | 443 | const size_t xored = std::min<size_t>(buffer.size(), out_len); |
28 | 443 | xor_buf(out, buffer.data(), xored); |
29 | 443 | out += xored; |
30 | 443 | out_len -= xored; |
31 | | |
32 | 443 | ++counter; |
33 | 443 | } |
34 | 57 | } |
35 | | |
36 | | } |