Handle special use case of EVP_DigestSignFinal() 72/160672/1
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Fri, 17 Nov 2017 10:34:07 +0000 (11:34 +0100)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Fri, 17 Nov 2017 10:34:07 +0000 (11:34 +0100)
EVP_DigestSignFinal() does not behave the same as other OpenSSL *Final
functions in regards to its length param. Handle this use case so its
different behaviour is not propagated onto YACA.

Change-Id: Iac9338e00a39a986049d1504791ff5e409da96f1

src/sign.c

index 23c9fa0..03f1cb0 100644 (file)
@@ -430,12 +430,20 @@ API int yaca_sign_finalize(yaca_context_h ctx,
        int ret;
 
        if (c == NULL ||  c->op_type != OP_SIGN ||
-               signature == NULL || signature_len == NULL || *signature_len == 0)
+               signature == NULL || signature_len == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
        if (!verify_state_change(c, CTX_FINALIZED))
                return YACA_ERROR_INVALID_PARAMETER;
 
+       /* EVP_DigestSignFinal() is the only *Final that requires buffer
+        * length as the [in,out], don't break the symmetry in our API,
+        * don't require it from the user, get the apropriate length here.
+        */
+       ret = ctx->get_output_length(ctx, 0, signature_len);
+       if (ret != YACA_ERROR_NONE)
+               return ret;
+
        ret = EVP_DigestSignFinal(c->md_ctx, (unsigned char *)signature, signature_len);
        if (ret != 1) {
                ret = YACA_ERROR_INTERNAL;