dess.cpp revision 55714
1305549Sjhb// 2218792Snp// gettsc.inl 3218792Snp// 4218792Snp// gives access to the Pentium's (secret) cycle counter 5218792Snp// 6218792Snp// This software was written by Leonard Janke (janke@unixg.ubc.ca) 7218792Snp// in 1996-7 and is entered, by him, into the public domain. 8218792Snp 9218792Snp#if defined(__WATCOMC__) 10218792Snpvoid GetTSC(unsigned long&); 11218792Snp#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; 12218792Snp#elif defined(__GNUC__) 13218792Snpinline 14218792Snpvoid GetTSC(unsigned long& tsc) 15218792Snp{ 16218792Snp asm volatile(".byte 15, 49\n\t" 17218792Snp : "=eax" (tsc) 18218792Snp : 19218792Snp : "%edx", "%eax"); 20218792Snp} 21218792Snp#elif defined(_MSC_VER) 22218792Snpinline 23218792Snpvoid GetTSC(unsigned long& tsc) 24218792Snp{ 25218792Snp unsigned long a; 26218792Snp __asm _emit 0fh 27218792Snp __asm _emit 31h 28218792Snp __asm mov a, eax; 29218792Snp tsc=a; 30218792Snp} 31218792Snp#endif 32218792Snp 33218792Snp#include <stdio.h> 34318204Sgjb#include <stdlib.h> 35305549Sjhb#include <openssl/des.h> 36218792Snp 37218792Snpvoid main(int argc,char *argv[]) 38305549Sjhb { 39310637Sjhb des_key_schedule key; 40218792Snp unsigned long s1,s2,e1,e2; 41218792Snp unsigned long data[2]; 42218792Snp int i,j; 43218792Snp 44218792Snp for (j=0; j<6; j++) 45218792Snp { 46305549Sjhb for (i=0; i<1000; i++) /**/ 47218792Snp { 48218792Snp des_encrypt(&data[0],key,1); 49218792Snp GetTSC(s1); 50305549Sjhb des_encrypt(&data[0],key,1); 51218792Snp des_encrypt(&data[0],key,1); 52218792Snp des_encrypt(&data[0],key,1); 53305549Sjhb GetTSC(e1); 54218792Snp GetTSC(s2); 55218792Snp des_encrypt(&data[0],key,1); 56218792Snp des_encrypt(&data[0],key,1); 57218792Snp des_encrypt(&data[0],key,1); 58305549Sjhb des_encrypt(&data[0],key,1); 59310637Sjhb GetTSC(e2); 60310637Sjhb des_encrypt(&data[0],key,1); 61232157Sgjb } 62218792Snp 63218792Snp printf("des %d %d (%d)\n", 64218792Snp e1-s1,e2-s2,((e2-s2)-(e1-s1))); 65218792Snp } 66218792Snp } 67218792Snp 68218792Snp