def pkcs_mgf1(mgfSeed, maskLen, h):
 if (not _hashFuncParams.has_key(h)):
  warning('pkcs_mgf1: invalid hash (%s) provided')
  return None
 hLen = _hashFuncParams[h][0]
 hFunc = _hashFuncParams[h][1]
 if (maskLen > ((2 ** 32) * hLen)):
  warning('pkcs_mgf1: maskLen > 2**32 * hLen')
  return None
 T = ''
 maxCounter = math.ceil((float(maskLen) / float(hLen)))
 counter = 0
 while (counter < maxCounter):
  C = pkcs_i2osp(counter, 4)
  T += hFunc((mgfSeed + C))
  counter += 1
 return T[:maskLen]

def pkcs_mgf1 ( mgfSeed , maskLen , h ) : if ( not _hashFuncParams . has_key ( h ) ) : warning ( 'pkcs_mgf1: invalid hash (%s) provided' ) return None hLen = _hashFuncParams [ h ] [ 0 ] hFunc = _hashFuncParams [ h ] [ 1 ] if ( maskLen > ( ( 2 ** 32 ) * hLen ) ) : warning ( 'pkcs_mgf1: maskLen > 2**32 * hLen' ) return None T = '' maxCounter = math . ceil ( ( float ( maskLen ) / float ( hLen ) ) ) counter = 0 while ( counter < maxCounter ) : C = pkcs_i2osp ( counter , 4 ) T += hFunc ( ( mgfSeed + C ) ) counter += 1 return T [ : maskLen ]
implements generic mgf1 mask generation function as described in appendix b .