Mask generation function: Difference between revisions

Content deleted Content added
m Definition: format
MGF1: formatting
Line 36:
=== MGF1 ===
 
MGF1 is a Mask Generation Function defined in the Public Key Cryptography Standard #1 published by RSA Laboratories.<ref name="rsa"/> The algorithm is described as follows:
<blockquote>
====Options====
<math>\mathsf{Hash}</math>
Hash : hash function (<math>\mathsf{hLen}</math> denotes the length in octets of the hash function output)
 
====Input====
<pre>
<math>Z</math>
Hash hash function (hLen denotes the length in octets of the hash
Z :seed from which mask is generated, an octet string
function output)
<math>l</math>
l :intended length in octets of the mask, at most <math>2^{32}(\mathsf{hLen})</math>
 
====Output:====
Input:
<math>\mathsf{mask}</math>
Z seed from which mask is generated, an octet string
mask :mask, an octet string of length <math>l</math>; or "mask too long"
l intended length in octets of the mask, at most 2^32(hLen)
 
====Steps====
Output:
{{Ordered list | list_style_type=decimal
mask mask, an octet string of length l; or "mask too long"
| 1.If <math>l > 2^{32}(\mathsf{hLen})</math>, output "mask too long" and stop.
 
| 2.Let <math>T</math> be the empty octet string.
Steps:
| 3.For <math>\mathsf{counter}</math> from <math>0</math> to <math>\left\lceil{\tfrac{l / }{\mathsf{hLen}}}\right\rceil-1</math>, do the following:
 
{{Ordered list | list_style_type=lower-alpha
1.If l > 2^32(hLen), output "mask too long" and stop.
a. | Convert <math>\mathsf{counter}</math> to an octet string <math>C</math> of length <math>4</math> with the primitive <math>\mathsf{I2OSP}</math>:
 
: I2OSP: <math>C = \mathsf{I2OSP} (\mathsf{counter}, 4)</math>
2.Let T be the empty octet string.
b. | Concatenate the hash of the seed <math>Z</math> and <math>C</math> to the octet string <math>T</math>: T =
 
: <math>T = T \shortparallel \mathsf{Hash} (Z \shortparallel C)</math>
3.For counter from 0 to \lceil{l / hLen}\rceil-1, do the following:
}}
 
| 4.Output the leading <math>l</math> octets of <math>T</math> as the octet string mask.
a.Convert counter to an octet string C of length 4 with the primitive
}}
I2OSP: C = I2OSP (counter, 4)
</blockquote>
 
b.Concatenate the hash of the seed Z and C to the octet string T: T =
T || Hash (Z || C)
 
4.Output the leading l octets of T as the octet string mask.
</pre>
 
=== Example Code ===