Skip to content

Commit

Permalink
Add AES/OFB RNG benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Mar 11, 2017
1 parent 76377f8 commit c2efbae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bench1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ void BenchMark(const char *name, RandomNumberGenerator &rng, double timeTotal)
Test::GlobalRNG().GenerateBlock(buf, BUF_SIZE);
buf.SetMark(16);

SymmetricCipher * cipher = dynamic_cast<SymmetricCipher*>(&rng);
if (cipher != NULLPTR)
{
const size_t size = cipher->DefaultKeyLength();
if (cipher->IsResynchronizable())
cipher->SetKeyWithIV(buf, size, buf+size);
else
cipher->SetKey(buf, size);
}

unsigned long long blocks = 1;
double timeTaken;

Expand Down Expand Up @@ -406,6 +416,7 @@ void Benchmark1(double t, double hertz)
if (HasRDSEED())
BenchMarkByNameKeyLess<RandomNumberGenerator>("RDSEED");
#endif
BenchMarkByNameKeyLess<RandomNumberGenerator>("AES/OFB RNG");
BenchMarkByNameKeyLess<NIST_DRBG>("Hash_DRBG(SHA1)");
BenchMarkByNameKeyLess<NIST_DRBG>("Hash_DRBG(SHA256)");
BenchMarkByNameKeyLess<NIST_DRBG>("HMAC_DRBG(SHA1)");
Expand Down
1 change: 1 addition & 0 deletions regtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void RegisterFactories()
if (HasRDSEED())
RegisterDefaultFactoryFor<RandomNumberGenerator, RDSEED>();
#endif
RegisterDefaultFactoryFor<RandomNumberGenerator, OFB_Mode<AES>::Encryption >("AES/OFB RNG");
RegisterDefaultFactoryFor<NIST_DRBG, Hash_DRBG<SHA1> >("Hash_DRBG(SHA1)");
RegisterDefaultFactoryFor<NIST_DRBG, Hash_DRBG<SHA256> >("Hash_DRBG(SHA256)");
RegisterDefaultFactoryFor<NIST_DRBG, HMAC_DRBG<SHA1> >("HMAC_DRBG(SHA1)");
Expand Down

1 comment on commit c2efbae

@noloader
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of an abuse... AES/OFB is a SymmetricCipher and it needs to be keyed. However, we test the generator using BenchMarkByNameKeyLess instead of BenchMarkByName. Then, inside BenchMark(const char *name, RandomNumberGenerator &rng, ...), we key it.

Its expedient but it hacks around the design because we lack a KeyedRandomNumberGenerator interface.

Please sign in to comment.