Mask generation function: Difference between revisions

Content deleted Content added
Initial page creation
 
No edit summary
Line 93:
return ''.join([chr((integer >> (8 * i)) & 0xFF) for i in reversed(range(size))])
 
def mgf1(input, length, digesthash=hashlib.sha1):
counter = 0
output = ''
while (len(output) < length):
C = i2osp(counter, 4)
output += digesthash(input + C).digest()
counter += 1
return output[:length]
Line 112:
>>> from binascii import hexlify
>>> from hashlib import sha256
>>> print hexlify(mgf1('foo', 3))
'1ac907'
>>> print hexlify(mgf1('foo', 5))
'1ac9075cd4'
>>> print hexlify(mgf1('bar', 5))
'bc0c655e01'
>>> print hexlify(mgf1('bar', 50))
'bc0c655e016bc2931d85a2e675181adcef7f581f76df2739da74faac41627be2f7f415c89e983fd0ce80ced9878641cb4876'
>>> print hexlify(mgf1('bar', 50, sha256))
'382576a7841021cc28fc4c0948753fb8312090cea942ea4c4e735d10dc724b155f9f6069f289d61daca0cb814502ef04eae1'
</source>