1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/des/des3s.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,67 @@
1.4 +//
1.5 +// gettsc.inl
1.6 +//
1.7 +// gives access to the Pentium's (secret) cycle counter
1.8 +//
1.9 +// This software was written by Leonard Janke (janke@unixg.ubc.ca)
1.10 +// in 1996-7 and is entered, by him, into the public domain.
1.11 +
1.12 +#if defined(__WATCOMC__)
1.13 +void GetTSC(unsigned long&);
1.14 +#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
1.15 +#elif defined(__GNUC__)
1.16 +inline
1.17 +void GetTSC(unsigned long& tsc)
1.18 +{
1.19 + asm volatile(".byte 15, 49\n\t"
1.20 + : "=eax" (tsc)
1.21 + :
1.22 + : "%edx", "%eax");
1.23 +}
1.24 +#elif defined(_MSC_VER)
1.25 +inline
1.26 +void GetTSC(unsigned long& tsc)
1.27 +{
1.28 + unsigned long a;
1.29 + __asm _emit 0fh
1.30 + __asm _emit 31h
1.31 + __asm mov a, eax;
1.32 + tsc=a;
1.33 +}
1.34 +#endif
1.35 +
1.36 +#include <stdio.h>
1.37 +#include <stdlib.h>
1.38 +#include <openssl/des.h>
1.39 +
1.40 +void main(int argc,char *argv[])
1.41 + {
1.42 + des_key_schedule key1,key2,key3;
1.43 + unsigned long s1,s2,e1,e2;
1.44 + unsigned long data[2];
1.45 + int i,j;
1.46 +
1.47 + for (j=0; j<6; j++)
1.48 + {
1.49 + for (i=0; i<1000; i++) /**/
1.50 + {
1.51 + des_encrypt3(&data[0],key1,key2,key3);
1.52 + GetTSC(s1);
1.53 + des_encrypt3(&data[0],key1,key2,key3);
1.54 + des_encrypt3(&data[0],key1,key2,key3);
1.55 + des_encrypt3(&data[0],key1,key2,key3);
1.56 + GetTSC(e1);
1.57 + GetTSC(s2);
1.58 + des_encrypt3(&data[0],key1,key2,key3);
1.59 + des_encrypt3(&data[0],key1,key2,key3);
1.60 + des_encrypt3(&data[0],key1,key2,key3);
1.61 + des_encrypt3(&data[0],key1,key2,key3);
1.62 + GetTSC(e2);
1.63 + des_encrypt3(&data[0],key1,key2,key3);
1.64 + }
1.65 +
1.66 + printf("des %d %d (%d)\n",
1.67 + e1-s1,e2-s2,((e2-s2)-(e1-s1)));
1.68 + }
1.69 + }
1.70 +