OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH); OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, 	     const unsigned char *salt, const unsigned char *data, int datal,	     int count, unsigned char *key, unsigned char *iv)	{	EVP_MD_CTX c;	unsigned char md_buf[EVP_MAX_MD_SIZE];	int niv,nkey,addmd=0;	unsigned int mds=0,i;	nkey=type->key_len;	niv=type->iv_len;	if (data == NULL) return(nkey);	EVP_MD_CTX_init(&c);	for (;;)		{		EVP_DigestInit_ex(&c,md, NULL);		if (addmd++)			EVP_DigestUpdate(&c,&(md_buf[0]),mds);		EVP_DigestUpdate(&c,data,datal);		if (salt != NULL)			EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN);		EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);		for (i=1; i<(unsigned int)count; i++)			{			EVP_DigestInit_ex(&c,md, NULL);			EVP_DigestUpdate(&c,&(md_buf[0]),mds);			EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);			}		i=0;		if (nkey)			{			for (;;)				{				if (nkey == 0) break;				if (i == mds) break;				if (key != NULL)					*(key++)=md_buf[i];				nkey--;				i++;				}			}		if (niv && (i != mds))			{			for (;;)				{				if (niv == 0) break;				if (i == mds) break;				if (iv != NULL)					*(iv++)=md_buf[i];				niv--;				i++;				}			}		if ((nkey == 0) && (niv == 0)) break;		}	EVP_MD_CTX_cleanup(&c);	memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE);	return(type->key_len);	}