Tony, all (See other mail for comments)
Below is the code that I have used for some simple and fast measurement of
the timeing.
Don't comment on the cleanness of the code, it's not to go in production!
To compile it, do (call the file time_it-small.c)
gcc -Wall -g -O -c time_it-small.c -o time_it-small.o
gcc -g -O -o time_it-small.demo time_it-small.o -lmd -lcrypto
Run it as:
./time_it-small.demo
No input is needed.
----------------------cut--------
/* time_it-small.c */
#include <stdio.h>
#include <assert.h>
#include <openssl/sha.h>
#include <openssl/dsa.h>
#include <sys/time.h>
void
do_sha1(unsigned char * in, unsigned char* out) {
SHA_CTX c;
SHA1_Init(&c);
SHA1_Update(&c, in, strlen(in));
SHA1_Final(out, &c);
}
int
do_dsa_sign(unsigned char * in, unsigned char * out, DSA* key)
{
int r, out_len;
r = DSA_sign(0, in, SHA_DIGEST_LENGTH, out, &out_len, key);
if (r == 0 ) printf("Error in signing\n");
assert (r != 0);
return out_len;
}
int
do_dsa_verify(unsigned char * in, unsigned char * sign, int sign_len, DSA*
key)
{
int r;
r = DSA_verify(0, in, SHA_DIGEST_LENGTH, sign, sign_len, key);
if (r == -1 ) printf("Error in verifing\n");
assert (r != -1);
return (r == 1);
}
int main()
{
unsigned char md[SHA_DIGEST_LENGTH];
unsigned char sign[1024+1];
DSA *key;
int counter, ret_val, len, is_ok;
struct timeval tp;
int time_base; // some huge number of seconds
int time1, time2; // in usec.
#define KEY_LEN 1024
#define USEC 1000000
gettimeofday(&tp,NULL); time_base = tp.tv_sec;
printf("Generating key & parameters: ");
gettimeofday(&tp,NULL); time1=(tp.tv_sec - time_base) * USEC + tp.tv_usec;
key = DSA_generate_parameters(KEY_LEN, NULL, 0,
&counter, NULL,
NULL, NULL);
ret_val = DSA_generate_key(key);
if (ret_val != 1 ) printf("Error in generating a key!!!!!\n");
gettimeofday(&tp,NULL); time2=(tp.tv_sec - time_base) * USEC + tp.tv_usec;
printf("%d iterations used to generate key (size=%d)\n", counter,
KEY_LEN);
printf("Time for keygen: %d Usec\n", time2-time1);
gettimeofday(&tp,NULL); time1=(tp.tv_sec - time_base) * USEC + tp.tv_usec;
do_sha1("abc", md);
gettimeofday(&tp,NULL); time2=(tp.tv_sec - time_base) * USEC + tp.tv_usec;
printf("Time for sha1: %d Usec\n", time2-time1);
gettimeofday(&tp,NULL); time1=(tp.tv_sec - time_base) * USEC + tp.tv_usec;
len = do_dsa_sign(md, sign, key);
gettimeofday(&tp,NULL); time2=(tp.tv_sec - time_base) * USEC + tp.tv_usec;
printf("Time for dsa: %d Usec\n", time2-time1);
gettimeofday(&tp,NULL); time1=(tp.tv_sec - time_base) * USEC + tp.tv_usec;
is_ok = do_dsa_verify(md, sign, len, key);
gettimeofday(&tp,NULL); time2=(tp.tv_sec - time_base) * USEC + tp.tv_usec;
printf("Time for dsa_verify: %d Usec\n", time2-time1);
if (is_ok)
{
printf("The signature is verifyed correctly!!\n");
} else {
printf("ERROR, sign not good (stange!)\n");
}
return is_ok;
}
------------------cut-again----------
--ALbert
sent mail to [EMAIL PROTECTED], to address me personal.
sent mail to [EMAIL PROTECTED], to address me for businesses