WARNING: This method is only PKCS5 v1.5 compliant when using RC2, RC4-40,
or DES with MD5 or SHA1. Using anything else (like AES) will generate the
key/iv using an OpenSSL specific method. Use a
PKCS5 v2 key generation method instead.

Parameters

salt must be an 8 byte string if provided. iterations is
a integer with a default of 2048. digest is a Digest object that defaults to ‘MD5’

staticVALUEossl_cipher_pkcs5_keyivgen(intargc,VALUE*argv,VALUEself){EVP_CIPHER_CTX*ctx;constEVP_MD*digest;VALUEvpass,vsalt,viter,vdigest;unsignedcharkey[EVP_MAX_KEY_LENGTH],iv[EVP_MAX_IV_LENGTH],*salt=NULL;intiter;rb_scan_args(argc,argv,"13",&vpass,&vsalt,&viter,&vdigest);StringValue(vpass);if(!NIL_P(vsalt)){StringValue(vsalt);if(RSTRING_LEN(vsalt)!=PKCS5_SALT_LEN)rb_raise(eCipherError,"salt must be an 8-octet string");salt=(unsignedchar*)RSTRING_PTR(vsalt);}iter=NIL_P(viter)?2048:NUM2INT(viter);digest=NIL_P(vdigest)?EVP_md5():GetDigestPtr(vdigest);GetCipher(self,ctx);EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx),digest,salt,(unsignedchar*)RSTRING_PTR(vpass),RSTRING_LEN(vpass),iter,key,iv);if(EVP_CipherInit_ex(ctx,NULL,NULL,key,iv,-1)!=1)ossl_raise(eCipherError,NULL);OPENSSL_cleanse(key,sizeofkey);OPENSSL_cleanse(iv,sizeofiv);returnQnil;}