73 lines
1.8 KiB
C
73 lines
1.8 KiB
C
#include <string.h>
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include "../ref/csidh/csidh.h"
|
|
|
|
static void u512_print(u512 const *x)
|
|
{
|
|
for (size_t i=0; i<8; i++) {
|
|
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");
|
|
}
|
|
|
|
static void fp_print(fp const *x)
|
|
{
|
|
u512 y;
|
|
fp_dec(&y, x);
|
|
u512_print(&y);
|
|
}
|
|
|
|
static void fp_cmp(fp const *x, uint64_t const *org)
|
|
{
|
|
u512 y;
|
|
fp_dec(&y, x);
|
|
assert(memcmp(&y.c, org, sizeof(y.c)) == 0);
|
|
}
|
|
|
|
static void testLoopRef() {
|
|
for(size_t i=0; i<10; i++) {
|
|
private_key prA, prB;
|
|
public_key pkA, pkB;
|
|
public_key shA, shB;
|
|
|
|
// private key
|
|
csidh_private(&prA);
|
|
csidh_private(&prB);
|
|
|
|
// public key
|
|
csidh(&pkA, &base, &prA);
|
|
csidh(&pkB, &base, &prB);
|
|
|
|
//csidh
|
|
csidh(&shA, &pkA, &prB);
|
|
csidh(&shB, &pkB, &prA);
|
|
//int_print(prA.e);
|
|
//fp_print(&pkA.A);
|
|
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();
|
|
}
|