From 127227fe4c705db9173254c20eb3fcb5085d13c6 Mon Sep 17 00:00:00 2001 From: Alessio Di Mauro Date: Wed, 5 Oct 2016 16:36:49 +0200 Subject: [PATCH] Better approximation for signature size Relates to #98. --- ykcs11/ykcs11.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ykcs11/ykcs11.c b/ykcs11/ykcs11.c index d1aa456..942c8c0 100644 --- a/ykcs11/ykcs11.c +++ b/ykcs11/ykcs11.c @@ -1865,7 +1865,15 @@ CK_DEFINE_FUNCTION(CK_RV, C_Sign)( if (pSignature == NULL_PTR) { // Just return the size of the signature - *pulSignatureLen = op_info.op.sign.key_len / 8 * 2 + 32; // Approximate the size of the signature. Specs agree with this. + if (is_RSA_mechanism(op_info.mechanism.mechanism)) { + // RSA + *pulSignatureLen = (op_info.op.sign.key_len + 7) / 8; + } + else { + // ECDSA + *pulSignatureLen = ((op_info.op.sign.key_len + 7) / 8) * 2; + } + DBG("The size of the signature will be %lu", *pulSignatureLen); DOUT;