2
0

dess.cpp 1.3 KB

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