xref: /onnv-gate/usr/src/common/openssl/crypto/md4/md4s.cpp (revision 0:68f95e015346)
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/md4.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate extern "C" {
38*0Sstevel@tonic-gate void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
39*0Sstevel@tonic-gate }
40*0Sstevel@tonic-gate 
main(int argc,char * argv[])41*0Sstevel@tonic-gate void main(int argc,char *argv[])
42*0Sstevel@tonic-gate 	{
43*0Sstevel@tonic-gate 	unsigned char buffer[64*256];
44*0Sstevel@tonic-gate 	MD4_CTX ctx;
45*0Sstevel@tonic-gate 	unsigned long s1,s2,e1,e2;
46*0Sstevel@tonic-gate 	unsigned char k[16];
47*0Sstevel@tonic-gate 	unsigned long data[2];
48*0Sstevel@tonic-gate 	unsigned char iv[8];
49*0Sstevel@tonic-gate 	int i,num=0,numm;
50*0Sstevel@tonic-gate 	int j=0;
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate 	if (argc >= 2)
53*0Sstevel@tonic-gate 		num=atoi(argv[1]);
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate 	if (num == 0) num=16;
56*0Sstevel@tonic-gate 	if (num > 250) num=16;
57*0Sstevel@tonic-gate 	numm=num+2;
58*0Sstevel@tonic-gate 	num*=64;
59*0Sstevel@tonic-gate 	numm*=64;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 	for (j=0; j<6; j++)
62*0Sstevel@tonic-gate 		{
63*0Sstevel@tonic-gate 		for (i=0; i<10; i++) /**/
64*0Sstevel@tonic-gate 			{
65*0Sstevel@tonic-gate 			md4_block_x86(&ctx,buffer,numm);
66*0Sstevel@tonic-gate 			GetTSC(s1);
67*0Sstevel@tonic-gate 			md4_block_x86(&ctx,buffer,numm);
68*0Sstevel@tonic-gate 			GetTSC(e1);
69*0Sstevel@tonic-gate 			GetTSC(s2);
70*0Sstevel@tonic-gate 			md4_block_x86(&ctx,buffer,num);
71*0Sstevel@tonic-gate 			GetTSC(e2);
72*0Sstevel@tonic-gate 			md4_block_x86(&ctx,buffer,num);
73*0Sstevel@tonic-gate 			}
74*0Sstevel@tonic-gate 		printf("md4 (%d bytes) %d %d (%.2f)\n",num,
75*0Sstevel@tonic-gate 			e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
76*0Sstevel@tonic-gate 		}
77*0Sstevel@tonic-gate 	}
78*0Sstevel@tonic-gate 
79