/******************************************************************************************** * Author: Nam Nguyen * Partner: Burt Gordon * With help from Chris Conger and Matt Murphy on cryptology theory and psuedocode. * * Spring 2003 * * Written and tested with resources made available by the * High-performance Computing and Simulation (HCS) Laboratory, * University of Florida * * ##################### DESCRIPTION and EXECUTION INFO ################################# * Differential Simulator * * This program simulates a simple differential analysis of made-up * S-Boxes. Use the definitions noted below to change the different * parameters of the S-Boxes, such as the number of input/output bits, * number of S-Boxes, etc. This should drastically affect the memory * performance of this program. Larger input and output bit #s will produce * exponentially larger tables (memory consumption) and execution time. * * The number of input bits should be any power of two and the number of * output bits can be anything. If you choose large numbers of input/output * bits, try using only 2 or 1 S-Boxes. * * Make sure that you specify -fthreads when you compile this code. Otherwise * errors are reported for the declaration of global variables. * * This code was written for and is known to with the Compaq (now HP) UPC * compiler V2.0 and V2.1. * ***************************************************************************************/ #include #include #include #include #ifndef MIN #define MIN(x,y) ((x)<(y)?(x):(y)) #endif #define NUMSBOXES 4 /* Number of S-Boxes */ #define NUMSINPUTS 8 /* Number of input bits to each S-Box */ #define NUMSOUTPUTS 8 /* Number of output bits from each S-Box */ char logfile[] = "parlog"; /* Name of file results are written to */ #define inputSq (1<> 1) & 2147483647); /* right shift 1, mask */ temp = (feedback << 31)|Itemp; /* add feedback as MSB */ bit = (1 & temp)?1:0; /* compute next bit of string A */ sElementTemp |= (bit<<(NUMSOUTPUTS-j-1)); } sBox[r][i]=sElementTemp; } } } /*=========================Cryptanalytic Functions=========================*/ ELEMENT SIO(INDEX k, COLUMN col, shared [BLKSIZE] UINT S[NUMSBOXES][inputSq]) { ELEMENT value; UINT r,c; c = (col & centerMask) >> centerShift; r = ((col & MSBmask) >> MSBshift) | (col & LSBmask); value = S[k][rowLength*r + c]; return value; } void findDC(INDEX k, shared [BLKSIZE] ELEMENT DT[NUMSBOXES][inputSq][outputSq]) { ELEMENT curV,curL=0; INDEX i,j; for(i=0;icurL)&(curV!=inputSq)) { curL = curV; dex[k] = i; dey[k] = j; } } } prob[k]=((double) curL)/inputSq; } int main(void) { int cnt, SBox_index, DPS_index, DTS_index; INDEX i,j,k,r,x,dx,dy; unsigned long int sboxMem; double memory, probability = 1.0; long time0, time1, time2, time3, time4, totaltime; long count = 0; struct timeval currentTime; ELEMENT *DTS_ptr, *DPS_ptr, *SBox_ptr; ELEMENT **DTS_pptr; ELEMENT **DPS_pptr; FILE *fid; //fid = fopen(logfile, "w"); /* THIS PORTION IS FOR THE LOG FILE ONLY AND CAN BE OMITTED sboxMem = 4*inputSq*(inputSq+outputSq) + 4*inputSq + 16; memory = 4*NUMSBOXES*inputSq*(inputSq+outputSq+1)+(4*7)+(16*NUMSBOXES); fprintf(fid,"Simulated Differential Analysis of Generic S-Boxes\n\n"); fprintf(fid,"# of S-Boxes................. %i\n\n",NUMSBOXES); fprintf(fid,"# of input bits per S-Box: %i\n",NUMSINPUTS); fprintf(fid,"# of output bits per S-Box: %i\n",NUMSOUTPUTS); fprintf(fid,"Total number of input bits: %i\n",TOTALINPUT); fprintf(fid,"Total number of output bits: %i\n\n\n",TOTALOUTPUT); fprintf(fid,"Size of 1 S-Box: %i Bytes\n",inputSq*4); fprintf(fid,"Memory to store all S-Boxes:%i Bytes\n\n",NUMSBOXES*inputSq*4); fprintf(fid,"Including all tables...\n"); fprintf(fid,"Memory per S-Box: %i Bytes\n",sboxMem); fprintf(fid,"Memory Used/Required > .3f MB\n\n",memory/1048576);*/ /*********** THIS BEGINS THE MAIN PORTION OF THE PROGRAM **************************** */ //printf("Thread %u running...\n-------------------\n\n", MYTHREAD); gettimeofday(¤tTime, NULL); time0 = currentTime.tv_sec*1000000 + currentTime.tv_usec; //generation of S boxes is sequential if(MYTHREAD == 0) create_sBoxes(); // generate arbitrary S-Boxes gettimeofday(¤tTime, NULL); time1 = currentTime.tv_sec*1000000 + currentTime.tv_usec; /* Fill in the Difference Pair Tables */ upc_barrier 1; for(r=0; r BLKSIZE) // DPS_ptr = (ELEMENT *) (&DPS[r][dx][k]); // naive, temporary work-around: shared [BLKSIZE] ELEMENT *DPS_ptr = (&DPS[r][dx][k]); for(i = 0; i < BLKSIZE; i++) { count++; if(DPS_ptr[i]==dy) cnt++; } } DTS_ptr[dy] = cnt; #else /* fix from Burt, 1/9/2004 */ cnt=0; for(k=0; k