diff options
author | Franziskus Kiefer <franziskuskiefer@gmail.com> | 2016-04-29 22:05:13 +0200 |
---|---|---|
committer | Franziskus Kiefer <franziskuskiefer@gmail.com> | 2016-04-29 22:05:13 +0200 |
commit | d2ec5a56bf18831b538ebc9f071c6a58fd3f6769 (patch) | |
tree | b09d0df38ecd4c86af74fd97293557558064cf92 | |
parent | cc2742adb4161ff24b5c5199352e726599d59c24 (diff) | |
download | nss-hg-d2ec5a56bf18831b538ebc9f071c6a58fd3f6769.tar.gz |
Bug 1265994 - enable ecperf tests, r=ttaubert
-rw-r--r-- | cmd/ecperf/ecperf.c | 50 | ||||
-rwxr-xr-x | cmd/ecperf/manifest.mn | 14 | ||||
-rw-r--r-- | cmd/manifest.mn | 1 | ||||
-rwxr-xr-x | tests/all.sh | 2 | ||||
-rwxr-xr-x | tests/ec/ec.sh | 37 | ||||
-rwxr-xr-x | tests/ec/ecperf.sh | 52 |
6 files changed, 138 insertions, 18 deletions
diff --git a/cmd/ecperf/ecperf.c b/cmd/ecperf/ecperf.c index 8a60ac641..a47147ed6 100644 --- a/cmd/ecperf/ecperf.c +++ b/cmd/ecperf/ecperf.c @@ -125,6 +125,9 @@ PKCS11Thread(void *data) PR_Lock(threadData->lock); crv = NSC_OpenSession(1, CKF_SERIAL_SESSION, NULL, 0, &session); PR_Unlock(threadData->lock); + if (crv != CKR_OK) { + return; + } if (threadData->isSign) { sig.data = sigData; @@ -311,8 +314,9 @@ hexString2SECItem(PLArenaPool *arena, SECItem *item, const char *str) int byteval = 0; int tmp = PORT_Strlen(str); - if ((tmp % 2) != 0) + if ((tmp % 2) != 0) { return NULL; + } /* skip leading 00's unless the hex string is "00" */ while ((tmp > 2) && (str[0] == '0') && (str[1] == '0')) { @@ -530,23 +534,27 @@ ectest_curve_pkcs11(ECCurveName curve, int iterations, int numThreads) rv = M_TimeOperation(PKCS11Thread, (op_func)PKCS11_Derive, "ECDH_Derive", &ecPriv, &mech, NULL, iterations, numThreads, lock, session, 0, &deriveRate); - if (rv != SECSuccess) + if (rv != SECSuccess) { goto cleanup; + } rv = M_TimeOperation(PKCS11Thread, (op_func)PKCS11_Sign, "ECDSA_Sign", (void *)&ecPriv, &sig, &digest, iterations, numThreads, lock, session, 1, &signRate); - if (rv != SECSuccess) + if (rv != SECSuccess) { goto cleanup; + } printf(" ECDHE max rate = %.2f\n", (deriveRate + signRate) / 4.0); /* get a signature */ rv = PKCS11_Sign(session, &ecPriv, &sig, &digest); - if (rv != SECSuccess) + if (rv != SECSuccess) { goto cleanup; + } rv = M_TimeOperation(PKCS11Thread, (op_func)PKCS11_Verify, "ECDSA_Verify", (void *)&ecPub, &sig, &digest, iterations, numThreads, lock, session, 0, NULL); - if (rv != SECSuccess) + if (rv != SECSuccess) { goto cleanup; + } cleanup: if (lock) { @@ -590,7 +598,7 @@ ectest_curve_freebl(ECCurveName curve, int iterations, int numThreads) unsigned char digestData[20]; double signRate, deriveRate; char genenc[3 + 2 * 2 * MAX_ECKEY_LEN]; - SECStatus rv; + SECStatus rv = SECFailure; GFP_POPULATE(ecParams, curve); @@ -609,20 +617,23 @@ ectest_curve_freebl(ECCurveName curve, int iterations, int numThreads) M_TimeOperation(genericThread, (op_func)ECDH_DeriveWrap, "ECDH_Derive", ecPriv, &ecPub, NULL, iterations, numThreads, 0, 0, 0, &deriveRate); - if (rv != SECSuccess) + if (rv != SECSuccess) { goto cleanup; + } M_TimeOperation(genericThread, (op_func)ECDSA_SignDigest, "ECDSA_Sign", ecPriv, &sig, &digest, iterations, numThreads, 0, 0, 1, &signRate); if (rv != SECSuccess) goto cleanup; printf(" ECDHE max rate = %.2f\n", (deriveRate + signRate) / 4.0); rv = ECDSA_SignDigest(ecPriv, &sig, &digest); - if (rv != SECSuccess) + if (rv != SECSuccess) { goto cleanup; + } M_TimeOperation(genericThread, (op_func)ECDSA_VerifyDigest, "ECDSA_Verify", &ecPub, &sig, &digest, iterations, numThreads, 0, 0, 0, NULL); - if (rv != SECSuccess) + if (rv != SECSuccess) { goto cleanup; + } cleanup: return rv; @@ -632,7 +643,9 @@ cleanup: void printUsage(char *prog) { - printf("Usage: %s [-i iterations] [-t threads ] [-ans] [-fp] [-A]\n", prog); + printf("Usage: %s [-i iterations] [-t threads ] [-ans] [-fp] [-Al]\n" + "-a: ansi\n-n: nist\n-s: secp\n-f: usefreebl\n-p: usepkcs11\n-A: all\n", + prog); } /* Performs tests of elliptic curve cryptography over prime fields If @@ -651,6 +664,11 @@ main(int argv, char **argc) int iterations = 100; int numThreads = 1; + const CK_C_INITIALIZE_ARGS pk11args = { + NULL, NULL, NULL, NULL, CKF_LIBRARY_CANT_CREATE_OS_THREADS, + (void *)"flags=readOnly,noCertDB,noModDB", NULL + }; + /* read command-line arguments */ for (i = 1; i < argv; i++) { if (strcasecmp(argc[i], "-i") == 0) { @@ -691,15 +709,26 @@ main(int argv, char **argc) goto cleanup; } + if (usepkcs11) { + CK_RV crv = NSC_Initialize((CK_VOID_PTR)&pk11args); + if (crv != CKR_OK) { + fprintf(stderr, "NSC_Initialize failed crv=0x%x\n", (unsigned int)crv); + return SECFailure; + } + } + /* specific arithmetic tests */ if (nist) { +#ifdef NSS_ECC_MORE_THAN_SUITE_B ECTEST_NAMED_GFP("SECP-160K1", ECCurve_SECG_PRIME_160K1); ECTEST_NAMED_GFP("NIST-P192", ECCurve_NIST_P192); ECTEST_NAMED_GFP("NIST-P224", ECCurve_NIST_P224); +#endif ECTEST_NAMED_GFP("NIST-P256", ECCurve_NIST_P256); ECTEST_NAMED_GFP("NIST-P384", ECCurve_NIST_P384); ECTEST_NAMED_GFP("NIST-P521", ECCurve_NIST_P521); } +#ifdef NSS_ECC_MORE_THAN_SUITE_B if (ansi) { ECTEST_NAMED_GFP("ANSI X9.62 PRIME192v1", ECCurve_X9_62_PRIME_192V1); ECTEST_NAMED_GFP("ANSI X9.62 PRIME192v2", ECCurve_X9_62_PRIME_192V2); @@ -726,6 +755,7 @@ main(int argv, char **argc) ECTEST_NAMED_GFP("SECP-384R1", ECCurve_SECG_PRIME_384R1); ECTEST_NAMED_GFP("SECP-521R1", ECCurve_SECG_PRIME_521R1); } +#endif cleanup: if (rv != SECSuccess) { diff --git a/cmd/ecperf/manifest.mn b/cmd/ecperf/manifest.mn index 61fa8809b..2931a11ad 100755 --- a/cmd/ecperf/manifest.mn +++ b/cmd/ecperf/manifest.mn @@ -1,24 +1,24 @@ -# +# # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -DEPTH = ../.. +DEPTH = ../.. CORE_DEPTH = ../.. -# MODULE public and private header directories are implicitly REQUIRED. +# MODULE public and private header directories are implicitly REQUIRED. MODULE = nss INCLUDES += -I$(CORE_DEPTH)/nss/lib/softoken # This next line is used by .mk files # and gets translated into $LINCS in manifest.mnw -REQUIRES = dbm seccmd +REQUIRES = dbm seccmd -# DIRS = +# DIRS = -CSRCS = ecperf.c +CSRCS = ecperf.c -PROGRAM = ecperf +PROGRAM = ecperf USE_STATIC_LIBS = 1 diff --git a/cmd/manifest.mn b/cmd/manifest.mn index deedd21c8..e892640cf 100644 --- a/cmd/manifest.mn +++ b/cmd/manifest.mn @@ -42,6 +42,7 @@ NSS_SRCDIRS = \ dbtest \ derdump \ digest \ + ecperf \ httpserv \ listsuites \ makepqg \ diff --git a/tests/all.sh b/tests/all.sh index e2890e53d..ac34bf658 100755 --- a/tests/all.sh +++ b/tests/all.sh @@ -280,7 +280,7 @@ run_cycles() cycles="standard pkix upgradedb sharedb" CYCLES=${NSS_CYCLES:-$cycles} -tests="cipher lowhash libpkix cert dbtests tools fips sdr crmf smime ssl ocsp merge pkits chains ssl_gtests pk11_gtests der_gtests util_gtests" +tests="cipher lowhash libpkix cert dbtests tools fips sdr crmf smime ssl ocsp merge pkits chains ec ssl_gtests pk11_gtests der_gtests util_gtests" TESTS=${NSS_TESTS:-$tests} ALL_TESTS=${TESTS} diff --git a/tests/ec/ec.sh b/tests/ec/ec.sh new file mode 100755 index 000000000..6b652006c --- /dev/null +++ b/tests/ec/ec.sh @@ -0,0 +1,37 @@ +#! /bin/bash +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +######################################################################## +# +# tests/ec/ec.sh +# +# needs to work on all Unix and Windows platforms +# this is a meta script to drive all ec tests +# +# special strings +# --------------- +# FIXME ... known problems, search for this string +# NOTE .... unexpected behavior +# +######################################################################## + +############################## run_tests ############################### +# run test suites defined in ECTESTS variable +######################################################################## +run_ec_tests() +{ + for ECTEST in ${ECTESTS} + do + SCRIPTNAME=${ECTEST}.sh + echo "Running ec tests for ${ECTEST}" + echo "TIMESTAMP ${ECTEST} BEGIN: `date`" + (cd ${QADIR}/ec; . ./${SCRIPTNAME} 2>&1) + echo "TIMESTAMP ${ECTEST} END: `date`" + done +} + +ECTESTS="ecperf" +run_ec_tests
\ No newline at end of file diff --git a/tests/ec/ecperf.sh b/tests/ec/ecperf.sh new file mode 100755 index 000000000..9dddc3959 --- /dev/null +++ b/tests/ec/ecperf.sh @@ -0,0 +1,52 @@ +#! /bin/bash +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +######################################################################## +# +# tests/ec/ecperf.sh +# +# needs to work on all Unix and Windows platforms +# +# special strings +# --------------- +# FIXME ... known problems, search for this string +# NOTE .... unexpected behavior +# +######################################################################## + +############################## ecperf_init ############################# +# local shell function to initialize this script +######################################################################## + +ecperf_init() +{ + SCRIPTNAME="ecperf.sh" + if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ] ; then + cd ../common + . ./init.sh + fi + SCRIPTNAME="ecperf.sh" + html_head "ecperf test" +} + +ecperf_cleanup() +{ + html "</TABLE><BR>" + cd ${QADIR} + chmod a+rw $RONLY_DIR + . common/cleanup.sh +} + +ecperf_init +ECPERF_OUT=`ecperf` +ECPERF_OUT=`echo $ECPERF_OUT | grep -i "failed"` +# TODO: this is a perf test we don't check for performance here but only failed +if [ -n "$ECPERF_OUT" ] ; then + html_failed "ec(perf) test" +else + html_passed "ec(perf) test" +fi +ecperf_cleanup
\ No newline at end of file |