ed25519/src/test.c

49 lines
1.1 KiB
C
Raw Normal View History

2013-01-11 18:54:40 -05:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "ed25519.h"
#include <time.h>
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-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
return 0;
}