*** Welcome to piglix ***

Mask generation function


A Mask Generation Function (MGF) is a cryptographic primitive similar to a Cryptographic hash function except that while a hash function's output is a fixed size, a MGF supports output of a variable length. In this respect, a MGF can be viewed as a single-use Sponge function, it can absorb any length of input and process it to produce any length of output. Mask Generation Functions are completely deterministic. For any given input and desired output length the output is always the same.

Mask Generation Functions, as generalizations of hash functions, are useful in all the same cases hash functions are useful. However use of a MGF is desirable in cases where a fixed-size hash would be inadequate. Examples include generating padding, producing one time pads or keystreams in symmetric key encryption, and yielding outputs for pseudorandom number generators.

Mask Generation Functions were first proposed as part of the specification for padding in the RSA-OAEP algorithm. The OAEP algorithm required a cryptographic hash function that could generate an output equal in size to a "data block" whose length was proportional to arbitrarily sized input message.

The Salsa20 stream cipher may be viewed as a Mask Generation Function as its keystream is produced by hashing the key and nonce with a counter, to yield an arbitrarily long output.

The NIST Special Publication 800-90A defines a class of cryptographically secure random number generators, one of which is the "Hash DRBG" which uses a hash function with a counter to produce a requested sequence of random bits equal in size to the requested number of random bits.

Perhaps the most common and straight forward mechanism to build a MGF is to iteratively apply a hash function together with an incrementing counter value. The counter may be incremented indefinitely to yield new output blocks until a sufficient amount of output is collected. This is the approach used in MGF1 shown below.

MGF1 is a Mask Generation Function defined in the Public Key Cryptography Standard #1 published by RSA Laboratories. The algorithm is described as follows:


...
Wikipedia

...