Crypto++ 8.9
Free C++ class library of cryptographic schemes
bench.h
1// bench.h - originally written and placed in the public domain by Wei Dai
2// CryptoPP::Test namespace added by JW in February 2017
3
4#ifndef CRYPTOPP_BENCH_H
5#define CRYPTOPP_BENCH_H
6
7#include "cryptlib.h"
8
9#include <iostream>
10#include <iomanip>
11#include <cmath>
12#include <ctime>
13
14NAMESPACE_BEGIN(CryptoPP)
15NAMESPACE_BEGIN(Test)
16
17// More granular control over benchmarks
18enum TestClass {
19 /// \brief Random number generators
20 UnkeyedRNG=(1<<0),
21 /// \brief Message digests
22 UnkeyedHash=(1<<1),
23 /// \brief Other unkeyed algorithms
24 UnkeyedOther=(1<<2),
25
26 /// \brief Message authentication codes
27 SharedKeyMAC=(1<<3),
28 /// \brief Stream ciphers
29 SharedKeyStream=(1<<4),
30 /// \brief Block ciphers ciphers
31 SharedKeyBlock=(1<<5),
32 /// \brief Other shared key algorithms
33 SharedKeyOther=(1<<6),
34
35 /// \brief Key agreement algorithms over integers
36 PublicKeyAgreement=(1<<7),
37 /// \brief Encryption algorithms over integers
38 PublicKeyEncryption=(1<<8),
39 /// \brief Signature algorithms over integers
40 PublicKeySignature=(1<<9),
41 /// \brief Other public key algorithms over integers
42 PublicKeyOther=(1<<10),
43
44 /// \brief Key agreement algorithms over EC
45 PublicKeyAgreementEC=(1<<11),
46 /// \brief Encryption algorithms over EC
47 PublicKeyEncryptionEC=(1<<12),
48 /// \brief Signature algorithms over EC
49 PublicKeySignatureEC=(1<<13),
50 /// \brief Other public key algorithms over EC
51 PublicKeyOtherEC=(1<<14),
52
53 Unkeyed=UnkeyedRNG|UnkeyedHash|UnkeyedOther,
54 SharedKey=SharedKeyMAC|SharedKeyStream|SharedKeyBlock|SharedKeyOther,
55 PublicKey=PublicKeyAgreement|PublicKeyEncryption|PublicKeySignature|PublicKeyOther,
56 PublicKeyEC=PublicKeyAgreementEC|PublicKeyEncryptionEC|PublicKeySignatureEC|PublicKeyOtherEC,
57
58 All=Unkeyed|SharedKey|PublicKey|PublicKeyEC,
59
60 TestFirst=(0), TestLast=(1<<15)
61};
62
63extern const double CLOCK_TICKS_PER_SECOND;
64extern double g_allocatedTime;
65extern double g_hertz;
66extern double g_logTotal;
67extern unsigned int g_logCount;
68extern const byte defaultKey[];
69
70// Test book keeping
71extern time_t g_testBegin;
72extern time_t g_testEnd;
73
74// Benchmark command handler
75void BenchmarkWithCommand(int argc, const char* const argv[]);
76// Top level, prints preamble and postamble
77void Benchmark(Test::TestClass suites, double t, double hertz);
78// Unkeyed systems
79void BenchmarkUnkeyedAlgorithms(double t, double hertz);
80// Shared key systems
81void BenchmarkSharedKeyedAlgorithms(double t, double hertz);
82// Public key systems over integers
83void BenchmarkPublicKeyAlgorithms(double t, double hertz);
84// Public key systems over elliptic curves
85void BenchmarkEllipticCurveAlgorithms(double t, double hertz);
86
87// These are defined in bench1.cpp
88extern void OutputResultKeying(double iterations, double timeTaken);
89extern void OutputResultBytes(const char *name, const char *provider, double length, double timeTaken);
90extern void OutputResultOperations(const char *name, const char *provider, const char *operation, bool pc, unsigned long iterations, double timeTaken);
91
92// These are defined in bench1.cpp
93extern void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal);
94extern void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal);
95extern void BenchMark(const char *name, HashTransformation &ht, double timeTotal);
96extern void BenchMark(const char *name, RandomNumberGenerator &rng, double timeTotal);
97
98// These are defined in bench2.cpp
99extern void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValuePairs &params);
100extern void BenchMark(const char *name, AuthenticatedSymmetricCipher &cipher, double timeTotal);
101
102NAMESPACE_END // Test
103NAMESPACE_END // CryptoPP
104
105#endif
Interface for authenticated encryption modes of operation.
Definition cryptlib.h:1326
Interface for buffered transformations.
Definition cryptlib.h:1657
Interface for hash functions and data processing part of MACs.
Definition cryptlib.h:1118
Interface for retrieving values given their names.
Definition cryptlib.h:327
Interface for public keys.
Definition cryptlib.h:2541
Interface for random number generators.
Definition cryptlib.h:1440
Interface for algorithms that take byte strings as keys.
Definition cryptlib.h:647
Interface for the data processing portion of stream ciphers.
Definition cryptlib.h:951
Abstract base classes that provide a uniform interface to this library.
Crypto++ library namespace.
Namespace containing testing and benchmark classes.
Definition cryptlib.h:580