00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <unistd.h>
00019 #include <signal.h>
00020 #include <iostream>
00021 #include <iomanip>
00022 #include <sys/resource.h>
00023 #include <sys/time.h>
00024 #include <openssl/ssl.h>
00025 #include <openssl/rand.h>
00026
00027 using namespace std;
00028
00029 int main( int argc, char** argv )
00030 {
00031
00032
00033
00034 unsigned char seed[40] =
00035 {0x38,0x4F,0x67,0x4C,0xA6,0x02,0x3D,0x9E,
00036 0x69, 0x2c, 0x3f, 0xfd, 0x98, 0x50, 0xcc,
00037 0x76, 0xfa, 0x78, 0x34, 0x12, 0x23, 0xdf,
00038 0x8a, 0xd4, 0x34, 0xcd, 0x98, 0x59, 0x19,
00039 0x35, 0x4f, 0xda, 0xed, 0x4e, 0x99, 0x0f};
00040 RAND_seed(seed,40);
00041
00042
00043
00044
00045
00046 SSL_load_error_strings();
00047 SSLeay_add_ssl_algorithms();
00048
00049 for ( int i = 0 ; i < 100 ; ++i )
00050 {
00051
00052 struct rusage ru1;
00053 struct timeval tv1;
00054 getrusage(RUSAGE_SELF,&ru1);
00055 gettimeofday(&tv1,0);
00056
00057
00058 const unsigned int kNumBits = 512;
00059 BIGNUM * p = BN_new();
00060 if ( 0 == p )
00061 {
00062 throw __LINE__;
00063 }
00064 if ( 0 == BN_generate_prime( p, kNumBits, 1, 0, 0, 0, 0 ) )
00065 {
00066 throw __LINE__;
00067 }
00068 BN_clear_free(p);
00069
00070
00071 struct rusage ru2;
00072 struct timeval tv2;
00073 getrusage(RUSAGE_SELF,&ru2);
00074 gettimeofday(&tv2,0);
00075
00076
00077 long int rt =
00078 ( ru2.ru_utime.tv_sec - ru1.ru_utime.tv_sec ) * 1000000 +
00079 ( ru2.ru_utime.tv_usec - ru1.ru_utime.tv_usec );
00080 long int t =
00081 ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + ( tv2.tv_usec - tv1.tv_usec );
00082 cout << rt << " " << t << endl;
00083 }
00084 }