long i, outlen = 0; unsigned char cnt[4]; EVP_MD_CTX c; unsigned char md[SHA_DIGEST_LENGTH];  EVP_MD_CTX_init(&c); for (i = 0; outlen < len; i++) { cnt[0] = (unsigned char)((i >> 24) & 255); cnt[1] = (unsigned char)((i >> 16) & 255); cnt[2] = (unsigned char)((i >> 8)) & 255; cnt[3] = (unsigned char)(i & 255); EVP_DigestInit_ex(&c,EVP_sha1(), NULL); EVP_DigestUpdate(&c, seed, seedlen); EVP_DigestUpdate(&c, cnt, 4); if (outlen + SHA_DIGEST_LENGTH <= len) { EVP_DigestFinal_ex(&c, mask + outlen, NULL); outlen += SHA_DIGEST_LENGTH; } else { EVP_DigestFinal_ex(&c, md, NULL); memcpy(mask + outlen, md, len - outlen); outlen = len; } } EVP_MD_CTX_cleanup(&c); return 0;
return PKCS1_MGF1(mask, len, seed, seedlen, EVP_sha1());
int MGF1(unsigned char *mask, long len,	const unsigned char *seed, long seedlen)	{	long i, outlen = 0;	unsigned char cnt[4];	EVP_MD_CTX c;	unsigned char md[SHA_DIGEST_LENGTH];	EVP_MD_CTX_init(&c);	for (i = 0; outlen < len; i++)		{		cnt[0] = (unsigned char)((i >> 24) & 255);		cnt[1] = (unsigned char)((i >> 16) & 255);		cnt[2] = (unsigned char)((i >> 8)) & 255;		cnt[3] = (unsigned char)(i & 255);		EVP_DigestInit_ex(&c,EVP_sha1(), NULL);		EVP_DigestUpdate(&c, seed, seedlen);		EVP_DigestUpdate(&c, cnt, 4);		if (outlen + SHA_DIGEST_LENGTH <= len)			{			EVP_DigestFinal_ex(&c, mask + outlen, NULL);			outlen += SHA_DIGEST_LENGTH;			}		else			{			EVP_DigestFinal_ex(&c, md, NULL);			memcpy(mask + outlen, md, len - outlen);			outlen = len;			}		}	EVP_MD_CTX_cleanup(&c);	return 0;	}