[openssl-commits] [openssl] master update
Rich Salz
rsalz at openssl.org
Wed Jun 21 13:34:58 UTC 2017
The branch master has been updated
via 2556aec5d07546963eddc2df6824729fc218f41b (commit)
from 1d23bbccd3dc966254368bcd102bb685c641b14f (commit)
- Log -----------------------------------------------------------------
commit 2556aec5d07546963eddc2df6824729fc218f41b
Author: Rich Salz <rsalz at openssl.org>
Date: Fri Jun 16 16:55:19 2017 -0400
Add ecstress test
Reviewed-by: Andy Polyakov <appro at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3720)
-----------------------------------------------------------------------
Summary of changes:
test/build.info | 6 +-
test/ecstresstest.c | 161 +++++++++++++++++++++
...{60-test_x509_dup_cert.t => 99-test_ecstress.t} | 14 +-
3 files changed, 176 insertions(+), 5 deletions(-)
create mode 100644 test/ecstresstest.c
copy test/recipes/{60-test_x509_dup_cert.t => 99-test_ecstress.t} (59%)
diff --git a/test/build.info b/test/build.info
index eba52cc..205ba60 100644
--- a/test/build.info
+++ b/test/build.info
@@ -27,7 +27,7 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=MAIN
PROGRAMS_NO_INST=\
aborttest test_test \
sanitytest exdatatest bntest \
- ectest ecdsatest gmdifftest pbelutest ideatest \
+ ectest ecstresstest ecdsatest gmdifftest pbelutest ideatest \
md2test \
hmactest \
rc2test rc4test rc5test \
@@ -69,6 +69,10 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=MAIN
INCLUDE[ectest]=.. ../include
DEPEND[ectest]=../libcrypto libtestutil.a
+ SOURCE[ecstresstest]=ecstresstest.c
+ INCLUDE[ecstresstest]=.. ../include
+ DEPEND[ecstresstest]=../libcrypto libtestutil.a
+
SOURCE[ecdsatest]=ecdsatest.c
INCLUDE[ecdsatest]=../include
DEPEND[ecdsatest]=../libcrypto libtestutil.a
diff --git a/test/ecstresstest.c b/test/ecstresstest.c
new file mode 100644
index 0000000..5ea8f84
--- /dev/null
+++ b/test/ecstresstest.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL licenses, (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * https://www.openssl.org/source/license.html
+ * or in the file LICENSE in the source distribution.
+ */
+
+#include "e_os.h"
+#include "testutil.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#define NUM_REPEATS "1000000"
+
+static int64_t num_repeats;
+static int print_mode = 0;
+
+#ifndef OPENSSL_NO_EC
+# include <openssl/ec.h>
+# include <openssl/err.h>
+# include <openssl/obj_mac.h>
+# include <openssl/objects.h>
+# include <openssl/rand.h>
+# include <openssl/bn.h>
+# include <openssl/opensslconf.h>
+
+static const char *kP256DefaultResult =
+ "A1E24B223B8E81BC1FFF99BAFB909EDB895FACDE7D6DA5EF5E7B3255FB378E0F";
+
+/*
+ * Perform a deterministic walk on the curve, by starting from |point| and
+ * using the X-coordinate of the previous point as the next scalar for
+ * point multiplication.
+ * Returns the X-coordinate of the end result or NULL on error.
+ */
+static BIGNUM *walk_curve(const EC_GROUP *group, EC_POINT *point, int64_t num)
+{
+ BIGNUM *scalar = NULL;
+ int64_t i;
+
+ if (!TEST_ptr(scalar = BN_new())
+ || !TEST_true(EC_POINT_get_affine_coordinates_GFp(group, point,
+ scalar,
+ NULL, NULL)))
+ goto err;
+
+ for (i = 0; i < num; i++) {
+ if (!TEST_true(EC_POINT_mul(group, point, NULL, point, scalar, NULL))
+ || !TEST_true(EC_POINT_get_affine_coordinates_GFp(group, point,
+ scalar,
+ NULL, NULL)))
+ goto err;
+ }
+ return scalar;
+
+err:
+ BN_free(scalar);
+ return NULL;
+}
+
+static int test_curve()
+{
+ EC_GROUP *group = NULL;
+ EC_POINT *point = NULL;
+ BIGNUM *result = NULL, *expected_result = NULL;
+ int ret = 0;
+
+ /*
+ * We currently hard-code P-256, though adaptation to other curves.
+ * would be straightforward.
+ */
+ if (!TEST_ptr(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1))
+ || !TEST_ptr(point = EC_POINT_dup(EC_GROUP_get0_generator(group),
+ group))
+ || !TEST_ptr(result = walk_curve(group, point, num_repeats)))
+ return 0;
+
+ if (print_mode) {
+ BN_print(bio_out, result);
+ BIO_printf(bio_out, "\n");
+ ret = 1;
+ } else {
+ if (!TEST_true(BN_hex2bn(&expected_result, kP256DefaultResult))
+ || !TEST_ptr(expected_result)
+ || !TEST_BN_eq(result, expected_result))
+ goto err;
+ ret = 1;
+ }
+
+err:
+ EC_GROUP_free(group);
+ EC_POINT_free(point);
+ BN_free(result);
+ BN_free(expected_result);
+ return ret;
+}
+#endif
+
+static int atoi64(const char *in, int64_t *result)
+{
+ int64_t ret = 0;
+
+ for ( ; *in != '\0'; in++) {
+ char c = *in;
+
+ if (!isdigit(c))
+ return 0;
+ ret *= 10;
+ ret += (c - '0');
+ }
+ *result = ret;
+ return 1;
+}
+
+/*
+ * Stress test the curve. If the '-num' argument is given, runs the loop
+ * |num| times and prints the resulting X-coordinate. Otherwise runs the test
+ * the default number of times and compares against the expected result.
+ */
+int test_main(int argc, char *argv[])
+{
+ const char *argv0 = argv[0];
+
+ if (!atoi64(NUM_REPEATS, &num_repeats)) {
+ TEST_error("Cannot parse " NUM_REPEATS);
+ return EXIT_FAILURE;
+ }
+ /*
+ * TODO(openssl-team): code under test/ should be able to reuse the option
+ * parsing framework currently in apps/.
+ */
+ argc--;
+ argv++;
+ while (argc >= 1) {
+ if (strcmp(*argv, "-num") == 0) {
+ if (--argc < 1
+ || !atoi64(*++argv, &num_repeats)
+ || num_repeats < 0) {
+ TEST_error("Bad -num argument\n");
+ return EXIT_FAILURE;
+ }
+ print_mode = 1;
+ } else {
+ TEST_error("Unknown option %s\n", *argv);
+ return EXIT_FAILURE;
+ }
+ argc--;
+ argv++;
+ }
+
+#ifndef OPENSSL_NO_EC
+ ADD_TEST(test_curve);
+#endif
+ return run_tests(argv0);
+}
diff --git a/test/recipes/60-test_x509_dup_cert.t b/test/recipes/99-test_ecstress.t
similarity index 59%
copy from test/recipes/60-test_x509_dup_cert.t
copy to test/recipes/99-test_ecstress.t
index 7cae05c..f95a544 100644
--- a/test/recipes/60-test_x509_dup_cert.t
+++ b/test/recipes/99-test_ecstress.t
@@ -1,17 +1,23 @@
#! /usr/bin/env perl
# Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
-# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
+use strict;
+use warnings;
-use OpenSSL::Test qw/:DEFAULT srctop_file/;
+use OpenSSL::Test;
+use OpenSSL::Test::Utils;
-setup("test_x509_dup_cert");
+setup("test_ecstress");
plan tests => 1;
-ok(run(test(["x509_dup_cert_test", srctop_file("test", "certs", "leaf.pem")])));
+SKIP: {
+ skip "Skipping EC stress test", 1
+ if ! exists $ENV{'ECSTRESS'};
+ ok(run(test(["ecstresstest"])), "running ecstresstest");
+}
More information about the openssl-commits
mailing list