You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by sa...@apache.org on 2021/01/06 14:28:11 UTC
[incubator-milagro-crypto-c] 02/04: Add benchmarks for ff
precomputation
This is an automated email from the ASF dual-hosted git repository.
sandreoli pushed a commit to branch add-ff-exp-precomputation
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-c.git
commit 43d8c433d3c675ca1f5199b0979f12882cd22a36
Author: Samuele Andreoli <sa...@yahoo.it>
AuthorDate: Wed Jan 6 13:40:10 2021 +0000
Add benchmarks for ff precomputation
---
benchmark/CMakeLists.txt | 31 ++++-
benchmark/bench.c.in | 97 ++++++++++++++
benchmark/bench.h | 44 +++++++
benchmark/benchtest_ec_ZZZ.c.in | 11 +-
benchmark/benchtest_ff_WWW.c.in | 265 ++++++++++++++++++++++++++++++++++++++
benchmark/benchtest_mpin_ZZZ.c.in | 8 ++
benchmark/benchtest_paillier.c.in | 81 +-----------
benchmark/benchtest_pair_ZZZ.c.in | 12 +-
benchmark/benchtest_rsa_WWW.c.in | 15 +--
9 files changed, 454 insertions(+), 110 deletions(-)
diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt
index af05ab7..782cbd4 100644
--- a/benchmark/CMakeLists.txt
+++ b/benchmark/CMakeLists.txt
@@ -17,6 +17,23 @@
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
+link_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+include_directories (
+ ${PROJECT_SOURCE_DIR}/include
+ ${PROJECT_SOURCE_DIR}/benchmark
+ ${PROJECT_BINARY_DIR}/include
+)
+
+configure_file(
+ "bench.c.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/bench.c"
+)
+
+add_library(amcl_bench_utils OBJECT ${CMAKE_CURRENT_BINARY_DIR}/bench.c)
+
foreach(curve ${AMCL_CURVE})
amcl_curve_field(PF "${curve}")
amcl_curve_field(TC "${curve}")
@@ -24,20 +41,20 @@ foreach(curve ${AMCL_CURVE})
# Curve Benchmark
amcl_configure_file_curve(benchtest_ec_ZZZ.c.in benchtest_ec_${TC}.c "${curve}" benchtest_ec_${TC}_GEN_SRCS)
- add_executable(benchtest_ec_${TC} ${benchtest_ec_${TC}_GEN_SRCS})
+ add_executable(benchtest_ec_${TC} ${benchtest_ec_${TC}_GEN_SRCS} $<TARGET_OBJECTS:amcl_bench_utils>)
target_link_libraries(benchtest_ec_${TC} PRIVATE amcl_curve_${TC})
# Pairing Benchmark
if(TARGET amcl_pairing_${TC})
amcl_configure_file_curve(benchtest_pair_ZZZ.c.in benchtest_pair_${TC}.c "${curve}" benchtest_pair_${TC}_GEN_SRCS)
- add_executable(benchtest_pair_${TC} ${benchtest_pair_${TC}_GEN_SRCS})
+ add_executable(benchtest_pair_${TC} ${benchtest_pair_${TC}_GEN_SRCS} $<TARGET_OBJECTS:amcl_bench_utils>)
target_link_libraries(benchtest_pair_${TC} PRIVATE amcl_pairing_${TC})
endif()
# MPIN Benchmark
if(TARGET amcl_mpin_${TC})
amcl_configure_file_curve(benchtest_mpin_ZZZ.c.in benchtest_mpin_${TC}.c "${curve}" benchtest_mpin_${TC}_GEN_SRCS)
- add_executable(benchtest_mpin_${TC} ${benchtest_mpin_${TC}_GEN_SRCS})
+ add_executable(benchtest_mpin_${TC} ${benchtest_mpin_${TC}_GEN_SRCS} $<TARGET_OBJECTS:amcl_bench_utils>)
target_link_libraries(benchtest_mpin_${TC} PRIVATE amcl_mpin_${TC})
endif()
@@ -47,12 +64,16 @@ foreach(level ${AMCL_RSA})
amcl_rsa_field(TFF "${level}")
amcl_configure_file_rsa(benchtest_rsa_WWW.c.in benchtest_rsa_${TFF}.c "${level}" benchtest_rsa_${TFF}_GEN_SRCS)
- add_executable(benchtest_rsa_${TFF} ${benchtest_rsa_${TFF}_GEN_SRCS})
+ add_executable(benchtest_rsa_${TFF} ${benchtest_rsa_${TFF}_GEN_SRCS} $<TARGET_OBJECTS:amcl_bench_utils>)
target_link_libraries(benchtest_rsa_${TFF} PRIVATE amcl_rsa_${TFF})
+
+ amcl_configure_file_rsa(benchtest_ff_WWW.c.in benchtest_ff_${TFF}.c "${level}" benchtest_ff_${TFF}_GEN_SRCS)
+ add_executable(benchtest_ff_${TFF} ${benchtest_ff_${TFF}_GEN_SRCS} $<TARGET_OBJECTS:amcl_bench_utils>)
+ target_link_libraries(benchtest_ff_${TFF} PRIVATE amcl_rsa_${TFF})
endforeach()
if(${BUILD_PAILLIER})
amcl_configure_file_core(benchtest_paillier.c.in benchtest_paillier.c benchtest_paillier_GEN_SRCS)
- add_executable(benchtest_paillier ${benchtest_paillier_GEN_SRCS})
+ add_executable(benchtest_paillier ${benchtest_paillier_GEN_SRCS} $<TARGET_OBJECTS:amcl_bench_utils>)
target_link_libraries(benchtest_paillier PRIVATE amcl_paillier)
endif()
diff --git a/benchmark/bench.c.in b/benchmark/bench.c.in
new file mode 100644
index 0000000..c49263b
--- /dev/null
+++ b/benchmark/bench.c.in
@@ -0,0 +1,97 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+/*
+ Benchmark utilities definitions.
+ */
+
+#include "bench.h"
+#include "amcl.h"
+
+// https://sourceforge.net/p/predef/wiki/Compilers/
+static void print_compiler_info()
+{
+#if defined(__clang__)
+ printf("Compiler:\t\tclang (%s)\n", __clang_version__);
+#elif defined(__GNUC_PATCHLEVEL__)
+ printf("Compiler:\t\tgcc (%d.%d.%d)\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
+#elif defined(__GNUC_MINOR__)
+ printf("Compiler:\t\tgcc (%d.%d)\n", __GNUC__, __GNUC_MINOR__);
+#elif defined(__INTEL_COMPILER)
+ printf("Compiler:\t\tIntel C/C++ (%d)\n", __INTEL_COMPILER);
+#elif defined(_MSC_FULL_VER)
+ printf("Compiler:\tMicrosoft C/C++ (%d)\n", _MSC_FULL_VER);
+#elif defined(__CC_ARM)
+ printf("Compiler:\t\tARM C/C++ (%d)\n", __ARMCC_VERSION);
+#else
+ printf("Compiler:\t\tUnknown"\n);
+#endif
+}
+
+#if defined(__ANDROID__)
+#include <android/api-level.h>
+#endif
+
+// https://sourceforge.net/p/predef/wiki/Architectures/
+// https://sourceforge.net/p/predef/wiki/OperatingSystems/
+static void print_platform_info()
+{
+#if defined(__linux__)
+ printf("Target platform:\tLinux ");
+
+#if defined(__x86_64__)
+ printf("(64-bit)\n");
+#else
+ printf("(32-bit)\n");
+#endif
+
+#if defined(__ANDROID__)
+ printf("Target platform:\tAndroid %d\n", __ANDROID_API__);
+#endif
+
+#elif defined(_WIN64)
+ printf("Target platform:\tWindows (64-bit)\n");
+#elif defined(_WIN32)
+ printf("Target platform:\tWindows (32-bit)\n");
+#elif defined(__APPLE__)
+ printf("Target platform:\tMac OS\n");
+#else
+ printf("Target platform:\tUnknown\n");
+#endif
+}
+
+static void print_amcl_configuration()
+{
+ printf("Project Version:\t@BUILD_VERSION@\n");
+ printf("CFLAGS:\t\t\t@CMAKE_C_FLAGS@\n");
+ printf("Build type:\t\t@CMAKE_BUILD_TYPE@\n");
+ printf("AMCL Version:\t\t%d.%d.%d\n", AMCL_VERSION_MAJOR, AMCL_VERSION_MINOR, AMCL_VERSION_PATCH);
+ printf("AMCL Detected OS:\t%s\n", OS);
+ printf("AMCL CHUNK:\t\t%d\n", CHUNK);
+}
+
+void print_system_info()
+{
+ printf("Configuration info\n");
+ printf("==================\n");
+ print_platform_info();
+ print_compiler_info();
+ print_amcl_configuration();
+ printf("\n");
+}
diff --git a/benchmark/bench.h b/benchmark/bench.h
new file mode 100644
index 0000000..6472bf5
--- /dev/null
+++ b/benchmark/bench.h
@@ -0,0 +1,44 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+/*
+ Benchmark utilities declarations
+ */
+
+#ifndef BENCH_H
+#define BENCH_H
+
+#include <time.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define MILLISECOND 1000.0
+#define MICROSECOND 1000000.0
+
+/*! @brief Print Target System and Build information */
+extern void print_system_info();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/benchmark/benchtest_ec_ZZZ.c.in b/benchmark/benchtest_ec_ZZZ.c.in
index acb3945..4994062 100644
--- a/benchmark/benchtest_ec_ZZZ.c.in
+++ b/benchmark/benchtest_ec_ZZZ.c.in
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <time.h>
#include "ecp_ZZZ.h"
+#include "bench.h"
#define MIN_TIME 10.0
#define MIN_ITERS 10
@@ -59,15 +60,7 @@ int main()
printf("Montgomery parameterization\n");
#endif
-#if CHUNK==16
- printf("16-bit Build\n\n");
-#endif
-#if CHUNK==32
- printf("32-bit Build\n\n");
-#endif
-#if CHUNK==64
- printf("64-bit Build\n\n");
-#endif
+ print_system_info();
time((time_t *)&ran);
pr[0]=ran;
diff --git a/benchmark/benchtest_ff_WWW.c.in b/benchmark/benchtest_ff_WWW.c.in
new file mode 100644
index 0000000..537d551
--- /dev/null
+++ b/benchmark/benchtest_ff_WWW.c.in
@@ -0,0 +1,265 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+/*
+ Benchmark FF exponentiations.
+ */
+
+#include <stdio.h>
+#include "bench.h"
+#include "arch.h"
+#include "amcl.h"
+#include "utils.h"
+#include "ff_WWW.h"
+
+#define MIN_TIME 5.0
+#define MIN_ITERS 10
+
+#define FS_WWW MODBYTES_XXX*FFLEN_WWW
+
+#if WWW == 2048
+char *Nhex = "c1bdd91e09594d376ec23bdb2de1cd08033fc89cdc44c4fa12a3d3295fa8a351a093e0bd23cc1c0faf7dd04cc306103581089f2756a2e3b233ec00c3544f4cf82634b0a33fb23e8f9991ea94a61e7212340db0c5d6b1c5c6e3ff7700117ee10ec08c7db17d1ccc765781dd64f03b068bca83125d8afb714739fea60a95777082aebba70aafd8757ec93f8340712eb4b652fdecb3522e175951b987b4403e7a7f3eb87eaf2b58159ff3d43cc3f1c7a08a305669dd6cc5682186ea1a61228ccf25185c9895ab637186263d0d57769abc3c3a0ba78e86ff0bbea6479f514a51495293dcaf4d4f1eec997ebf3bd972c77a [...]
+#elif WWW == 3072
+char *Nhex = "ed9eb99a931743d83c465d65f4e467808105ea2dba2662741315985c9416f482dcb527da186e96e4cff1541ec7584a832ab0c849c2356f0821b1d1ff2606834411fdaa2a82ee6380e2c97e5b7324ecdc0a0a224349e405b8f5ed6d6d46c3b5564f98c432b1c56143b665821831bb3eb09b230873622a3fbce9d563a46f2574110442284fae27a90d926050572b620d676f37cef349a77632a3171e9288d6c8c85e3fdbe0df1f0ca9028b9edeebdad15ee2a9b65aa12e3902fa7f17a4e4dc4fcecc4ed264a7a2107d2cef8e7239037249ca33d82b900d24b605ae870dc16cdcc87e701b6456129a25839fb0d16c5508 [...]
+#else
+char *Nhex = "c01b73cc3f6232c4b525ee17053d1c90aa21750422c19718bf0caa688c70f9fba2df575dffe03bc7fa2cf568235323afaba8cf466aaad86909e189af3f8d941c37d8c68cd68a07b2329c7c8183ab0af013f2737decc59c1b69af3a80bc13d47742df98b0f5f398ce396d2dcf015bd97618d1ea9ad8dc653d408950821b021c1176a9f645c479c205a4810c33e6993fc7448848ad07470f77fd859b0c8acee2f89e6724770b43c2b6f8621bd0b91cf16e46fbad293399fed1864e9e8f558c3f17f1714d6d2f1ae43933404cf692375b65a8af9dfd2ca237c8722ae2b58d21272ec5fb0c03a118186adcdd6a393019ca [...]
+#endif
+
+int main()
+{
+ int iterations;
+ clock_t start;
+ double elapsed;
+
+ // Material for exponents
+ BIG_XXX A[FFLEN_WWW], B[FFLEN_WWW], C[FFLEN_WWW], D[FFLEN_WWW];
+ BIG_XXX E[FFLEN_WWW], F[FFLEN_WWW], G[FFLEN_WWW], H[FFLEN_WWW];
+ BIG_XXX N[FFLEN_WWW];
+ BIG_XXX R[FFLEN_WWW];
+
+ // Material for precomputation
+ BIG_XXX T_mem[16][FFLEN_WWW];
+ BIG_XXX *T[] =
+ {
+ T_mem[0], T_mem[1], T_mem[2], T_mem[3],
+ T_mem[4], T_mem[5], T_mem[6], T_mem[7],
+ T_mem[8], T_mem[9], T_mem[10], T_mem[11],
+ T_mem[12], T_mem[13], T_mem[14], T_mem[15],
+ };
+
+ BIG_XXX *X[] = {A, B, C, D};
+ BIG_XXX *EXP[] = {E, F, G, H};
+
+ BIG_XXX ND[FFLEN_WWW];
+
+ char oct[FS_WWW];
+ octet OCT = {0,sizeof(oct),oct};
+
+ /* Fake random source */
+ int i;
+ char seed[256];
+ csprng RNG;
+
+ RAND_clean(&RNG);
+ for (i=0; i<256; i++) seed[i]=(char)i;
+ RAND_seed(&RNG,256,seed);
+
+ /* Read N from hex */
+ OCT_fromHex(&OCT, Nhex);
+ FF_WWW_fromOctet(N, &OCT, FFLEN_WWW);
+
+ /* Compute additional values */
+ FF_WWW_invmod2m(ND, N, FFLEN_WWW);
+
+ printf("\nBechmark FF exponentiation - FF_WWW\n");
+
+ print_system_info();
+
+ FF_WWW_random(A, &RNG, FFLEN_WWW);
+ FF_WWW_random(B, &RNG, FFLEN_WWW);
+ FF_WWW_random(C, &RNG, FFLEN_WWW);
+ FF_WWW_random(D, &RNG, FFLEN_WWW);
+
+ FF_WWW_random(E, &RNG, FFLEN_WWW);
+ FF_WWW_random(F, &RNG, FFLEN_WWW);
+ FF_WWW_random(G, &RNG, FFLEN_WWW);
+ FF_WWW_random(H, &RNG, FFLEN_WWW);
+
+ /* Benchmark non constant-time exponents */
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_nt_pow(R, A, E, N, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_nt_pow\t\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_nt_pow_2(R, A, E, B, F, N, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_nt_pow_2\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_nt_pow_3(R, A, E, B, F, C, G, N, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_nt_pow_3\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_nt_pow_4(R, A, E, B, F, C, G, D, H, N, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_nt_pow_4\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ /* Benchmark constant-time exponenets */
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_ct_pow(R, A, E, N, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_ct_pow\t\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_ct_pow_2(R, A, E, B, F, N, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_ct_pow_2\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_ct_pow_3(R, A, E, B, F, C, G, N, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_ct_pow_3\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ /* Benchmark standalone precomputation/evaluation */
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_2w_precompute(X, T, 4, 1, N, ND, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_2w_precompute\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_ct_2w_pow(R, T, EXP, 4, 1, N, ND, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_ct_2w_pow\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_nt_2w_pow(R, T, EXP, 4, 1, N, ND, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_nt_2w_pow\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_bi_precompute(X, T, 4, 3, N, ND, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_bi_precompute\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+
+ iterations=0;
+ start=clock();
+ do
+ {
+ FF_WWW_bi_pow(R, T, EXP, 4, 3, N, ND, FFLEN_WWW, FFLEN_WWW);
+ iterations++;
+ elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
+ }
+ while (elapsed<MIN_TIME || iterations<MIN_ITERS);
+ elapsed=1000.0*elapsed/iterations;
+ printf("FF_WWW_bi_pow\t\t%8d iterations\t",iterations);
+ printf("%8.2lf ms per iteration\n",elapsed);
+}
\ No newline at end of file
diff --git a/benchmark/benchtest_mpin_ZZZ.c.in b/benchmark/benchtest_mpin_ZZZ.c.in
index 49c117b..1a8af0f 100644
--- a/benchmark/benchtest_mpin_ZZZ.c.in
+++ b/benchmark/benchtest_mpin_ZZZ.c.in
@@ -24,6 +24,8 @@ under the License.
#include <time.h>
#include "config_curve_ZZZ.h"
#include "randapi.h"
+#include "bench.h"
+
#if CURVE_SECURITY_ZZZ == 128
#include "mpin_ZZZ.h"
#elif CURVE_SECURITY_ZZZ == 192
@@ -85,6 +87,12 @@ int mpin(csprng *RNG)
clock_t start;
double elapsed;
+ printf("\nBechmark test MPIN - ");
+
+ printf("ZZZ Curve\n");
+
+ print_system_info();
+
/* Trusted Authority set-up */
MPIN_ZZZ_RANDOM_GENERATE(RNG,&S);
printf("Master Secret= ");
diff --git a/benchmark/benchtest_paillier.c.in b/benchmark/benchtest_paillier.c.in
index 765e8eb..f10511b 100644
--- a/benchmark/benchtest_paillier.c.in
+++ b/benchmark/benchtest_paillier.c.in
@@ -29,85 +29,12 @@ under the License.
#include "paillier.h"
#include "amcl.h"
#include "arch.h"
+#include "bench.h"
#define MIN_TIME 5.0
#define MIN_ITERS 10
#define NTHREADS 2
-// https://sourceforge.net/p/predef/wiki/Compilers/
-static void print_compiler_info()
-{
-#if defined(__clang__)
- printf("Compiler:\t\tclang (%s)\n", __clang_version__);
-#elif defined(__GNUC_PATCHLEVEL__)
- printf("Compiler:\t\tgcc (%d.%d.%d)\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
-#elif defined(__GNUC_MINOR__)
- printf("Compiler:\t\tgcc (%d.%d)\n", __GNUC__, __GNUC_MINOR__);
-#elif defined(__INTEL_COMPILER)
- printf("Compiler:\t\tIntel C/C++ (%d)\n", __INTEL_COMPILER);
-#elif defined(_MSC_FULL_VER)
- printf("Compiler:\tMicrosoft C/C++ (%d)\n", _MSC_FULL_VER);
-#elif defined(__CC_ARM)
- printf("Compiler:\t\tARM C/C++ (%d)\n", __ARMCC_VERSION);
-#else
- printf("Compiler:\t\tUnknown"\n);
-#endif
-}
-
-#if defined(__ANDROID__)
-#include <android/api-level.h>
-#endif
-
-// https://sourceforge.net/p/predef/wiki/Architectures/
-// https://sourceforge.net/p/predef/wiki/OperatingSystems/
-static void print_platform_info()
-{
-#if defined(__linux__)
- printf("Target platform:\tLinux ");
-
-#if defined(__x86_64__)
- printf("(64-bit)\n");
-#else
- printf("(32-bit)\n");
-#endif
-
-#if defined(__ANDROID__)
- printf("Target platform:\tAndroid %d\n", __ANDROID_API__);
-#endif
-
-#elif defined(_WIN64)
- printf("Target platform:\tWindows (64-bit)\n");
-#elif defined(_WIN32)
- printf("Target platform:\tWindows (32-bit)\n");
-#elif defined(__APPLE__)
- printf("Target platform:\tMac OS\n");
-#else
- printf("Target platform:\tUnknown\n");
-#endif
-}
-
-
-static void print_paillier_configuration()
-{
- printf("Project Version:\t@BUILD_VERSION@\n");
- printf("CFLAGS:\t\t\t@CMAKE_C_FLAGS@\n");
- printf("Build type:\t\t@CMAKE_BUILD_TYPE@\n");
- printf("AMCL Version:\t\t@AMCL_VERSION_MAJOR@.@AMCL_VERSION_MINOR@.@AMCL_VERSION_PATCH@\n");
- printf("AMCL Detected OS:\t@OS@\n");
- printf("AMCL CHUNK:\t\t%d\n", CHUNK);
-}
-
-static void print_system_info()
-{
- printf("Configuration info\n");
- printf("==================\n");
- print_platform_info();
- print_compiler_info();
- print_paillier_configuration();
- printf("\n");
-}
-
-
int paillier(csprng *RNG)
{
int iterations;
@@ -148,8 +75,6 @@ int paillier(csprng *RNG)
int values[NTHREADS] = {2,4};
int kvalues[NTHREADS] = {3,5};
- print_system_info();
-
// Initialize octets
for(int i=0; i<NTHREADS; i++)
{
@@ -298,6 +223,10 @@ int main()
char seed[16] = {0};
octet SEED = {sizeof(seed),sizeof(seed),seed};
+
+ printf("\nBechmark test Paillier");
+
+ print_system_info();
// CSPRNG
csprng RNG;
diff --git a/benchmark/benchtest_pair_ZZZ.c.in b/benchmark/benchtest_pair_ZZZ.c.in
index 60eafd8..0be66ff 100644
--- a/benchmark/benchtest_pair_ZZZ.c.in
+++ b/benchmark/benchtest_pair_ZZZ.c.in
@@ -27,6 +27,8 @@
#include <stdlib.h>
#include <time.h>
#include "config_curve_ZZZ.h"
+#include "bench.h"
+
#if CURVE_SECURITY_ZZZ == 128
#include "pair_ZZZ.h"
#elif CURVE_SECURITY_ZZZ == 192
@@ -81,15 +83,7 @@ int main()
printf("Bechmark test PAIR - ZZZ Curve\n");
-#if CHUNK==16
- printf("16-bit Build\n\n");
-#endif
-#if CHUNK==32
- printf("32-bit Build\n\n");
-#endif
-#if CHUNK==64
- printf("64-bit Build\n\n");
-#endif
+ print_system_info();
time((time_t *)&ran);
pr[0]=ran;
diff --git a/benchmark/benchtest_rsa_WWW.c.in b/benchmark/benchtest_rsa_WWW.c.in
index f04345e..4e803ed 100644
--- a/benchmark/benchtest_rsa_WWW.c.in
+++ b/benchmark/benchtest_rsa_WWW.c.in
@@ -28,6 +28,7 @@
#include <time.h>
#include "rsa_WWW.h"
+#include "bench.h"
#define MIN_TIME 10.0
#define MIN_ITERS 10
@@ -35,10 +36,12 @@
int main()
{
csprng RNG;
+
int i,iterations;
clock_t start;
double elapsed;
char pr[10];
+
unsigned long ran;
rsa_public_key_WWW pub;
rsa_private_key_WWW priv;
@@ -47,17 +50,7 @@ int main()
octet D= {0,sizeof(d),d};
octet C= {0,sizeof(c),c};
- printf("\nBechmark test RSA - ");
-
-#if CHUNK==16
- printf("16-bit Build\n\n");
-#endif
-#if CHUNK==32
- printf("32-bit Build\n\n");
-#endif
-#if CHUNK==64
- printf("64-bit Build\n\n");
-#endif
+ print_system_info();
time((time_t *)&ran);
pr[0]=ran;