Пример #1
0
void test_des_encrypt()
{
  int n;
  int nt=10000;
  int i;
  byte key[8]={0x5b,0x5a,0x57,0x67,0x6a,0x56,0x67,0x6e};
  byte inex[8]={0x67,0x5a,0x69,0x67,0x5e,0x5a,0x6b,0x5a};
  byte outex[8]={0x97,0x4a,0xff,0xbf,0x86,0x02,0x2d,0x1f}; 

  byte in[8];
  byte out[8];

  //  testlagrangeRoy();
    
  for(i=0;i<8;i++) in[i]=inex[i];

  int dt,base=0;

  printf("Without countermeasure, plain: ");
  dt=run_des(in,out,key,nt);
  base=dt;
  report_time(dt,nt,base,0);
  check_ciphertext(out,outex,8);

  printf("Without countermeasure, Carlet: ");
  runalgo(des_encrypt_carlet,in,out,key,outex,8,nt,base);

  for(n=3;n<=13;n+=2)
  {
    printf("n=%d\n",n);
    printf("  With Carlet (RV13) countermeasure: ");
    init_randcount();
    dt=run_des_share(in,out,key,n,&polyRoy_share,nt); // &polygen_share
    report_time(dt,nt,base,get_randcount());
    check_ciphertext(out,outex,8);

    printf("  With Carlet (CRV14) countermeasure: ");
    init_randcount();
    dt=run_des_share(in,out,key,n,&polyCRV_share,nt);
    report_time(dt,nt,base,get_randcount());
    check_ciphertext(out,outex,8);	
	
    printf("  With randomized table: ");
    init_randcount();
    dt=run_des_share(in,out,key,n,&sbox_htable_word,nt);
    report_time(dt,nt,base,get_randcount());
    check_ciphertext(out,outex,8);
  }
}
Пример #2
0
int main()
{
  int n;
  int nt=100;
  int i;
  byte keyex[16]={0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c};

  byte inex[16]={0x32,0x43,0xf6,0xa8,0x88,0x5a,0x30,0x8d,0x31,0x31,0x98,0xa2,0xe0,0x37,0x07,0x34};

  byte outex[16]={0x39,0x25,0x84,0x1d,0x02,0xdc,0x09,0xfb,0xdc,0x11,0x85,0x97,0x19,0x6a,0x0b,0x32};

  byte in[16],out[16];
  byte key[16];

  printMes("in",inex);
  printMes("key",keyex);

  for(i=0;i<16;i++) key[i]=keyex[i];
  for(i=0;i<16;i++) in[i]=inex[i];

  double dt,base;

  printf("Without countermeasure, plain: ");
  dt=run_aes(in,out,key,nt);
  base=dt;
  check_ciphertext(out,outex,16);
  report_time(dt,nt,base);

  printf("Without countermeasure, RP: ");
  runalgo(&aes_rp,in,out,key,outex,16,nt,base);

  for(n=3;n<=9;n+=2)
  {
    printf("n=%d\n",n);
    printf("  With RP countermeasure: ");
    dt=run_aes_share(in,out,key,n,&subbyte_rp_share,nt);
    report_time(dt,nt,base);
    check_ciphertext(out,outex,16);

    printf("  With randomized table : ");
    dt=run_aes_share(in,out,key,n,&subbyte_htable_word,nt);
    report_time(dt,nt,base);
    check_ciphertext(out,outex,16);
  }
}
Пример #3
0
int runalgo(void (*algo)(byte *,byte *,byte *),byte *in,byte *out,byte *key,byte *outex,int nbyte,int nt,int base)
{
  int i;
  clock_t start,end;
  int dt;
  start=clock();
  for(i=0;i<nt;i++)
    algo(in,out,key);
  end=clock();
  dt=(int) (end-start);
  if (base==0) base=dt;
  report_time(dt,nt,base);
  check_ciphertext(out,outex,nbyte);
  return dt;
}