1*0Sstevel@tonic-gate //
2*0Sstevel@tonic-gate // gettsc.inl
3*0Sstevel@tonic-gate //
4*0Sstevel@tonic-gate // gives access to the Pentium's (secret) cycle counter
5*0Sstevel@tonic-gate //
6*0Sstevel@tonic-gate // This software was written by Leonard Janke (janke@unixg.ubc.ca)
7*0Sstevel@tonic-gate // in 1996-7 and is entered, by him, into the public domain.
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gate #if defined(__WATCOMC__)
10*0Sstevel@tonic-gate void GetTSC(unsigned long&);
11*0Sstevel@tonic-gate #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12*0Sstevel@tonic-gate #elif defined(__GNUC__)
13*0Sstevel@tonic-gate inline
GetTSC(unsigned long & tsc)14*0Sstevel@tonic-gate void GetTSC(unsigned long& tsc)
15*0Sstevel@tonic-gate {
16*0Sstevel@tonic-gate asm volatile(".byte 15, 49\n\t"
17*0Sstevel@tonic-gate : "=eax" (tsc)
18*0Sstevel@tonic-gate :
19*0Sstevel@tonic-gate : "%edx", "%eax");
20*0Sstevel@tonic-gate }
21*0Sstevel@tonic-gate #elif defined(_MSC_VER)
22*0Sstevel@tonic-gate inline
GetTSC(unsigned long & tsc)23*0Sstevel@tonic-gate void GetTSC(unsigned long& tsc)
24*0Sstevel@tonic-gate {
25*0Sstevel@tonic-gate unsigned long a;
26*0Sstevel@tonic-gate __asm _emit 0fh
27*0Sstevel@tonic-gate __asm _emit 31h
28*0Sstevel@tonic-gate __asm mov a, eax;
29*0Sstevel@tonic-gate tsc=a;
30*0Sstevel@tonic-gate }
31*0Sstevel@tonic-gate #endif
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate #include <stdio.h>
34*0Sstevel@tonic-gate #include <stdlib.h>
35*0Sstevel@tonic-gate #include <openssl/rc4.h>
36*0Sstevel@tonic-gate
main(int argc,char * argv[])37*0Sstevel@tonic-gate void main(int argc,char *argv[])
38*0Sstevel@tonic-gate {
39*0Sstevel@tonic-gate unsigned char buffer[1024];
40*0Sstevel@tonic-gate RC4_KEY ctx;
41*0Sstevel@tonic-gate unsigned long s1,s2,e1,e2;
42*0Sstevel@tonic-gate unsigned char k[16];
43*0Sstevel@tonic-gate unsigned long data[2];
44*0Sstevel@tonic-gate unsigned char iv[8];
45*0Sstevel@tonic-gate int i,num=64,numm;
46*0Sstevel@tonic-gate int j=0;
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate if (argc >= 2)
49*0Sstevel@tonic-gate num=atoi(argv[1]);
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate if (num == 0) num=256;
52*0Sstevel@tonic-gate if (num > 1024-16) num=1024-16;
53*0Sstevel@tonic-gate numm=num+8;
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate for (j=0; j<6; j++)
56*0Sstevel@tonic-gate {
57*0Sstevel@tonic-gate for (i=0; i<10; i++) /**/
58*0Sstevel@tonic-gate {
59*0Sstevel@tonic-gate RC4(&ctx,numm,buffer,buffer);
60*0Sstevel@tonic-gate GetTSC(s1);
61*0Sstevel@tonic-gate RC4(&ctx,numm,buffer,buffer);
62*0Sstevel@tonic-gate GetTSC(e1);
63*0Sstevel@tonic-gate GetTSC(s2);
64*0Sstevel@tonic-gate RC4(&ctx,num,buffer,buffer);
65*0Sstevel@tonic-gate GetTSC(e2);
66*0Sstevel@tonic-gate RC4(&ctx,num,buffer,buffer);
67*0Sstevel@tonic-gate }
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate printf("RC4 (%d bytes) %d %d (%d) - 8 bytes\n",num,
70*0Sstevel@tonic-gate e1-s1,e2-s2,(e1-s1)-(e2-s2));
71*0Sstevel@tonic-gate }
72*0Sstevel@tonic-gate }
73*0Sstevel@tonic-gate
74