Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:54

0001 // bench.h - originally written and placed in the public domain by Wei Dai

0002 //           CryptoPP::Test namespace added by JW in February 2017

0003 
0004 #ifndef CRYPTOPP_BENCH_H
0005 #define CRYPTOPP_BENCH_H
0006 
0007 #include "cryptlib.h"
0008 
0009 #include <iostream>
0010 #include <iomanip>
0011 #include <cmath>
0012 #include <ctime>
0013 
0014 NAMESPACE_BEGIN(CryptoPP)
0015 NAMESPACE_BEGIN(Test)
0016 
0017 // More granular control over benchmarks

0018 enum TestClass {
0019     /// \brief Random number generators

0020     UnkeyedRNG=(1<<0),
0021     /// \brief Message digests

0022     UnkeyedHash=(1<<1),
0023     /// \brief Other unkeyed algorithms

0024     UnkeyedOther=(1<<2),
0025 
0026     /// \brief Message authentication codes

0027     SharedKeyMAC=(1<<3),
0028     /// \brief Stream ciphers

0029     SharedKeyStream=(1<<4),
0030     /// \brief Block ciphers ciphers

0031     SharedKeyBlock=(1<<5),
0032     /// \brief Other shared key algorithms

0033     SharedKeyOther=(1<<6),
0034 
0035     /// \brief Key agreement algorithms over integers

0036     PublicKeyAgreement=(1<<7),
0037     /// \brief Encryption algorithms over integers

0038     PublicKeyEncryption=(1<<8),
0039     /// \brief Signature algorithms over integers

0040     PublicKeySignature=(1<<9),
0041     /// \brief Other public key algorithms over integers

0042     PublicKeyOther=(1<<10),
0043 
0044     /// \brief Key agreement algorithms over EC

0045     PublicKeyAgreementEC=(1<<11),
0046     /// \brief Encryption algorithms over EC

0047     PublicKeyEncryptionEC=(1<<12),
0048     /// \brief Signature algorithms over EC

0049     PublicKeySignatureEC=(1<<13),
0050     /// \brief Other public key algorithms over EC

0051     PublicKeyOtherEC=(1<<14),
0052 
0053     Unkeyed=UnkeyedRNG|UnkeyedHash|UnkeyedOther,
0054     SharedKey=SharedKeyMAC|SharedKeyStream|SharedKeyBlock|SharedKeyOther,
0055     PublicKey=PublicKeyAgreement|PublicKeyEncryption|PublicKeySignature|PublicKeyOther,
0056     PublicKeyEC=PublicKeyAgreementEC|PublicKeyEncryptionEC|PublicKeySignatureEC|PublicKeyOtherEC,
0057 
0058     All=Unkeyed|SharedKey|PublicKey|PublicKeyEC,
0059 
0060     TestFirst=(0), TestLast=(1<<15)
0061 };
0062 
0063 extern const double CLOCK_TICKS_PER_SECOND;
0064 extern double g_allocatedTime;
0065 extern double g_hertz;
0066 extern double g_logTotal;
0067 extern unsigned int g_logCount;
0068 extern const byte defaultKey[];
0069 
0070 // Test book keeping

0071 extern time_t g_testBegin;
0072 extern time_t g_testEnd;
0073 
0074 // Benchmark command handler

0075 void BenchmarkWithCommand(int argc, const char* const argv[]);
0076 // Top level, prints preamble and postamble

0077 void Benchmark(Test::TestClass suites, double t, double hertz);
0078 // Unkeyed systems

0079 void BenchmarkUnkeyedAlgorithms(double t, double hertz);
0080 // Shared key systems

0081 void BenchmarkSharedKeyedAlgorithms(double t, double hertz);
0082 // Public key systems over integers

0083 void BenchmarkPublicKeyAlgorithms(double t, double hertz);
0084 // Public key systems over elliptic curves

0085 void BenchmarkEllipticCurveAlgorithms(double t, double hertz);
0086 
0087 // These are defined in bench1.cpp

0088 extern void OutputResultKeying(double iterations, double timeTaken);
0089 extern void OutputResultBytes(const char *name, const char *provider, double length, double timeTaken);
0090 extern void OutputResultOperations(const char *name, const char *provider, const char *operation, bool pc, unsigned long iterations, double timeTaken);
0091 
0092 // These are defined in bench1.cpp

0093 extern void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal);
0094 extern void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal);
0095 extern void BenchMark(const char *name, HashTransformation &ht, double timeTotal);
0096 extern void BenchMark(const char *name, RandomNumberGenerator &rng, double timeTotal);
0097 
0098 // These are defined in bench2.cpp

0099 extern void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValuePairs &params);
0100 extern void BenchMark(const char *name, AuthenticatedSymmetricCipher &cipher, double timeTotal);
0101 
0102 NAMESPACE_END  // Test

0103 NAMESPACE_END  // CryptoPP

0104 
0105 #endif