In order to support both single-key and dual-key RSA implementations where single-key will use key 0 for both sign and encryption and where dual-key will use key 0 for sign and key 1 for encryption. Additional changes in this code drop: - Added VMP / RA override enabled tests - Added VMP / RA override disabled tests This brings the partner repo in sync with the internal repo at commit 71760b6da1ec546c65b56e2f86b39b73b53f6734.
91 lines
2.6 KiB
C++
91 lines
2.6 KiB
C++
// Copyright 2020 Google LLC. All Rights Reserved.
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "api/license_whitebox.h"
|
|
#include "api/license_whitebox_benchmark.h"
|
|
#include "api/result.h"
|
|
#include "api/test_license_builder.h"
|
|
#include "benchmarking/data_source.h"
|
|
#include "benchmarking/measurements.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace widevine {
|
|
namespace {
|
|
|
|
constexpr size_t kMessageSize = 4 * 1024;
|
|
constexpr size_t kSignatureSize = 256;
|
|
constexpr size_t kIterations = 100;
|
|
|
|
} // namespace
|
|
|
|
class LicenseWhiteboxSignBenchmark : public LicenseWhiteboxBenchmark {
|
|
protected:
|
|
void SetUp() override {
|
|
LicenseWhiteboxBenchmark::SetUp();
|
|
|
|
message_ = Data().Get(kMessageSize);
|
|
signature_.resize(kSignatureSize);
|
|
|
|
ASSERT_EQ(WB_License_Create(&whitebox_), WB_RESULT_OK);
|
|
|
|
const auto license = CreateLicense();
|
|
ASSERT_EQ(WB_License_ProcessLicenseResponse(
|
|
whitebox_, WB_LICENSE_KEY_MODE_DUAL_KEY,
|
|
license.core_message.data(), license.core_message.size(),
|
|
license.message.data(), license.message.size(),
|
|
license.signature.data(), license.signature.size(),
|
|
license.session_key.data(), license.session_key.size(),
|
|
license.request.data(), license.request.size()),
|
|
WB_RESULT_OK);
|
|
}
|
|
|
|
void TearDown() override { WB_License_Delete(whitebox_); }
|
|
|
|
WB_License_Whitebox* whitebox_;
|
|
|
|
std::vector<uint8_t> message_;
|
|
std::vector<uint8_t> signature_;
|
|
};
|
|
|
|
TEST_F(LicenseWhiteboxSignBenchmark, SignLicenseRequest) {
|
|
Timer timer;
|
|
Sampler sampler;
|
|
|
|
for (size_t i = 0; i < kIterations; i++) {
|
|
size_t signature_size = signature_.size();
|
|
|
|
timer.Reset();
|
|
ASSERT_EQ(WB_RESULT_OK, WB_License_SignLicenseRequest(
|
|
whitebox_, message_.data(), message_.size(),
|
|
signature_.data(), &signature_size));
|
|
sampler.Push(timer.Get());
|
|
}
|
|
|
|
PrettyPrint("License White-box Sign License Request Duration", sampler,
|
|
message_.size());
|
|
}
|
|
|
|
TEST_F(LicenseWhiteboxSignBenchmark, SignRenewalRequest) {
|
|
Timer timer;
|
|
Sampler sampler;
|
|
|
|
for (size_t i = 0; i < kIterations; i++) {
|
|
size_t signature_size = signature_.size();
|
|
|
|
timer.Reset();
|
|
ASSERT_EQ(WB_RESULT_OK, WB_License_SignRenewalRequest(
|
|
whitebox_, message_.data(), message_.size(),
|
|
signature_.data(), &signature_size));
|
|
sampler.Push(timer.Get());
|
|
}
|
|
|
|
PrettyPrint("License White-box Sign Renewal Request Duration", sampler,
|
|
message_.size());
|
|
}
|
|
} // namespace widevine
|