/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 | | |
10 | | #include <botan/hash.h> |
11 | | #include <botan/mem_ops.h> |
12 | | #include <algorithm> |
13 | | |
14 | | namespace Botan { |
15 | | |
16 | 56 | void mgf1_mask(HashFunction& hash, const uint8_t in[], size_t in_len, uint8_t out[], size_t out_len) { |
17 | 56 | uint32_t counter = 0; |
18 | | |
19 | 56 | std::vector<uint8_t> buffer(hash.output_length()); |
20 | 652 | while(out_len) { |
21 | 596 | hash.update(in, in_len); |
22 | 596 | hash.update_be(counter); |
23 | 596 | hash.final(buffer.data()); |
24 | | |
25 | 596 | const size_t xored = std::min<size_t>(buffer.size(), out_len); |
26 | 596 | xor_buf(out, buffer.data(), xored); |
27 | 596 | out += xored; |
28 | 596 | out_len -= xored; |
29 | | |
30 | 596 | ++counter; |
31 | 596 | } |
32 | 56 | } |
33 | | |
34 | | } // namespace Botan |