1 //g++ test_sub_perm.cpp -o test_sub_perm -O3 -fpermissive
4 // ./test_sub_perm sizebuf512 nb1000
15 typedef unsigned char uchar;
22 double time_encrypt=0;
23 double time_decrypt=0;
27 struct timeval tstart;
28 gettimeofday(&tstart,0);
29 return( (double) (tstart.tv_sec + tstart.tv_usec*1e-6) );
32 double TimeStop(double t)
36 gettimeofday(&tend,0);
37 t = (double) (tend.tv_sec + tend.tv_usec*1e-6) - t;
44 void rc4key(uchar *key, uchar *sc, int size_DK) {
46 for(int i=0;i<256;i++) {
52 for(int i0=0; i0<256; i0++) {
53 j0 = (j0 + sc[i0] + key[i0%size_DK] )&0xFF;
61 int main (int argc, char** argv)
63 /* Set up the key and iv. Do I need to say to not hard code these in a
64 * real application? :-)
71 for(int i=1; i<argc; i++){
72 if(strncmp(argv[i],"nb",2)==0) nb_test = atoi(&(argv[i][2])); //nb of test
73 if(strncmp(argv[i],"sizebuf",7)==0) size_buf = atoi(&(argv[i][7])); //SIZE of the buffer
80 for(int i=0;i<size;i++) {
97 buffer=malloc(imsize*sizeof(uchar));
98 for(int i=0;i<imsize;i++) {
104 int oneD=width*height;
105 uchar *plaintext = malloc(imsize+1000); //add that for cbc
106 for(int i=0;i<oneD;i++) {
107 plaintext[i]=buffer[i];
112 uchar *ciphertext = malloc(imsize+1000); //add that for cbc
114 /* Buffer for the decrypted text */
115 uchar *decryptedtext = malloc(imsize+1000); //add that for cbc
117 int decryptedtext_len, ciphertext_len;
119 double t=TimeStart();
120 for(int i=0;i<nb_test;i++)
123 for(int j=0;j<imsize;j++)
124 plaintext[j]=Sbox1[plaintext[j]];
127 double time=TimeStop(t);
128 cout<<"Throughput Sbox \t";
129 cout<<(double)imsize*nb_test/time<<"\t";