Merge "Added unittests for WV CRC-32 implementation." into sc-dev
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
//
|
||||
// Compute CRC32 Checksum. Needed for verification of WV Keybox.
|
||||
// Compute CRC32/MPEG2 Checksum. Needed for verification of WV Keybox.
|
||||
//
|
||||
#include "platform.h"
|
||||
#include "wvcrc32.h"
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
//
|
||||
// Reference implementation of OEMCrypto APIs
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wvcrc32.h"
|
||||
|
||||
namespace wvoec_ref {
|
||||
|
||||
uint32_t ComputeCrc32(const std::string& s) {
|
||||
return wvcrc32(reinterpret_cast<const uint8_t*>(s.data()), s.size());
|
||||
}
|
||||
|
||||
uint32_t ComputeCrc32Cont(const std::string& s, uint32_t prev_crc) {
|
||||
return wvcrc32Cont(reinterpret_cast<const uint8_t*>(s.data()), s.size(),
|
||||
prev_crc);
|
||||
}
|
||||
|
||||
TEST(OEMCryptoWvCrc32Test, BasicTest) {
|
||||
EXPECT_EQ(0xF88AC628, ComputeCrc32("abcdefg"));
|
||||
EXPECT_EQ(0xDF520F72, ComputeCrc32("Widevine"));
|
||||
EXPECT_EQ(0x0376E6E7, ComputeCrc32("123456789"));
|
||||
EXPECT_EQ(0xBA62119E,
|
||||
ComputeCrc32("The quick brown fox jumps over the lazy dog"));
|
||||
}
|
||||
|
||||
TEST(OEMCryptoWvCrc32Test, StreamTest) {
|
||||
const std::vector<std::string> parts = {"The ", "quick", " brown ",
|
||||
"fox", " jumps ", "over",
|
||||
" the ", "lazy", " dog"};
|
||||
uint32_t crc = wvcrc32Init();
|
||||
for (const auto& part : parts) {
|
||||
crc = ComputeCrc32Cont(part, crc);
|
||||
}
|
||||
EXPECT_EQ(0xBA62119E, crc);
|
||||
}
|
||||
|
||||
TEST(OEMCryptoWvCrc32Test, Keybox) {
|
||||
// clang-format off
|
||||
const uint8_t kKeyboxData[128] = {
|
||||
// deviceID = WidevineCRCTestKeyBox
|
||||
0x57, 0x69, 0x64, 0x65, 0x76, 0x69, 0x6e, 0x65,
|
||||
0x43, 0x52, 0x43, 0x54, 0x65, 0x73, 0x74, 0x4b,
|
||||
0x65, 0x79, 0x62, 0x6f, 0x78, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// key = random
|
||||
0x8a, 0x7c, 0xda, 0x3e, 0x09, 0xd9, 0x8e, 0xd5,
|
||||
0x47, 0x47, 0x00, 0x84, 0x5a, 0x1f, 0x52, 0xd4,
|
||||
// data = random
|
||||
0x98, 0xa5, 0x00, 0x19, 0x8b, 0xfe, 0x54, 0xfd,
|
||||
0xca, 0x4d, 0x26, 0xa3, 0xfa, 0xaa, 0x3b, 0x6c,
|
||||
0x35, 0xfe, 0x03, 0x7c, 0xbf, 0x35, 0xba, 0xce,
|
||||
0x31, 0xb5, 0x1e, 0x3c, 0x49, 0xd6, 0x3f, 0x9c,
|
||||
0x3a, 0xde, 0x9b, 0x58, 0xcc, 0x54, 0x8d, 0xc0,
|
||||
0x4b, 0x04, 0xcc, 0xee, 0xae, 0x4d, 0x9f, 0x90,
|
||||
0xd3, 0xf3, 0xfe, 0x23, 0x26, 0x13, 0x56, 0x80,
|
||||
0xe4, 0x3b, 0x79, 0x22, 0x69, 0x5d, 0xd6, 0xb7,
|
||||
0xa0, 0x0e, 0x7e, 0x07, 0xcd, 0x1a, 0x15, 0xca,
|
||||
// magic
|
||||
'k', 'b', 'o', 'x',
|
||||
// crc
|
||||
0x09, 0x7b, 0x7e, 0xcc
|
||||
};
|
||||
// clang-format on
|
||||
const uint32_t crc_computed = wvcrc32n(kKeyboxData, 124);
|
||||
uint32_t crc_current;
|
||||
memcpy(&crc_current, &kKeyboxData[124], 4);
|
||||
EXPECT_EQ(crc_computed, crc_current);
|
||||
}
|
||||
|
||||
} // namespace wvoec_ref
|
||||
Reference in New Issue
Block a user