| /* |
| 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 Bit Commitment Setup. |
| */ |
| |
| #include "bench.h" |
| #include "commitments.c" |
| |
| #define MIN_TIME 5.0 |
| #define MIN_ITERS 10 |
| |
| char *Phex = "CA5F37B7C0DDF6530B30A41116588218DE95F1F36B807FD7C28E4C467EE3F35967BC01D28B71F8A627A353675A81C86A1FF03DCECAF1686891183FA317BA34A4A1148D40A89F1F3AC0C200511C6CFE02342CD75354C25A2E069886DD4FB73BD365660D163F1282B143119AB8F375A73875EC16B634F52593B73BC6D875F2D3EF"; |
| char *Qhex = "C2FC545C1C803F6C7625FBC4ECF9355734D6B6058FD714816D3ECFB93F1F705C9CE90D4F8796A05148AB5ABC201F90889231CC6BF5F68ED15EE4D901F603930A280EEABF10C613BFCB67A816363C839EB902B02607EB48AB8325E2B72620D4D294A232803217090DFB50AF8C620D4679E77CE3053437ED518F4F68840DCF1AA3"; |
| |
| int main() |
| { |
| int iterations; |
| clock_t start; |
| double elapsed; |
| |
| char p[HFS_2048]; |
| octet P = {0, sizeof(p), p}; |
| |
| char q[HFS_2048]; |
| octet Q = {0, sizeof(q), q}; |
| |
| BIG_1024_58 sP[HFLEN_2048]; |
| BIG_1024_58 sp[HFLEN_2048]; |
| BIG_1024_58 x[FFLEN_2048]; |
| |
| COMMITMENTS_BC_priv_modulus m; |
| |
| // Load values |
| OCT_fromHex(&P, Phex); |
| OCT_fromHex(&Q, Qhex); |
| |
| FF_2048_fromOctet(sP, &P, HFLEN_2048); |
| FF_2048_copy(sp, sP, HFLEN_2048); |
| FF_2048_shr(sp, HFLEN_2048); |
| |
| // Deterministic RNG for testing |
| char seed[32] = {0}; |
| csprng RNG; |
| RAND_seed(&RNG, 32, seed); |
| |
| print_system_info(); |
| |
| printf("Timing info\n"); |
| printf("===========\n"); |
| |
| iterations = 0; |
| start = clock(); |
| do |
| { |
| is_safe_prime(sp, sP, &RNG, HFLEN_2048); |
| iterations++; |
| elapsed = (clock() - start) / (double)CLOCKS_PER_SEC; |
| } |
| while (elapsed < MIN_TIME || iterations < MIN_ITERS); |
| |
| elapsed = MILLISECOND * elapsed / iterations; |
| printf("\tis_safe_prime\t\t\t\t%8d iterations\t", iterations); |
| printf("%8.2lf ms per iteration\n", elapsed); |
| |
| iterations = 0; |
| start = clock(); |
| do |
| { |
| bc_generator(&RNG, x, sP, HFLEN_2048); |
| iterations++; |
| elapsed = (clock() - start) / (double)CLOCKS_PER_SEC; |
| } |
| while (elapsed < MIN_TIME || iterations < MIN_ITERS); |
| |
| elapsed = MILLISECOND * elapsed / iterations; |
| printf("\tbc_generator\t\t\t\t%8d iterations\t", iterations); |
| printf("%8.2lf ms per iteration\n", elapsed); |
| |
| iterations = 0; |
| start = clock(); |
| do |
| { |
| COMMITMENTS_BC_setup(&RNG, &m, &P, &Q, NULL, NULL); |
| iterations++; |
| elapsed = (clock() - start) / (double)CLOCKS_PER_SEC; |
| } |
| while (elapsed < MIN_TIME || iterations < MIN_ITERS); |
| |
| elapsed = MILLISECOND * elapsed / iterations; |
| printf("\tCOMMITMENTS_BC_setup\t\t\t%8d iterations\t", iterations); |
| printf("%8.2lf ms per iteration\n", elapsed); |
| |
| iterations = 0; |
| start = clock(); |
| do |
| { |
| COMMITMENTS_BC_kill_priv_modulus(&m); |
| iterations++; |
| elapsed = (clock() - start) / (double)CLOCKS_PER_SEC; |
| } |
| while (elapsed < MIN_TIME || iterations < MIN_ITERS); |
| |
| elapsed = MICROSECOND * elapsed / iterations; |
| printf("\tCOMMITMENTS_BC_kill_priv_modulus\t%8d iterations\t", iterations); |
| printf("%8.2lf us per iteration\n", elapsed); |
| |
| exit(EXIT_SUCCESS); |
| } |