#include #include #include #include #include #include #include #include #include #include #include "Hacl_Curve25519_64.h" #include "EverCrypt_AutoConfig2.h" #include "test_helpers.h" #include "curve25519_vectors.h" typedef __attribute__((aligned(32))) uint8_t X25519_KEY[32]; #define ROUNDS 100000 #define SIZE 1 bool print_result(int in_len, uint8_t* comp, uint8_t* exp) { return compare_and_print(in_len, comp, exp); } bool print_test(uint8_t* scalar, uint8_t* pub, uint8_t* exp){ uint8_t comp[32] = {0}; Hacl_Curve25519_64_ecdh(comp,scalar,pub); printf("Curve25519 (Vale 64-bit) Result:\n"); bool ok = print_result(32,comp,exp); return ok; } int main() { EverCrypt_AutoConfig2_init(); if (!(EverCrypt_AutoConfig2_has_adx () && EverCrypt_AutoConfig2_has_bmi2())) return EXIT_SUCCESS; bool ok = true; for (int i = 0; i < sizeof(vectors)/sizeof(curve25519_test_vector); ++i) { ok &= print_test(vectors[i].scalar,vectors[i].public,vectors[i].secret); } X25519_KEY pub, priv, key; uint64_t res = 0; cycles a,b; clock_t t1,t2; memset(pub,'P',32); memset(priv,'S',32); for (int j = 0; j < ROUNDS; j++) { Hacl_Curve25519_64_ecdh(pub,priv,pub); } t1 = clock(); a = cpucycles_begin(); for (int j = 0; j < ROUNDS; j++) { Hacl_Curve25519_64_ecdh(key,priv,pub); res ^= key[0] ^ key[15]; } b = cpucycles_end(); t2 = clock(); clock_t tdiff1 = t2 - t1; cycles cdiff1 = b - a; uint64_t count = ROUNDS * SIZE; double time = (((double)tdiff1) / CLOCKS_PER_SEC); double nsigs = ((double)ROUNDS) / time; printf("Curve25519 (Vale 64-bit) PERF:\n"); print_time(count,tdiff1,cdiff1); printf("smult %8.2f mul/s\n",nsigs); if (ok) return EXIT_SUCCESS; else return EXIT_FAILURE; }