Adds hardcoded test

This commit is contained in:
Henry Case 2019-01-17 10:28:56 +00:00
parent b6bb3a63d0
commit 5c8c82e58e

View File

@ -5,8 +5,15 @@
static void u512_print(u512 const *x) static void u512_print(u512 const *x)
{ {
for (size_t i = 63; i < 64; --i) for (size_t i=0; i<8; i++) {
printf("%02hhx", i[(unsigned char *) x->c]); printf("0x%016lX,", x->c[i]);
}
printf("\n");
}
static void int_print(const int8_t v[37]) {
for (size_t i = 0; i<37; i++)
printf("0x%x,", (unsigned char)v[i]);
printf("\n"); printf("\n");
} }
@ -17,14 +24,15 @@ static void fp_print(fp const *x)
u512_print(&y); u512_print(&y);
} }
static void int_print(const int8_t v[37]) { static void fp_cmp(fp const *x, uint64_t const *org)
for (size_t i = 0; i<37; i++) {
printf("%02hhx", v[i]); u512 y;
printf("\n"); fp_dec(&y, x);
assert(memcmp(&y.c, org, sizeof(y.c)) == 0);
} }
int main() { static void testLoopRef() {
for(size_t i=0; i<1000; i++) { for(size_t i=0; i<10; i++) {
private_key prA, prB; private_key prA, prB;
public_key pkA, pkB; public_key pkA, pkB;
public_key shA, shB; public_key shA, shB;
@ -40,8 +48,25 @@ int main() {
//csidh //csidh
csidh(&shA, &pkA, &prB); csidh(&shA, &pkA, &prB);
csidh(&shB, &pkB, &prA); csidh(&shB, &pkB, &prA);
int_print(prA.e); //int_print(prA.e);
fp_print(&pkA.A); //fp_print(&pkA.A);
assert(memcmp(&shA, &shB, sizeof(shB))==0); assert(memcmp(&shA, &shB, sizeof(shB))==0);
} }
} }
static void testHardcoded() {
private_key prv;
public_key pub;
uint8_t prv_bytes[] = {0xdb,0x54,0xe4,0xd4,0xd0,0xbd,0xee,0xcb,0xf4,0xd0,0xc2,0xbc,0x52,0x44,0x11,0xee,0xe1,0x14,0xd2,0x24,0xe5,0x0,0xcc,0xf5,0xc0,0xe1,0x1e,0xb3,0x43,0x52,0x45,0xbe,0xfb,0x54,0xc0,0x55,0xb2};
uint64_t pub_bytes[] = {0x6BCAAD7EFD426976,0x743D780A06D2CDC5,0x841A2D76984849F7,0x1523EB45B3B78D5F,0xCF7A093C773EDF8D,0xFAB0FF04A7B4A54D,0x05DE322C864069D2,0x0C55DC69711DF47A};
memcpy(prv.e, prv_bytes, sizeof(prv.e));
// generate public key from private and compare to reference value
csidh(&pub, &base, &prv);
fp_cmp(&pub.A, pub_bytes);
}
int main() {
testHardcoded();
testLoopRef();
}