Botan
1.11.15
|
00001 /* 00002 * MGF1 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #include <botan/mgf1.h> 00009 #include <botan/exceptn.h> 00010 #include <botan/internal/xor_buf.h> 00011 #include <algorithm> 00012 00013 namespace Botan { 00014 00015 void mgf1_mask(HashFunction& hash, 00016 const byte in[], size_t in_len, 00017 byte out[], size_t out_len) 00018 { 00019 u32bit counter = 0; 00020 00021 while(out_len) 00022 { 00023 hash.update(in, in_len); 00024 hash.update_be(counter); 00025 secure_vector<byte> buffer = hash.final(); 00026 00027 size_t xored = std::min<size_t>(buffer.size(), out_len); 00028 xor_buf(out, &buffer[0], xored); 00029 out += xored; 00030 out_len -= xored; 00031 00032 ++counter; 00033 } 00034 } 00035 00036 }