#include #include #include #include "../csidh/csidh.h" #include "../csidh/rng.h" static void u512_print(u512 const *x) { for (size_t i=0; i<8; i++) { printf("0x%016lX,", x->c[i]); } printf("\n"); } void print_bytes(uint8_t *out, size_t sz) { for(size_t i=0; ix.c[i]); } printf("\n"); } static bool fp_cmp(fp const *l, fp const *r) { u512 lu,ru; fp_dec(&lu, l); fp_dec(&ru, r); return ( sizeof(lu.c) == sizeof(ru.c) ) && (memcmp(&lu.c, &ru.c, sizeof(lu.c)) == 0); } static bool 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); return (memcmp(&shA, &shB, sizeof(shB))==0); } } static bool testImportExport() { uint8_t buf_pub[64]={0}; private_key prv1 = {0}; private_key prv2 = {0}; public_key pub1 = {0}; public_key pub2 = {0}; csidh_private(&prv1); csidh_private(&prv2); csidh(&pub1, &base, &prv1); export_public(buf_pub, &pub1); import_public(&pub2, buf_pub); return fp_cmp(&pub1.A, &pub2.A); } static void validator() { uint8_t rnd[64] = {0}; public_key pub = {0}; for (size_t i=0; i<100; i++) { randombytes(rnd, sizeof(rnd)); printf("%llu=", i); import_public(&pub, rnd); printf("\n"); } } int main() { return !( testImportExport() && testLoopRef()); }