* Build an EMPSA PKCS1 signature described in PKCS#1
*/
static bool build_emsa_pkcs1_signature(private_openssl_rsa_private_key_t *this,
- int type, chunk_t data, chunk_t *signature)
+ int type, chunk_t data, chunk_t *out)
{
bool success = FALSE;
+ u_char *sig = NULL;
u_int len;
const EVP_MD *hasher = EVP_get_digestbynid(type);
if (!hasher)
goto error;
}
- *signature = chunk_alloc(RSA_size(this->rsa));
-
- if (!EVP_SignFinal(ctx, signature->ptr, &len, key))
+ sig = malloc(EVP_PKEY_size(key));
+ if (EVP_SignFinal(ctx, sig, &len, key))
{
- goto error;
+ out->ptr = sig;
+ out->len = len;
+ success = TRUE;
+ }
+ else
+ {
+ free(sig);
}
- signature->len = len;
-
- success = TRUE;
error:
if (key)