Handle EVP_PKEY_derive errors and fix coding style issues
authorNicola Tuveri <nic.tuv@gmail.com>
Mon, 3 Oct 2016 22:30:54 +0000 (01:30 +0300)
committerRich Salz <rsalz@openssl.org>
Thu, 17 Nov 2016 05:36:23 +0000 (00:36 -0500)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1658)

apps/speed.c

index ebbd8e46d639aaca838f06e34480ac4960973be0..f40f9fa50cef978b745a5070c0fc34a12733eb4c 100644 (file)
@@ -1038,15 +1038,17 @@ static int ECDSA_verify_loop(void *args)
 /* ******************************************************************** */
 static long ecdh_c[EC_NUM][1];
 
-static void ECDH_EVP_derive_key(unsigned char *derived_secret,
+static int ECDH_EVP_derive_key(unsigned char *derived_secret,
                             size_t *outlen,
                             EVP_PKEY_CTX *ctx)
 {
-    if( !EVP_PKEY_derive(ctx, derived_secret, outlen) ) {
-        /* FIXME: handle errors */
-        ;
+    int rt=1;
+    if ( (rt=EVP_PKEY_derive(ctx, derived_secret, outlen)) <= 0 ) {
+        BIO_printf(bio_err, "ECDH EVP_PKEY_derive failure: returned %d\n", rt);
+        ERR_print_errors(bio_err);
+        return rt;
     }
-    return;
+    return rt;
 }
 
 static int ECDH_EVP_derive_key_loop(void *args)
@@ -1058,7 +1060,8 @@ static int ECDH_EVP_derive_key_loop(void *args)
     size_t *outlen = &(tempargs->outlen);
 
     for (count = 0; COND(ecdh_c[testnum][0]); count++) {
-        ECDH_EVP_derive_key(derived_secret, outlen, ctx);
+        if ( !ECDH_EVP_derive_key(derived_secret, outlen, ctx) )
+            break;
     }
     return count;
 }
@@ -2565,7 +2568,7 @@ int speed_main(int argc, char **argv)
                 EVP_PKEY_CTX *pctx = NULL;
                 EVP_PKEY *params = NULL;
 
-                if    /* Create the context for parameter generation */
+                if (    /* Create the context for parameter generation */
                         !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
                         /* Initialise the parameter generation */
                         !EVP_PKEY_paramgen_init(pctx) ||