In this code drop we introduce the benchmarking tests that allow us to
compare the performance of different implementations. Like the other
tests, any implementation can link with them to create their own
binary.
There are two types of benchmarks:
1 - Throughput, which measures the speed that a function can process
information (bits per second). These are used for AEAD decrypt
and license white-box decrypt functions.
2 - Samples, which measures the min, 25% percentile, median, 75%
percentile, and max observed values. These is used for all other
functions as a way to measure the execute duration of a call.
The other change in this code drop is the update to the unmasking
function to only unmask a subset of the bytes in the masked buffer.
This was added to better align with the decoder behaviour in the CDM.
64 lines
2.1 KiB
C++
64 lines
2.1 KiB
C++
// Copyright 2020 Google LLC. All Rights Reserved.
|
|
|
|
#include "api/license_whitebox_benchmark.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "api/license_whitebox.h"
|
|
#include "api/test_data.h"
|
|
#include "api/test_license_builder.h"
|
|
#include "benchmarking/data_source.h"
|
|
#include "crypto_utils/crypto_util.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace widevine {
|
|
namespace {
|
|
constexpr size_t kBlockSize = 16; // This must align with the AES block size.
|
|
} // namespace
|
|
|
|
void LicenseWhiteboxBenchmark::SetUp() {
|
|
key_id_ = data_source_.Get(8); // The id size is not meaningful.
|
|
key_ = data_source_.Get(kBlockSize);
|
|
iv_ = data_source_.Get(kBlockSize);
|
|
|
|
const auto public_key_data = GetMatchingLicensePublicKey();
|
|
public_key_.reset(widevine::RsaPublicKey::Create(
|
|
std::string(public_key_data.begin(), public_key_data.end())));
|
|
ASSERT_TRUE(public_key_);
|
|
}
|
|
|
|
License LicenseWhiteboxBenchmark::CreateLicense() const {
|
|
widevine::TestLicenseBuilder license_builder;
|
|
license_builder.AddSigningKey(TestLicenseBuilder::DefaultSigningKey());
|
|
// Use secure crypto as it will work with both Decrypt() and
|
|
// MaskedDecrypt().
|
|
license_builder.AddContentKey(
|
|
video_widevine::License_KeyContainer_SecurityLevel_SW_SECURE_CRYPTO,
|
|
key_id_, key_);
|
|
|
|
widevine::License license;
|
|
license_builder.Build(*public_key_, &license);
|
|
|
|
return license;
|
|
}
|
|
|
|
std::vector<uint8_t> LicenseWhiteboxBenchmark::SignAsServer(
|
|
const std::vector<uint8_t>& message) const {
|
|
// The server key is the first half of the signing key.
|
|
const auto key = TestLicenseBuilder::DefaultSigningKey();
|
|
const std::string server_key(key.begin(),
|
|
key.begin() + crypto_util::kSigningKeySizeBytes);
|
|
|
|
// crypto util uses strings, so we will need to convert the result back to a
|
|
// vector before we return it.
|
|
const auto signature = crypto_util::CreateSignatureHmacSha256(
|
|
server_key, std::string(message.begin(), message.end()));
|
|
return std::vector<uint8_t>(signature.begin(), signature.end());
|
|
}
|
|
|
|
} // namespace widevine
|