* [including the GNU Public Licence.]
*/
+#ifndef NO_RSA
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/evp.h>
{
unsigned char *key=NULL;
int i,size=0,ret=0;
-
+
+ if(type) {
+ EVP_CIPHER_CTX_init(ctx);
+ if(!EVP_DecryptInit(ctx,type,NULL,NULL)) return 0;
+ }
+
+ if(!priv) return 1;
+
if (priv->type != EVP_PKEY_RSA)
{
EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
- ret= -1;
goto err;
}
size=RSA_size(priv->pkey.rsa);
- key=(unsigned char *)Malloc(size+2);
+ key=(unsigned char *)OPENSSL_malloc(size+2);
if (key == NULL)
{
/* ERROR */
EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE);
- ret= -1;
goto err;
}
i=EVP_PKEY_decrypt(key,ek,ekl,priv);
- if (i != type->key_len)
+ if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i))
{
/* ERROR */
goto err;
}
+ if(!EVP_DecryptInit(ctx,NULL,key,iv)) goto err;
- EVP_CIPHER_CTX_init(ctx);
- EVP_DecryptInit(ctx,type,key,iv);
ret=1;
err:
if (key != NULL) memset(key,0,size);
- Free(key);
+ OPENSSL_free(key);
return(ret);
}
EVP_DecryptInit(ctx,NULL,NULL,NULL);
return(i);
}
+#else /* !NO_RSA */
+
+# ifdef PEDANTIC
+static void *dummy=&dummy;
+# endif
+
+#endif