From e6d4387fd5f7b3044c2ad17ef821f644235b042c Mon Sep 17 00:00:00 2001 From: couturie <you@example.com> Date: Sun, 24 Feb 2019 15:05:43 +0100 Subject: [PATCH] new --- OneRoundIoT/NEW/scprng.cpp | 59 ++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/OneRoundIoT/NEW/scprng.cpp b/OneRoundIoT/NEW/scprng.cpp index 83765d1..e50118d 100644 --- a/OneRoundIoT/NEW/scprng.cpp +++ b/OneRoundIoT/NEW/scprng.cpp @@ -2,7 +2,7 @@ #include <stdlib.h> #include <stdint.h> #include <sys/time.h> - +#include<string.h> typedef unsigned char uchar; @@ -237,19 +237,34 @@ void scprng(uint64_t *plain, uint64_t* cipher, int bufsize, int nb_bloc, uint64_ } -int main() { +int main(int argc, char **argv) { printf("%d %d \n",sizeof(__uint64_t),sizeof(ulong)); + uint nb_test=1; + int width; int height; uchar *data_R, *data_G, *data_B; int imsize; uchar *buffer; - int size_buf=512; + int size_buf=128; + + int lena=0; + int h=128; + for(int i=1; i<argc; i++){ + if(strncmp(argv[i],"nb",2)==0) nb_test = atoi(&(argv[i][2])); //nb of test + if(strncmp(argv[i],"h",1)==0) h = atoi(&(argv[i][1])); //size of block + if(strncmp(argv[i],"sizebuf",7)==0) size_buf = atoi(&(argv[i][7])); //SIZE of the buffer + if(strncmp(argv[i],"lena",4)==0) lena = atoi(&(argv[i][4])); //Use Lena or buffer + } + + + + + - int lena=1; if(lena==1) { load_RGB_pixmap("lena.ppm", &width, &height, &data_R, &data_G, &data_B); @@ -304,24 +319,18 @@ int main() { rc4key(DK, Sbox1, 8); rc4key(&DK[8], Sbox2, 8); - const int bufsize=128; - int Pbox[bufsize]; - int Pbox2[bufsize]; - rc4keyperm(&DK[16], bufsize, 1, Pbox, 16); - rc4keyperm(&DK[32], bufsize, 1, Pbox2, 16); + int Pbox[h]; + int Pbox2[h]; + rc4keyperm(&DK[16], h, 1, Pbox, 16); + rc4keyperm(&DK[32], h, 1, Pbox2, 16); // uint64_t plain[bufsize]; // uint64_t cipher[bufsize]; - ulong2 xoro[bufsize]; - - ranctx ctx[bufsize]; - sfcctx sfcd[bufsize]; - - uint64_t Val[bufsize]; - for(int i=0;i<bufsize;i++) { + uint64_t Val[h]; + for(int i=0;i<h;i++) { Val[Pbox[i]]=splitmix64_stateless(i+DK[i&63]); } @@ -330,19 +339,19 @@ int main() { - uint nb_test=100; + double t=TimeStart(); - int nb_bloc=imsize/(bufsize*8); //8 because we use 64bits numbers + int nb_bloc=imsize/(h*8); //8 because we use 64bits numbers for(uint iter=0;iter<nb_test;iter++) { - scprng(SEQ, SEQ2, bufsize, nb_bloc, Val,Sbox1, Sbox2, Pbox, Pbox2, DK, delta); + scprng(SEQ, SEQ2, h, nb_bloc, Val,Sbox1, Sbox2, Pbox, Pbox2, DK, delta); } double time=TimeStop(t); - printf("time %e\n",nb_test*nb_bloc*bufsize*8/time); + printf("time %e\n",nb_test*nb_bloc*h*8/time); if(lena) { for(int i=0;i<oneD;i++) { @@ -358,20 +367,20 @@ int main() { rc4key(DK, Sbox1, 8); rc4key(&DK[8], Sbox2, 8); - rc4keyperm(&DK[16], bufsize, 1, Pbox, 16); - rc4keyperm(&DK[32], bufsize, 1, Pbox2, 16); - for(int i=0;i<bufsize;i++) { + rc4keyperm(&DK[16], h, 1, Pbox, 16); + rc4keyperm(&DK[32], h, 1, Pbox2, 16); + for(int i=0;i<h;i++) { Val[Pbox[i]]=splitmix64_stateless(i+DK[i&63]); } t=TimeStart(); for(uint iter=0;iter<nb_test;iter++) { - scprng(SEQ2, SEQ, bufsize, nb_bloc, Val,Sbox1, Sbox2, Pbox, Pbox2, DK, delta); + scprng(SEQ2, SEQ, h, nb_bloc, Val,Sbox1, Sbox2, Pbox, Pbox2, DK, delta); } time=TimeStop(t); - printf("time %e\n",nb_test*nb_bloc*bufsize*8/time); + printf("time %e\n",nb_test*nb_bloc*h*8/time); if(lena) { for(int i=0;i<oneD;i++) { -- 2.39.5