if(ctx->cipher_data) OPENSSL_free(ctx->cipher_data);
if(ctx->cipher) EVP_CIPHER_CTX_cleanup(ctx);
int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,	     unsigned char *key, unsigned char *iv, int enc)	{	if(enc && (enc != -1)) enc = 1;	if (cipher)		{		if(ctx->cipher_data)			OPENSSL_free(ctx->cipher_data);		ctx->cipher=cipher;		ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size);		ctx->key_len = cipher->key_len;		ctx->flags = 0;		if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT) {			if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) {				EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);				return 0;			}		}	} else if(!ctx->cipher) {		EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET);		return 0;	}	/* we assume block size is a power of 2 in *cryptUpdate */	assert(ctx->cipher->block_size == 1	       || ctx->cipher->block_size == 8	       || ctx->cipher->block_size == 16);	if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {		switch(EVP_CIPHER_CTX_mode(ctx)) {			case EVP_CIPH_STREAM_CIPHER:			case EVP_CIPH_ECB_MODE:			break;			case EVP_CIPH_CFB_MODE:			case EVP_CIPH_OFB_MODE:			ctx->num = 0;			case EVP_CIPH_CBC_MODE:			if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));			memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));			break;			default:			return 0;			break;		}	}	if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {		if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;	}	if(enc != -1) ctx->encrypt=enc;	ctx->buf_len=0;	ctx->final_used=0;	ctx->block_mask=ctx->cipher->block_size-1;	return 1;	}