/* This program is used to measure the encryption speed of stream cipher HC-128 for a 128-bit key and a 128-bit IV HC-128 is a final portfolio cipher of eSTREAM, of the European Network of Excellence for Cryptology (ECRYPT, 2004-2008). The docuement of HC-128 is available at: 1) Hongjun Wu. ``The Stream Cipher HC-128.'' New Stream Cipher Designs -- The eSTREAM Finalists, LNCS 4986, pp. 39-47, Springer-Verlag, 2008. 2) eSTREAM website: http://www.ecrypt.eu.org/stream/hcp3.html ----------------------------------- The encryption speed is measured by repeatedly encrypting a 64-byte buffer. ----------------------------------- Written by: Hongjun Wu Last Modified: December 15, 2009 */ #include #include #include "hc128_opt32.h" //#include "hc128_ref.h" int main() { unsigned char key[16],iv[16]; unsigned char message[1024],ciphertext[1024]; unsigned long long msglength; HC128_State state; unsigned long i; clock_t start, finish; double duration, speed; /*set the value of the key and iv*/ for (i = 0; i < 16; i++) {key[i] = 0; iv[i] = 0;} /*key[0] = 0x55;*/ /*initialize the message*/ for (i = 0; i < 1024; i++) message[i] = 0; /*key and iv setup*/ Initialization(&state,key,iv); /*mesure the encryption speed by encrypting a 64-byte message repeatedly for 2*0x4000000 times*/ msglength = 64; start = clock(); for (i = 0; i < 0x4000000; i++) { EncryptMessage(&state,message,ciphertext,msglength); EncryptMessage(&state,ciphertext,message,msglength); } finish = clock(); /*compute the speed*/ duration = ((double)(finish - start))/ CLOCKS_PER_SEC; speed = duration*2.53*1000*1000*1000/(((double)i)*2*msglength); /* 2.53*1000*1000*1000 indicates a 2.53GHz CPU */ /*print out the speed*/ printf("\n\nThe encryption takes %4.4f seconds.\nThe encryption speed is %3.4f cycles/byte \n",duration,speed); /*print out part of the contents of message It is to prevent the over-optimization of compiler so as to ensure that the above cipher computation must be computed*/ printf("\nPart of the message after being repeatedly encrypted: \n"); for (i = 0; i < 16; i++) printf("%x%x",message[i] >> 4, message[i] & 0xf); printf("\n"); return (0); }