Initial Code Drop

This is the initial code drop of the reference implementation and
test cases for the Widevine Whitebox API.

In this drop, the full reference implementation for the AEAD
white-box is provided and all test cases verifying the top-level
behave have are enabled. Since the implementations can vary so much
the testing is mostly left to verifying the return codes for specific
parameter conditions.

A full reference implementation for the license white-box is provided,
however not all tests are implemented or enabled. A number of tests
have been disabled as they required a loaded license and test licenses
are still being worked on.

The two license white-box API functions that are the further from
competition are ProcessLicenseResponse() and MaskedDecryt().
ProcessLicenseResponse() is still being worked on and MaskedDecrypt()
is waiting on Decrypt() to be fully functional.

Most tests focus on verifying return code for specific parameter
conditions, but as test licenses are created, tests looking to test
the internal behaviour of license management will be added to
ProcessLicenseResponse(), Decrypt(), and MaskedDecrypt().
This commit is contained in:
Aaron Vaage
2020-05-18 19:45:53 -07:00
commit 77f7ef98c0
91 changed files with 9597 additions and 0 deletions

22
chromium_deps/base/BUILD Normal file
View File

@@ -0,0 +1,22 @@
# Copyright 2020 Google LLC. All Rights Reserved.
cc_library(
name = "base",
srcs = [
"base64.cc",
"strings/string_number_conversions.cc",
],
hdrs = [
"base64.h",
"logging.h",
"strings/string_number_conversions.h",
],
strip_include_prefix = "//chromium_deps",
visibility = ["//visibility:public"],
deps = [
"//external:gflags",
"//external:glog",
"@abseil_repo//absl/base",
"@abseil_repo//absl/strings",
],
)

View File

@@ -0,0 +1,63 @@
// Copyright 2020 Google LLC. All Rights Reserved.
#include "base/base64.h"
#include <stddef.h>
#include <stdint.h>
namespace base {
namespace {
static const char kBase64Codes[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
// Calculates a/b using round-up division (only works for numbers
// greater than 0).
constexpr size_t CeilDivide(size_t a, size_t b) {
return ((a - 1) / b) + 1;
}
} // namespace
void Base64Encode(const std::string& input, std::string* output) {
if (input.empty()) {
output->clear();
return;
}
// |temp| stores a 24-bit block that is treated as an array where insertions
// occur from high to low.
uint32_t temp = 0;
size_t out_index = 0;
const size_t out_size = CeilDivide(input.size(), 3) * 4;
std::string result(out_size, '\0');
for (size_t i = 0; i < input.size(); i++) {
// "insert" 8-bits of data
temp = (temp << 8) | (input[i] & 0x0FF);
if (i % 3 == 2) {
result[out_index++] = kBase64Codes[(temp >> 18) & 0x3f];
result[out_index++] = kBase64Codes[(temp >> 12) & 0x3f];
result[out_index++] = kBase64Codes[(temp >> 6) & 0x3f];
result[out_index++] = kBase64Codes[temp & 0x3f];
temp = 0;
}
}
if (input.size() % 3 == 1) {
result[out_index++] = kBase64Codes[(temp >> 18) & 0x3f];
result[out_index++] = kBase64Codes[(temp >> 12) & 0x3f];
result[out_index++] = '=';
result[out_index++] = '=';
} else if (input.size() % 3 == 2) {
result[out_index++] = kBase64Codes[(temp >> 18) & 0x3f];
result[out_index++] = kBase64Codes[(temp >> 12) & 0x3f];
result[out_index++] = kBase64Codes[(temp >> 6) & 0x3f];
result[out_index++] = '=';
}
output->swap(result);
}
} // namespace base

View File

@@ -0,0 +1,18 @@
// Copyright 2020 Google LLC. All Rights Reserved.
#ifndef BASE_BASE64_H_
#define BASE_BASE64_H_
#include <string>
namespace base {
// Encodes the input string in base64.
// Note that the Chromium code uses base::StringPiece for |input|, but to
// avoid dragging in too much code, use std::string instead (which is
// convertable to base::StringPiece automatically).
void Base64Encode(const std::string& input, std::string* output);
} // namespace base
#endif // BASE_BASE64_H_

View File

@@ -0,0 +1,10 @@
// Copyright 2020 Google LLC. All Rights Reserved.
#ifndef BASE_LOGGING_H_
#define BASE_LOGGING_H_
// See https://github.com/google/glog/blob/master/doc/glog.html
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include "glog/logging.h"
#endif // BASE_LOGGING_H_

View File

@@ -0,0 +1,14 @@
// Copyright 2020 Google LLC. All Rights Reserved.
#include "base/strings/string_number_conversions.h"
#include "absl/strings/escaping.h"
namespace base {
std::string HexEncode(const void* bytes, size_t size) {
return absl::BytesToHexString(
std::string(reinterpret_cast<const char*>(bytes), size));
}
} // namespace base

View File

@@ -0,0 +1,17 @@
// Copyright 2020 Google LLC. All Rights Reserved.
#ifndef BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_
#define BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
namespace base {
// Returns a hex string representation of a binary buffer.
std::string HexEncode(const void* bytes, size_t size);
} // namespace base
#endif // BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_