Mask generation function

Uses your system voice; voice and rate in settings.

Snapshot

≈ 3 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

A mask generation function (MGF) is a cryptographic primitive similar to a cryptographic hash function except that while a hash function's output has a fixed size, a MGF supports output of a variable length. In this respect, a MGF can be viewed as a extendable-output function (XOF): it can accept input of any length and process it to produce output of any length. Mask generation functions are completely deterministic: for any given input and any desired output length the output is always the same.

A mask generation function (MGF) is a cryptographic primitive similar to a cryptographic hash function except that while a hash function's output has a fixed size, a MGF supports output of a variable length. In this respect, a MGF can be viewed as a extendable-output function (XOF): it can accept input of any length and process it to produce output of any length. Mask generation functions are completely deterministic: for any given input and any desired output length the output is always the same. ====Options==== \mathsf{Hash} hash function ( \mathsf{hLen} denotes the length in octets of the hash function output) ====Input==== Z seed from which mask is generated, an octet string l intended length in octets of the mask, at most 2^{32}(\mathsf{hLen}) ====Output==== \mathsf{mask} mask, an octet string of length l ; or "mask too long" ====Steps==== {{Ordered list | list_style_type=decimal | If l > 2^{32}(\mathsf{hLen}) , output "mask too long" and stop. | Let T be the empty octet string. | For \mathsf{counter} from 0 to \left\lceil{\tfrac{l}{\mathsf{hLen}}}\right\rceil-1 , do the following: | Output the leading l octets of T as the octet string mask. }} import hashlib def mgf1(seed: bytes, length: int, hash_func=hashlib.sha1) -> bytes: """Mask generation function.""" hLen = hash_func().digest_size # https://www.ietf.org/rfc/rfc2437.txt # 1. If l > 2^32(hLen), output "mask too long" and stop. if length > (hLen Example outputs of MGF1: Python 3.10.4 (main, Apr 16 2022, 16:28:41) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from mgf1 import mgf1 >>> from hashlib import sha256 >>> mgf1(b"foo", 3).hex() '1ac907' >>> mgf1(b"foo", 5).hex() '1ac9075cd4' >>> mgf1(b"bar", 5).hex() 'bc0c655e01' >>> mgf1(b"bar", 50).hex() 'bc0c655e016bc2931d85a2e675181adcef7f581f76df2739da74faac41627be2f7f415c89e983fd0ce80ced9878641cb4876' >>> mgf1(b"bar", 50, sha256).hex() '382576a7841021cc28fc4c0948753fb8312090cea942ea4c4e735d10dc724b155f9f6069f289d61daca0cb814502ef04eae1'

Text derived from https://en.wikipedia.org/w/index.php?oldid=1346908491 under CC BY-SA 4.0; modifications have been made.