Commit de994f22 authored by Jan Včelák's avatar Jan Včelák 🚀
Browse files

wip: benchmarking

parent 0dde2956
CFLAGS=-std=gnu99 -Wall -g -O2 -Icrypto
CFLAGS=-std=gnu99 -Wall -g -O3 -Icrypto
openssl_FLAGS=$(shell pkg-config --cflags --libs libcrypto)
......
......@@ -386,6 +386,62 @@ static void nsec5_ecc_proof2hash(const uint8_t *proof, size_t proof_size,
memcpy(hash, proof + 1, NSEC5_ECC_HASH_SIZE);
}
static void bench_sign(const EC_KEY *privkey, const uint8_t *data, size_t size)
{
uint8_t proof[NSEC5_ECC_PROOF_SIZE] = { 0 };
nsec5_ecc_sign(privkey, data, size, proof, sizeof(proof));
/*
int len = 3 + size + NSEC5_ECC_PROOF_SIZE;
assert(len <= UINT8_MAX);
uint8_t buffer[512] = { 0 };
uint8_t *pos = buffer;
*pos = len;
pos += 1;
*pos = size;
pos += 1;
memcpy(pos, data, size);
pos += size;
*pos = sizeof(proof);
pos += 1;
memcpy(pos, proof, sizeof(proof));
pos += sizeof(proof);
assert(buffer + len == pos);
fwrite(buffer, len, 1, stdout);
*/
}
/*
static void bench_verify(const EC_KEY *pubkey, const uint8_t *bin, size_t size)
{
const uint8_t *ptr = bin;
size_t data_len = *ptr;
ptr += 1;
const uint8_t *data = ptr;
ptr += data_len;
size_t proof_len = *ptr;
ptr += 1;
assert(proof_len == 81);
const uint8_t *proof = ptr;
ptr += proof_len;
assert(bin + size == ptr);
bool ok = nsec5_ecc_verify(pubkey, data, data_len, proof, proof_len);
assert(ok);
}
*/
int main(int argc, char *argv[])
{
if (argc != 3) {
......@@ -399,28 +455,56 @@ int main(int argc, char *argv[])
return 1;
}
const uint8_t *data = (uint8_t *)argv[2];
size_t data_len = strlen(argv[2]);
// const uint8_t *data = (uint8_t *)argv[2];
// size_t data_len = strlen(argv[2]);
uint8_t proof[NSEC5_ECC_PROOF_SIZE] = { 0 };
nsec5_ecc_sign(privkey, data, data_len, proof, sizeof(proof));
uint8_t hash[NSEC5_ECC_HASH_SIZE] = { 0 };
nsec5_ecc_proof2hash(proof, sizeof(proof), hash, sizeof(hash));
printf("proof (pi):\n");
hex_dump(proof, sizeof(proof));
printf("hash (beta):\n");
hex_dump(hash, sizeof(hash));
FILE *f = fopen("/usr/share/dict/words", "r");
char *buf = NULL;
size_t buf_len = 0;
ssize_t r = 0;
while ((r = getline(&buf, &buf_len, f)) != -1) {
bench_sign(privkey, (uint8_t *)buf, r - 1);
}
free(buf);
// FILE *f = fopen("hashes.bin", "rb");
// uint8_t buffer[512] = { 0 };
// for (;;) {
// int len = fgetc(f);
// if (len == EOF) {
// break;
// }
//
// assert(len > 0);
// len -= 1;
//
// int read = fread(buffer, 1, len, f);
// assert(read == len);
//
// bench_verify(privkey, buffer, read);
// }
//
//// bench_sign(privkey, data, data_len);
// uint8_t proof[NSEC5_ECC_PROOF_SIZE] = { 0 };
// nsec5_ecc_sign(privkey, data, data_len, proof, sizeof(proof));
//
// uint8_t hash[NSEC5_ECC_HASH_SIZE] = { 0 };
// nsec5_ecc_proof2hash(proof, sizeof(proof), hash, sizeof(hash));
//
// printf("proof (pi):\n");
// hex_dump(proof, sizeof(proof));
// printf("hash (beta):\n");
// hex_dump(hash, sizeof(hash));
//
// EC_KEY *pubkey = key_priv2pub(privkey);
// assert(pubkey);
//
// bool ok = nsec5_ecc_verify(pubkey, data, data_len, proof, sizeof(proof));
// printf("valid:\n%s\n", ok ? "true" : "false");
EC_KEY *pubkey = key_priv2pub(privkey);
assert(pubkey);
EC_KEY_free(privkey);
bool ok = nsec5_ecc_verify(pubkey, data, data_len, proof, sizeof(proof));
printf("valid:\n%s\n", ok ? "true" : "false");
EC_KEY_free(pubkey);
// EC_KEY_free(pubkey);
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment