#include <stdio.h>
#include <math.h>
#include "cpucycles.h"
#include "params.h"
#include "polx.h"
#include "polz.h"
#include "fft.h"
#include "keygen.h"
#include "sign.h"
#include <time.h>

int main(void) {
  int i,ret;
  double sign_time[21];
  double verify_time[21];
  double keygen_time = 0;
  double total_sign = 0, total_verify = 0;
  poly a1,a2;
  polx a3,a[2],b[2],s[4];
  polz u;
  const int32_t id[3] = {1,0,0};
  signature sig;
  clock_t start, end;

  start = clock();
  mpfft_init();
  keygen(&a1,&a2,&a3,a,b,&u,s);
  end = clock();
  keygen_time = (double)(end - start) / CLOCKS_PER_SEC;

  ret = 0;
  for(i=0;i<20;i++) {
    start = clock();
    ret += sign(&sig,&a1,&a2,&a3,a,b,s,id);
    end = clock();
    sign_time[i] = (double)(end - start) / CLOCKS_PER_SEC;

    start = clock();
    verify(&sig,&a1,&a2,&a3,a,b,&u);
    end = clock();
    verify_time[i] = (double)(end - start) / CLOCKS_PER_SEC;
  }

  for(i=0;i<20;i++){
    printf("sign: %2d: %f\n",i,sign_time[i]);
    printf("verify: %2d: %f\n",i,verify_time[i]);
    total_sign += sign_time[i];
    total_verify += verify_time[i];

  }
  printf("Average sign: %f\n", total_sign/20.0);
  printf("Average verify: %f\n", total_verify/20.0);
  printf("GPK and 1 member keygen: %f\n", keygen_time);
  printf("Average rejections: %f\n", ret/21.0);
  printf("Size of signature: %lu KB\n", sizeof(sig));
  printf("Size of secret key: %lu KB\n", sizeof(s[0])*4);
  printf("Size of public key: %lu KB\n", (sizeof(a1) + sizeof(a2) + sizeof(u) + sizeof(a[0])*2 + sizeof(b[0])*2));
  return 0;
}