Mask generation function: Difference between revisions

Content deleted Content added
Dannyniu (talk | contribs)
Changed Sponge -> XOF.
Line 66:
</blockquote>
 
=== Example Codecode ===
 
Below is pythonPython code implementing MGF1:
 
<source lang="python">
import hashlib
 
def i2osp(integer: int, size: int = 4) -> str:
return ''.join([chr((integer >> (8 * i)) & 0xFF) for i in reversed(range(size))])
 
def mgf1(inputinput_str: str, length: int, hash=hashlib.sha1) -> str:
counter = 0
output = ''
while (len(output) < length):
C = i2osp(counter, 4)
output += hash(inputinput_str + C).digest()
counter += 1
return output[:length]
</source>
 
Example outputs of MGF1:
 
<source lang="pythonpycon">
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin