2013-01-11 18:54:40 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "ed25519.h"
|
|
|
|
#include <time.h>
|
2013-01-19 18:08:14 -05:00
|
|
|
|
2013-01-11 18:54:40 -05:00
|
|
|
char msg[] = "Hello World";
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
unsigned char sk[64], vk[32], seed[32];
|
|
|
|
unsigned char *sigmsg;
|
2013-01-11 20:38:34 -05:00
|
|
|
FILE *f;
|
|
|
|
int ret;
|
2013-01-19 18:08:14 -05:00
|
|
|
clock_t start;
|
|
|
|
clock_t end;
|
|
|
|
int i;
|
|
|
|
double millis;
|
|
|
|
|
2013-01-11 18:54:40 -05:00
|
|
|
ed25519_create_seed(seed);
|
|
|
|
f = fopen("seed.txt", "wb");
|
|
|
|
fwrite(seed, 32, 1, f);
|
|
|
|
fclose(f);
|
|
|
|
ed25519_create_keypair(vk, sk, "01234567890123456789012345678901");
|
|
|
|
printf("got keypair\n");
|
|
|
|
sigmsg = malloc(64);
|
2013-01-11 20:38:34 -05:00
|
|
|
|
|
|
|
if (!sigmsg) {
|
2013-01-11 18:54:40 -05:00
|
|
|
return 1;
|
2013-01-11 20:38:34 -05:00
|
|
|
}
|
|
|
|
|
2013-01-11 18:54:40 -05:00
|
|
|
ed25519_sign(sigmsg, (unsigned char *)msg, strlen(msg), sk);
|
|
|
|
printf("got signature\n");
|
2013-01-11 20:38:34 -05:00
|
|
|
f = fopen("sig.txt", "wb");
|
|
|
|
fwrite(sigmsg, 64, 1, f);
|
|
|
|
fclose(f);
|
2013-01-11 18:54:40 -05:00
|
|
|
ret = ed25519_verify(sigmsg, "Hello World", strlen(msg), vk);
|
|
|
|
printf("verified signature\n");
|
2013-01-11 20:38:34 -05:00
|
|
|
|
|
|
|
if (ret == 0) {
|
2013-01-11 18:54:40 -05:00
|
|
|
printf("good!\n");
|
2013-01-11 20:38:34 -05:00
|
|
|
} else {
|
2013-01-11 18:54:40 -05:00
|
|
|
printf("bad\n");
|
2013-01-11 20:38:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sigmsg[44] ^= 0x01;
|
2013-01-11 18:54:40 -05:00
|
|
|
ret = ed25519_verify(sigmsg, msg, strlen(msg), vk);
|
2013-01-11 20:38:34 -05:00
|
|
|
|
|
|
|
if (ret == 0) {
|
2013-01-11 18:54:40 -05:00
|
|
|
printf("bad: failed to detect simple corruption\n");
|
2013-01-11 20:38:34 -05:00
|
|
|
} else {
|
2013-01-11 18:54:40 -05:00
|
|
|
printf("good: detected simple corruption\n");
|
2013-01-11 20:38:34 -05:00
|
|
|
}
|
2013-01-11 18:54:40 -05:00
|
|
|
|
2013-01-19 18:08:14 -05:00
|
|
|
start = clock();
|
|
|
|
for (i = 0; i < 10000; ++i) {
|
|
|
|
ed25519_sign(sigmsg, (unsigned char *)msg, strlen(msg), sk);
|
|
|
|
}
|
|
|
|
end = clock();
|
|
|
|
|
|
|
|
millis = ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000;
|
|
|
|
printf("Sign time in %fus per signature\n", millis);
|
|
|
|
|
|
|
|
start = clock();
|
|
|
|
for (i = 0; i < 10000; ++i) {
|
|
|
|
ed25519_verify(sigmsg, "Hello World", strlen(msg), vk);
|
|
|
|
}
|
|
|
|
end = clock();
|
|
|
|
|
|
|
|
millis = ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000;
|
|
|
|
printf("Verify time in %fus per signature\n", millis);
|
|
|
|
|
2013-01-11 18:54:40 -05:00
|
|
|
return 0;
|
|
|
|
}
|