documentation and duplicate goto statements
authorBilly Brumley <bbrumley@gmail.com>
Mon, 29 Feb 2016 20:35:35 +0000 (22:35 +0200)
committerRich Salz <rsalz@openssl.org>
Mon, 7 Mar 2016 17:20:42 +0000 (12:20 -0500)
Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
test/ecdhtest.c
test/ecdhtest_cavs.h

index 3a67552b1ae315dca3f93a1e73e049dc2ae25b0d..356f3e939c127ff3ad5f6a5d754cf26d349a4a8f 100644 (file)
@@ -463,6 +463,27 @@ static int ecdh_kat(BIO *out, const ecdh_kat_t *kat)
 
 #include "ecdhtest_cavs.h"
 
 
 #include "ecdhtest_cavs.h"
 
+/*
+ * NIST SP800-56A co-factor ECDH tests.
+ * KATs taken from NIST documents with parameters:
+ *
+ * - (QCAVSx,QCAVSy) is the public key for CAVS.
+ * - dIUT is the private key for IUT.
+ * - (QIUTx,QIUTy) is the public key for IUT.
+ * - ZIUT is the shared secret KAT.
+ *
+ * CAVS: Cryptographic Algorithm Validation System
+ * IUT: Implementation Under Test
+ *
+ * This function tests two things:
+ *
+ * 1. dIUT * G = (QIUTx,QIUTy)
+ *    i.e. public key for IUT computes correctly.
+ * 2. x-coord of cofactor * dIUT * (QCAVSx,QCAVSy) = ZIUT
+ *    i.e. co-factor ECDH key computes correctly.
+ *
+ * returns zero on failure or unsupported curve. One otherwise.
+ */
 static int ecdh_cavs_kat(BIO *out, const ecdh_cavs_kat_t *kat)
 {
     int rv = 0, is_char_two = 0;
 static int ecdh_cavs_kat(BIO *out, const ecdh_cavs_kat_t *kat)
 {
     int rv = 0, is_char_two = 0;
@@ -495,7 +516,9 @@ static int ecdh_cavs_kat(BIO *out, const ecdh_cavs_kat_t *kat)
     if(!BN_hex2bn(&y, kat->QIUTy))
         goto err;
     if (is_char_two) {
     if(!BN_hex2bn(&y, kat->QIUTy))
         goto err;
     if (is_char_two) {
-#ifndef OPENSSL_NO_EC2M
+#ifdef OPENSSL_NO_EC2M
+        goto err;
+#else
         if (!EC_POINT_set_affine_coordinates_GF2m(group, pub, x, y, NULL))
             goto err;
 #endif
         if (!EC_POINT_set_affine_coordinates_GF2m(group, pub, x, y, NULL))
             goto err;
 #endif
@@ -514,7 +537,9 @@ static int ecdh_cavs_kat(BIO *out, const ecdh_cavs_kat_t *kat)
     if(!BN_hex2bn(&y, kat->QCAVSy))
         goto err;
     if (is_char_two) {
     if(!BN_hex2bn(&y, kat->QCAVSy))
         goto err;
     if (is_char_two) {
-#ifndef OPENSSL_NO_EC2M
+#ifdef OPENSSL_NO_EC2M
+        goto err;
+#else
         if (!EC_POINT_set_affine_coordinates_GF2m(group, pub, x, y, NULL))
             goto err;
 #endif
         if (!EC_POINT_set_affine_coordinates_GF2m(group, pub, x, y, NULL))
             goto err;
 #endif
@@ -551,8 +576,9 @@ static int ecdh_cavs_kat(BIO *out, const ecdh_cavs_kat_t *kat)
     BN_free(y);
     OPENSSL_free(Ztmp);
     OPENSSL_free(Z);
     BN_free(y);
     OPENSSL_free(Ztmp);
     OPENSSL_free(Z);
-    if (rv)
+    if (rv) {
         BIO_puts(out, " ok\n");
         BIO_puts(out, " ok\n");
+    }
     else {
         fprintf(stderr, "Error in ECC CDH routines\n");
         ERR_print_errors_fp(stderr);
     else {
         fprintf(stderr, "Error in ECC CDH routines\n");
         ERR_print_errors_fp(stderr);
index 0d700ed390579ae98f38de16650a4edef7492b02..632d02d69ee2f73a28de10c7b5b877366cf3589a 100644 (file)
@@ -3,7 +3,7 @@
 
 /* 
  * co-factor ECDH KATs for NIST SP800-56A
 
 /* 
  * co-factor ECDH KATs for NIST SP800-56A
- * http://csrc.nist.gov/groups/STM/cavp/component-testing.html#ecc-cdh
+ * http://csrc.nist.gov/groups/STM/cavp/component-testing.html#ECCCDH
  * $ sha256sum KAS_ECC_CDH_PrimitiveTest.txt 
  * 456068d3f8aad8ac62a03d19ed3173f00ad51f42b51aeab4753c20f30c01cf23  KAS_ECC_CDH_PrimitiveTest.txt
  */
  * $ sha256sum KAS_ECC_CDH_PrimitiveTest.txt 
  * 456068d3f8aad8ac62a03d19ed3173f00ad51f42b51aeab4753c20f30c01cf23  KAS_ECC_CDH_PrimitiveTest.txt
  */
@@ -19,6 +19,7 @@ typedef struct {
 } ecdh_cavs_kat_t;
 
 static const ecdh_cavs_kat_t ecdh_cavs_kats[] = {
 } ecdh_cavs_kat_t;
 
 static const ecdh_cavs_kat_t ecdh_cavs_kats[] = {
+    /* curves over prime fields go here */
     { NID_X9_62_prime192v1,
     "42ea6dd9969dd2a61fea1aac7f8e98edcc896c6e55857cc0",
     "dfbe5d7c61fac88b11811bde328e8a0d12bf01a9d204b523",
     { NID_X9_62_prime192v1,
     "42ea6dd9969dd2a61fea1aac7f8e98edcc896c6e55857cc0",
     "dfbe5d7c61fac88b11811bde328e8a0d12bf01a9d204b523",
@@ -1345,6 +1346,7 @@ static const ecdh_cavs_kat_t ecdh_cavs_kats[] = {
     "b4411cda7a0785b15d149ed301a3697062f42da237aa7f07e0af3fd00eb1800d"
     "9c41" }
 #ifndef OPENSSL_NO_EC2M
     "b4411cda7a0785b15d149ed301a3697062f42da237aa7f07e0af3fd00eb1800d"
     "9c41" }
 #ifndef OPENSSL_NO_EC2M
+    /* curves over binary fields go here */
     , { NID_sect163k1,
     "0000000574236f1428c432130946783a5b3aabb6c27ea5d6",
     "00000007908c251b8da021cbac281f123f7af4fac5b3dbb8",
     , { NID_sect163k1,
     "0000000574236f1428c432130946783a5b3aabb6c27ea5d6",
     "00000007908c251b8da021cbac281f123f7af4fac5b3dbb8",