This is a merge of the following CLs: Style clean up in oemcrypto/mock https://widevine-internal-review.googlesource.com/#/c/10660 Split off default keybox. https://widevine-internal-review.googlesource.com/#/c/10661/ Split off several properties from CryptoEngine. https://widevine-internal-review.googlesource.com/#/c/10662/ Split off Keybox installation. https://widevine-internal-review.googlesource.com/#/c/10680/ Wii-U build compatibility fixes. https://widevine-internal-review.googlesource.com/#/c/10720/ Fix style issues in oemcrypto_logging_test. https://widevine-internal-review.googlesource.com/#/c/10824/ Correct OEMCrypto error codes in the mock. https://widevine-internal-review.googlesource.com/#/c/10821/ Enable logging during OEMCrypto unit tests. https://widevine-internal-review.googlesource.com/#/c/10833/ Wait to create usage table path until needed. https://widevine-internal-review.googlesource.com/#/c/10831/ Allow keybox installation to be unimplemented. https://widevine-internal-review.googlesource.com/#/c/10850/ Minor clean up in the OEMCrypto header. https://widevine-internal-review.googlesource.com/#/c/10921/ Add usage table device property to the mock oemcrypto https://widevine-internal-review.googlesource.com/#/c/11092/ Change-Id: I02a818a620bcd4bd2291f1b3c0ac9308ae444319
78 lines
2.4 KiB
C++
78 lines
2.4 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
//
|
|
// Mock implementation of OEMCrypto APIs
|
|
//
|
|
#ifndef OEMCRYPTO_KEY_MOCK_H_
|
|
#define OEMCRYPTO_KEY_MOCK_H_
|
|
|
|
#include <stdint.h>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace wvoec_mock {
|
|
|
|
const uint32_t kControlObserveDataPath = (1<<31);
|
|
const uint32_t kControlObserveHDCP = (1<<30);
|
|
const uint32_t kControlObserveCGMS = (1<<29);
|
|
const uint32_t kControlReplayMask = (0x03<<13);
|
|
const uint32_t kControlNonceRequired = (0x01<<13);
|
|
const uint32_t kControlNonceOrEntry = (0x02<<13);
|
|
const uint32_t kControlHDCPVersionShift = 9;
|
|
const uint32_t kControlHDCPVersionMask = (0x0F<<kControlHDCPVersionShift);
|
|
const uint32_t kControlAllowEncrypt = (1<<8);
|
|
const uint32_t kControlAllowDecrypt = (1<<7);
|
|
const uint32_t kControlAllowSign = (1<<6);
|
|
const uint32_t kControlAllowVerify = (1<<5);
|
|
const uint32_t kControlDataPathSecure = (1<<4);
|
|
const uint32_t kControlNonceEnabled = (1<<3);
|
|
const uint32_t kControlHDCPRequired = (1<<2);
|
|
const uint32_t kControlCGMSMask = (0x03);
|
|
const uint32_t kControlCGMSCopyFreely = (0x00);
|
|
const uint32_t kControlCGMSCopyOnce = (0x02);
|
|
const uint32_t kControlCGMSCopyNever = (0x03);
|
|
|
|
class KeyControlBlock {
|
|
public:
|
|
KeyControlBlock(const std::vector<uint8_t>& key_control_string);
|
|
~KeyControlBlock() {}
|
|
|
|
bool Validate();
|
|
void Invalidate() { valid_ = false; }
|
|
|
|
bool valid() const { return valid_; }
|
|
uint32_t duration() const { return duration_; }
|
|
void set_duration(uint32_t duration) { duration_ = duration; }
|
|
uint32_t nonce() const { return nonce_; }
|
|
uint32_t verification() const { return verification_; }
|
|
uint32_t control_bits() const { return control_bits_; }
|
|
|
|
private:
|
|
uint32_t ExtractField(const std::vector<uint8_t>& str, int idx);
|
|
|
|
bool valid_;
|
|
uint32_t verification_;
|
|
uint32_t duration_;
|
|
uint32_t nonce_;
|
|
uint32_t control_bits_;
|
|
};
|
|
|
|
// AES-128 crypto key, or HMAC signing key.
|
|
class Key {
|
|
public:
|
|
Key(const Key& key) : value_(key.value_), control_(key.control_) {}
|
|
Key(const std::vector<uint8_t>& key_string, const KeyControlBlock& control);
|
|
|
|
virtual ~Key() {};
|
|
void UpdateDuration(const KeyControlBlock& control);
|
|
const std::vector<uint8_t>& value() const { return value_; }
|
|
const KeyControlBlock& control() const { return control_; }
|
|
|
|
private:
|
|
std::vector<uint8_t> value_;
|
|
KeyControlBlock control_;
|
|
};
|
|
|
|
} // namespace wvoec_mock
|
|
|
|
#endif // OEMCRYPTO_KEY_MOCK_H_
|