proxygen
EncryptedRecordBench.cpp File Reference

Go to the source code of this file.

Functions

std::unique_ptr< folly::IOBufmakeRandom (size_t n)
 
std::unique_ptr< folly::IOBuftoIOBuf (std::string hexData)
 
TrafficKey getKey ()
 
void encryptGCM (uint32_t n, size_t size)
 
 BENCHMARK_PARAM (encryptGCM, 10)
 
 BENCHMARK_PARAM (encryptGCM, 100)
 
 BENCHMARK_PARAM (encryptGCM, 1000)
 
 BENCHMARK_PARAM (encryptGCM, 4000)
 
 BENCHMARK_PARAM (encryptGCM, 8000)
 
int main (int argc, char **argv)
 

Function Documentation

BENCHMARK_PARAM ( encryptGCM  ,
10   
)

Referenced by encryptGCM().

BENCHMARK_PARAM ( encryptGCM  ,
100   
)
BENCHMARK_PARAM ( encryptGCM  ,
1000   
)
BENCHMARK_PARAM ( encryptGCM  ,
4000   
)
BENCHMARK_PARAM ( encryptGCM  ,
8000   
)
void encryptGCM ( uint32_t  n,
size_t  size 
)

Definition at line 43 of file EncryptedRecordBench.cpp.

References fizz::application_data, fizz::AppTraffic, BENCHMARK_PARAM(), BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), getKey(), i, makeRandom(), folly::gen::move, fizz::Aead::setKey(), folly::size(), uint32_t, and fizz::detail::write().

43  {
44  std::unique_ptr<Aead> aead;
45  std::vector<fizz::TLSMessage> msgs;
46  EncryptedWriteRecordLayer write{EncryptionLevel::AppTraffic};
48  aead = std::make_unique<OpenSSLEVPCipher<AESGCM128>>();
49  aead->setKey(getKey());
50  write.setAead(folly::ByteRange(), std::move(aead));
51  for (size_t i = 0; i < n; ++i) {
52  TLSMessage msg{ContentType::application_data, makeRandom(size)};
53  msgs.push_back(std::move(msg));
54  }
55  }
56 
57  TLSContent content;
58  for (auto& msg : msgs) {
59  content = write.write(std::move(msg));
60  }
61  folly::doNotOptimizeAway(content);
62 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void setKey(TrafficKey key)=0
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
std::unique_ptr< folly::IOBuf > makeRandom(size_t n)
TrafficKey getKey()
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
TrafficKey getKey ( )

Definition at line 36 of file EncryptedRecordBench.cpp.

References fizz::TrafficKey::iv, fizz::TrafficKey::key, and toIOBuf().

Referenced by encryptGCM(), fizz::test::getCert< RSATest >(), folly::settings::detail::SettingCore< T >::set(), fizz::testing::TEST_P(), and fizz::test::TEST_P().

36  {
37  TrafficKey trafficKey;
38  trafficKey.key = toIOBuf("000102030405060708090A0B0C0D0E0F");
39  trafficKey.iv = toIOBuf("000102030405060708090A0B");
40  return trafficKey;
41 }
std::unique_ptr< folly::IOBuf > toIOBuf(std::string hexData)
std::unique_ptr< folly::IOBuf > key
Definition: Aead.h:17
std::unique_ptr< folly::IOBuf > iv
Definition: Aead.h:18
int main ( int  argc,
char **  argv 
)

Definition at line 99 of file EncryptedRecordBench.cpp.

References fizz::CryptoUtils::init(), folly::init(), and folly::runBenchmarks().

99  {
100  folly::init(&argc, &argv);
103  return 0;
104 }
void runBenchmarks()
Definition: Benchmark.cpp:456
void init()
void init(int *argc, char ***argv, bool removeFlags)
Definition: Init.cpp:34
char ** argv
std::unique_ptr<folly::IOBuf> makeRandom ( size_t  n)

Definition at line 16 of file EncryptedRecordBench.cpp.

References folly::IOBuf::copyBuffer(), i, folly::Random::rand32(), and string.

Referenced by encryptGCM(), fizz::test::MockFactory::setDefaults(), fizz::client::test::TEST_F(), and fizz::server::test::TEST_F().

16  {
17  static const char alphanum[] =
18  "0123456789"
19  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
20  "abcdefghijklmnopqrstuvwxyz";
21 
22  std::string rv;
23  rv.reserve(n);
24  for (size_t i = 0; i < n; ++i) {
25  rv.push_back(alphanum[folly::Random::rand32() % (sizeof(alphanum) - 1)]);
26  }
27  return folly::IOBuf::copyBuffer(rv, 5, 17);
28 }
const char * string
Definition: Conv.cpp:212
static uint32_t rand32()
Definition: Random.h:213
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
std::unique_ptr<folly::IOBuf> toIOBuf ( std::string  hexData)

Definition at line 30 of file EncryptedRecordBench.cpp.

References folly::IOBuf::copyBuffer(), string, and folly::unhexlify().

Referenced by fizz::test::callDecrypt(), fizz::test::callEncrypt(), fizz::test::getCipher(), getKey(), and fizz::test::TEST_P().

30  {
31  std::string out;
32  CHECK(folly::unhexlify(hexData, out));
33  return folly::IOBuf::copyBuffer(out);
34 }
bool unhexlify(const InputString &input, OutputString &output)
Definition: String-inl.h:616
const char * string
Definition: Conv.cpp:212
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587