diff options
| author | markus <> | 2003-05-11 21:36:59 +0000 |
|---|---|---|
| committer | markus <> | 2003-05-11 21:36:59 +0000 |
| commit | 9cea7b85baecb1a02a3ea617de73d9693a9792eb (patch) | |
| tree | b0ca83a03e35572831c5818cd2011868d462a5d1 /src/lib/libcrypto/rc5/rc5s.cpp | |
| parent | f8f1d7fabf136ce9810602509c477d2c42bf6d1c (diff) | |
| download | openbsd-9cea7b85baecb1a02a3ea617de73d9693a9792eb.tar.gz openbsd-9cea7b85baecb1a02a3ea617de73d9693a9792eb.tar.bz2 openbsd-9cea7b85baecb1a02a3ea617de73d9693a9792eb.zip | |
import 0.9.7b (without idea and rc5)
Diffstat (limited to 'src/lib/libcrypto/rc5/rc5s.cpp')
| -rw-r--r-- | src/lib/libcrypto/rc5/rc5s.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/lib/libcrypto/rc5/rc5s.cpp b/src/lib/libcrypto/rc5/rc5s.cpp new file mode 100644 index 0000000000..1c5518bc80 --- /dev/null +++ b/src/lib/libcrypto/rc5/rc5s.cpp | |||
| @@ -0,0 +1,70 @@ | |||
| 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 | |||
| 9 | #if defined(__WATCOMC__) | ||
| 10 | void GetTSC(unsigned long&); | ||
| 11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
| 12 | #elif defined(__GNUC__) | ||
| 13 | inline | ||
| 14 | void GetTSC(unsigned long& tsc) | ||
| 15 | { | ||
| 16 | asm volatile(".byte 15, 49\n\t" | ||
| 17 | : "=eax" (tsc) | ||
| 18 | : | ||
| 19 | : "%edx", "%eax"); | ||
| 20 | } | ||
| 21 | #elif defined(_MSC_VER) | ||
| 22 | inline | ||
| 23 | void GetTSC(unsigned long& tsc) | ||
| 24 | { | ||
| 25 | unsigned long a; | ||
| 26 | __asm _emit 0fh | ||
| 27 | __asm _emit 31h | ||
| 28 | __asm mov a, eax; | ||
| 29 | tsc=a; | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #include <stdio.h> | ||
| 34 | #include <stdlib.h> | ||
| 35 | #include <openssl/rc5.h> | ||
| 36 | |||
| 37 | void main(int argc,char *argv[]) | ||
| 38 | { | ||
| 39 | RC5_32_KEY key; | ||
| 40 | unsigned long s1,s2,e1,e2; | ||
| 41 | unsigned long data[2]; | ||
| 42 | int i,j; | ||
| 43 | static unsigned char d[16]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; | ||
| 44 | |||
| 45 | RC5_32_set_key(&key, 16,d,12); | ||
| 46 | |||
| 47 | for (j=0; j<6; j++) | ||
| 48 | { | ||
| 49 | for (i=0; i<1000; i++) /**/ | ||
| 50 | { | ||
| 51 | RC5_32_encrypt(&data[0],&key); | ||
| 52 | GetTSC(s1); | ||
| 53 | RC5_32_encrypt(&data[0],&key); | ||
| 54 | RC5_32_encrypt(&data[0],&key); | ||
| 55 | RC5_32_encrypt(&data[0],&key); | ||
| 56 | GetTSC(e1); | ||
| 57 | GetTSC(s2); | ||
| 58 | RC5_32_encrypt(&data[0],&key); | ||
| 59 | RC5_32_encrypt(&data[0],&key); | ||
| 60 | RC5_32_encrypt(&data[0],&key); | ||
| 61 | RC5_32_encrypt(&data[0],&key); | ||
| 62 | GetTSC(e2); | ||
| 63 | RC5_32_encrypt(&data[0],&key); | ||
| 64 | } | ||
| 65 | |||
| 66 | printf("cast %d %d (%d)\n", | ||
| 67 | e1-s1,e2-s2,((e2-s2)-(e1-s1))); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
