free(key);
}
-static int decode_rsa(gcry_sexp_t sexp, unsigned char *outbuf, size_t *nbytes)
+static int decode_rsa(gcry_sexp_t sexp, unsigned char **outbuf, size_t *nbytes)
{
const char *p = gcry_sexp_nth_data(sexp, 1, nbytes);
- if (!p)
+ if (!p) {
+ *outbuf = NULL;
return -E_RSA_DECODE;
- memcpy(outbuf, p, *nbytes);
+ }
+ *outbuf = alloc(*nbytes);
+ memcpy(*outbuf, p, *nbytes);
return 1;
}
-int apc_priv_decrypt(const char *key_file, unsigned char *outbuf,
+int apc_priv_decrypt(const char *key_file, unsigned char **outbuf,
unsigned char *inbuf, int inlen)
{
gcry_error_t gret;
gcry_sexp_t in, out, priv_key;
size_t nbytes;
+ *outbuf = NULL;
ret = check_private_key_file(key_file);
if (ret < 0)
return ret;