first commit, SM2-DSA only

This commit is contained in:
Zhi Guan
2014-12-01 10:40:26 +08:00
commit 57954c4567
2230 changed files with 569407 additions and 0 deletions

67
times/x86/bfs.cpp Normal file
View File

@@ -0,0 +1,67 @@
//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.
#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
asm volatile(".byte 15, 49\n\t"
: "=eax" (tsc)
:
: "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
unsigned long a;
__asm _emit 0fh
__asm _emit 31h
__asm mov a, eax;
tsc=a;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <openssl/blowfish.h>
void main(int argc,char *argv[])
{
BF_KEY key;
unsigned long s1,s2,e1,e2;
unsigned long data[2];
int i,j;
for (j=0; j<6; j++)
{
for (i=0; i<1000; i++) /**/
{
BF_encrypt(&data[0],&key);
GetTSC(s1);
BF_encrypt(&data[0],&key);
BF_encrypt(&data[0],&key);
BF_encrypt(&data[0],&key);
GetTSC(e1);
GetTSC(s2);
BF_encrypt(&data[0],&key);
BF_encrypt(&data[0],&key);
BF_encrypt(&data[0],&key);
BF_encrypt(&data[0],&key);
GetTSC(e2);
BF_encrypt(&data[0],&key);
}
printf("blowfish %d %d (%d)\n",
e1-s1,e2-s2,((e2-s2)-(e1-s1)));
}
}

67
times/x86/casts.cpp Normal file
View File

@@ -0,0 +1,67 @@
//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.
#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
asm volatile(".byte 15, 49\n\t"
: "=eax" (tsc)
:
: "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
unsigned long a;
__asm _emit 0fh
__asm _emit 31h
__asm mov a, eax;
tsc=a;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <openssl/cast.h>
void main(int argc,char *argv[])
{
CAST_KEY key;
unsigned long s1,s2,e1,e2;
unsigned long data[2];
int i,j;
for (j=0; j<6; j++)
{
for (i=0; i<1000; i++) /**/
{
CAST_encrypt(&data[0],&key);
GetTSC(s1);
CAST_encrypt(&data[0],&key);
CAST_encrypt(&data[0],&key);
CAST_encrypt(&data[0],&key);
GetTSC(e1);
GetTSC(s2);
CAST_encrypt(&data[0],&key);
CAST_encrypt(&data[0],&key);
CAST_encrypt(&data[0],&key);
CAST_encrypt(&data[0],&key);
GetTSC(e2);
CAST_encrypt(&data[0],&key);
}
printf("cast %d %d (%d)\n",
e1-s1,e2-s2,((e2-s2)-(e1-s1)));
}
}

67
times/x86/des3s.cpp Normal file
View File

@@ -0,0 +1,67 @@
//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.
#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
asm volatile(".byte 15, 49\n\t"
: "=eax" (tsc)
:
: "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
unsigned long a;
__asm _emit 0fh
__asm _emit 31h
__asm mov a, eax;
tsc=a;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <openssl/des.h>
void main(int argc,char *argv[])
{
des_key_schedule key1,key2,key3;
unsigned long s1,s2,e1,e2;
unsigned long data[2];
int i,j;
for (j=0; j<6; j++)
{
for (i=0; i<1000; i++) /**/
{
des_encrypt3(&data[0],key1,key2,key3);
GetTSC(s1);
des_encrypt3(&data[0],key1,key2,key3);
des_encrypt3(&data[0],key1,key2,key3);
des_encrypt3(&data[0],key1,key2,key3);
GetTSC(e1);
GetTSC(s2);
des_encrypt3(&data[0],key1,key2,key3);
des_encrypt3(&data[0],key1,key2,key3);
des_encrypt3(&data[0],key1,key2,key3);
des_encrypt3(&data[0],key1,key2,key3);
GetTSC(e2);
des_encrypt3(&data[0],key1,key2,key3);
}
printf("des3 %d %d (%d)\n",
e1-s1,e2-s2,((e2-s2)-(e1-s1)));
}
}

67
times/x86/dess.cpp Normal file
View File

@@ -0,0 +1,67 @@
//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.
#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
asm volatile(".byte 15, 49\n\t"
: "=eax" (tsc)
:
: "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
unsigned long a;
__asm _emit 0fh
__asm _emit 31h
__asm mov a, eax;
tsc=a;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <openssl/des.h>
void main(int argc,char *argv[])
{
des_key_schedule key;
unsigned long s1,s2,e1,e2;
unsigned long data[2];
int i,j;
for (j=0; j<6; j++)
{
for (i=0; i<1000; i++) /**/
{
des_encrypt(&data[0],key,1);
GetTSC(s1);
des_encrypt(&data[0],key,1);
des_encrypt(&data[0],key,1);
des_encrypt(&data[0],key,1);
GetTSC(e1);
GetTSC(s2);
des_encrypt(&data[0],key,1);
des_encrypt(&data[0],key,1);
des_encrypt(&data[0],key,1);
des_encrypt(&data[0],key,1);
GetTSC(e2);
des_encrypt(&data[0],key,1);
}
printf("des %d %d (%d)\n",
e1-s1,e2-s2,((e2-s2)-(e1-s1)));
}
}

78
times/x86/md4s.cpp Normal file
View File

@@ -0,0 +1,78 @@
//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.
#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
asm volatile(".byte 15, 49\n\t"
: "=eax" (tsc)
:
: "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
unsigned long a;
__asm _emit 0fh
__asm _emit 31h
__asm mov a, eax;
tsc=a;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <openssl/md4.h>
extern "C" {
void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
}
void main(int argc,char *argv[])
{
unsigned char buffer[64*256];
MD4_CTX ctx;
unsigned long s1,s2,e1,e2;
unsigned char k[16];
unsigned long data[2];
unsigned char iv[8];
int i,num=0,numm;
int j=0;
if (argc >= 2)
num=atoi(argv[1]);
if (num == 0) num=16;
if (num > 250) num=16;
numm=num+2;
num*=64;
numm*=64;
for (j=0; j<6; j++)
{
for (i=0; i<10; i++) /**/
{
md4_block_x86(&ctx,buffer,numm);
GetTSC(s1);
md4_block_x86(&ctx,buffer,numm);
GetTSC(e1);
GetTSC(s2);
md4_block_x86(&ctx,buffer,num);
GetTSC(e2);
md4_block_x86(&ctx,buffer,num);
}
printf("md4 (%d bytes) %d %d (%.2f)\n",num,
e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
}
}

78
times/x86/md5s.cpp Normal file
View File

@@ -0,0 +1,78 @@
//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.
#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
asm volatile(".byte 15, 49\n\t"
: "=eax" (tsc)
:
: "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
unsigned long a;
__asm _emit 0fh
__asm _emit 31h
__asm mov a, eax;
tsc=a;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <openssl/md5.h>
extern "C" {
void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num);
}
void main(int argc,char *argv[])
{
unsigned char buffer[64*256];
MD5_CTX ctx;
unsigned long s1,s2,e1,e2;
unsigned char k[16];
unsigned long data[2];
unsigned char iv[8];
int i,num=0,numm;
int j=0;
if (argc >= 2)
num=atoi(argv[1]);
if (num == 0) num=16;
if (num > 250) num=16;
numm=num+2;
num*=64;
numm*=64;
for (j=0; j<6; j++)
{
for (i=0; i<10; i++) /**/
{
md5_block_x86(&ctx,buffer,numm);
GetTSC(s1);
md5_block_x86(&ctx,buffer,numm);
GetTSC(e1);
GetTSC(s2);
md5_block_x86(&ctx,buffer,num);
GetTSC(e2);
md5_block_x86(&ctx,buffer,num);
}
printf("md5 (%d bytes) %d %d (%.2f)\n",num,
e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
}
}

73
times/x86/rc4s.cpp Normal file
View File

@@ -0,0 +1,73 @@
//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.
#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
asm volatile(".byte 15, 49\n\t"
: "=eax" (tsc)
:
: "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
unsigned long a;
__asm _emit 0fh
__asm _emit 31h
__asm mov a, eax;
tsc=a;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <openssl/rc4.h>
void main(int argc,char *argv[])
{
unsigned char buffer[1024];
RC4_KEY ctx;
unsigned long s1,s2,e1,e2;
unsigned char k[16];
unsigned long data[2];
unsigned char iv[8];
int i,num=64,numm;
int j=0;
if (argc >= 2)
num=atoi(argv[1]);
if (num == 0) num=256;
if (num > 1024-16) num=1024-16;
numm=num+8;
for (j=0; j<6; j++)
{
for (i=0; i<10; i++) /**/
{
RC4(&ctx,numm,buffer,buffer);
GetTSC(s1);
RC4(&ctx,numm,buffer,buffer);
GetTSC(e1);
GetTSC(s2);
RC4(&ctx,num,buffer,buffer);
GetTSC(e2);
RC4(&ctx,num,buffer,buffer);
}
printf("RC4 (%d bytes) %d %d (%d) - 8 bytes\n",num,
e1-s1,e2-s2,(e1-s1)-(e2-s2));
}
}

79
times/x86/sha1s.cpp Normal file
View File

@@ -0,0 +1,79 @@
//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.
#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
asm volatile(".byte 15, 49\n\t"
: "=eax" (tsc)
:
: "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
unsigned long a;
__asm _emit 0fh
__asm _emit 31h
__asm mov a, eax;
tsc=a;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <openssl/sha.h>
extern "C" {
void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num);
}
void main(int argc,char *argv[])
{
unsigned char buffer[64*256];
SHA_CTX ctx;
unsigned long s1,s2,e1,e2;
unsigned char k[16];
unsigned long data[2];
unsigned char iv[8];
int i,num=0,numm;
int j=0;
if (argc >= 2)
num=atoi(argv[1]);
if (num == 0) num=16;
if (num > 250) num=16;
numm=num+2;
num*=64;
numm*=64;
for (j=0; j<6; j++)
{
for (i=0; i<10; i++) /**/
{
sha1_block_x86(&ctx,buffer,numm);
GetTSC(s1);
sha1_block_x86(&ctx,buffer,numm);
GetTSC(e1);
GetTSC(s2);
sha1_block_x86(&ctx,buffer,num);
GetTSC(e2);
sha1_block_x86(&ctx,buffer,num);
}
printf("sha1 (%d bytes) %d %d (%.2f)\n",num,
e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
}
}