blob: 29e140d70dc0e285583141b1f06fbe90d2c15b87 [file] [log] [blame]
/*
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.
*/
/* Time ECDSA Protocol */
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "ecdh_ZZZ.h"
#include "ecdh_support.h"
#include "randapi.h"
#include "bench.h"
#define MIN_TIME 10.0
#define MIN_ITERS 10
int ecdsa(csprng *RNG)
{
int rc;
char m[2000];
octet M = {0,sizeof(m),m};
char s0[2*EGS_ZZZ];
octet S0= {0,sizeof(s0),s0};
char w0[2*EFS_ZZZ+1];
octet W0= {0,sizeof(w0),w0};
char ds[EGS_ZZZ];
octet DS= {0,sizeof(ds),ds};
char cs[EGS_ZZZ];
octet CS= {0,sizeof(cs),cs};
int iterations;
clock_t start;
double elapsed;
printf("\nBenchmark test ECDSA - ");
printf("ZZZ Curve\n");
print_system_info();
// Generate key pair
ECP_ZZZ_KEY_PAIR_GENERATE(RNG,&S0,&W0);
rc=ECP_ZZZ_PUBLIC_KEY_VALIDATE(&W0);
if (rc!=0)
{
printf("ECP Public Key is invalid!\n");
return 0;
}
#if CURVETYPE_ZZZ != MONTGOMERY
OCT_jstring(&M,"test message");
// Sign the message
iterations=0;
start=clock();
do
{
rc=ECP_ZZZ_SP_DSA(HASH_TYPE_ZZZ,RNG,NULL,&S0,&M,&CS,&DS);
if (rc!=0)
{
printf("Error: ECP_ZZZ_SP_DSA\n");
return 1;
}
iterations++;
elapsed=(double)(clock()-start)/(double)CLOCKS_PER_SEC;
}
while (elapsed<MIN_TIME || iterations<MIN_ITERS);
elapsed=1000.0*elapsed/iterations;
printf("ECDSA Signing \t %8d iterations ",iterations);
printf(" %8.2lf ms per iteration\n",elapsed);
// Verify signature
iterations=0;
start=clock();
do
{
rc=ECP_ZZZ_VP_DSA(HASH_TYPE_ZZZ,&W0,&M,&CS,&DS);
if (rc!=0)
{
printf("Error: ECP_ZZZ_VP_DSA\n");
return 1;
}
iterations++;
elapsed=(double)(clock()-start)/(double)CLOCKS_PER_SEC;
}
while (elapsed<MIN_TIME || iterations<MIN_ITERS);
elapsed=1000.0*elapsed/iterations;
printf("ECDSA Verification \t %8d iterations ",iterations);
printf(" %8.2lf ms per iteration\n",elapsed);
#endif
return 0;
}
int main()
{
const char* seedHex = "78d0fb6705ce77dee47d03eb5b9c5d30";
char seed[16] = {0};
octet SEED = {sizeof(seed),sizeof(seed),seed};
// CSPRNG
csprng RNG;
// fake random source
OCT_fromHex(&SEED,seedHex);
/* initialise strong RNG */
CREATE_CSPRNG(&RNG,&SEED);
ecdsa(&RNG);
KILL_CSPRNG(&RNG);
}