Buffer Size Unit Tests
Merge from widevine repo of http://go/wvgerrit/21260 This CL adds some oemcrypto unit tests for various buffer sizes, as described in b/28887904 and the OEMCrypto v12 specification. Encryption and Decryption buffers can be 100k large. License request and response messages can be 8k. A provider session token (pst) can be at most 255 bytes long. I also passed the code through clang-format. b/28887904 Change-Id: Ia3e317c0f6466e663461e66b610c9a98a90efb0a
This commit is contained in:
@@ -67,6 +67,9 @@ const size_t kTestKeyIdMaxLength = 16;
|
||||
const int kDefaultKeyIdLength = 16;
|
||||
|
||||
const size_t kMaxTestRSAKeyLength = 2000; // Rough estimate.
|
||||
const size_t kMaxPSTLength = 255; // In specification.
|
||||
const size_t kMaxMessageSize = 8 * 1024; // In specification.
|
||||
const size_t kMaxDecryptSize = 100 * 1024; // In specification.
|
||||
|
||||
typedef struct {
|
||||
uint8_t key_id[kTestKeyIdMaxLength];
|
||||
@@ -86,7 +89,7 @@ struct MessageData {
|
||||
MessageKeyData keys[kMaxNumKeys];
|
||||
uint8_t mac_key_iv[wvcdm::KEY_IV_SIZE];
|
||||
uint8_t mac_keys[2 * wvcdm::MAC_KEY_SIZE];
|
||||
uint8_t pst[kTestKeyIdMaxLength];
|
||||
uint8_t pst[kMaxPSTLength];
|
||||
};
|
||||
|
||||
struct RSAPrivateKeyMessage {
|
||||
@@ -141,35 +144,34 @@ class Session {
|
||||
void EncryptAndSign();
|
||||
void EncryptMessage(RSAPrivateKeyMessage* data,
|
||||
RSAPrivateKeyMessage* encrypted);
|
||||
|
||||
template <typename T>
|
||||
void ServerSignMessage(const T& data, std::vector<uint8_t>* signature);
|
||||
|
||||
void ServerSignBuffer(const uint8_t* data, size_t data_length,
|
||||
std::vector<uint8_t>* signature);
|
||||
void ClientSignMessage(const vector<uint8_t>& data,
|
||||
std::vector<uint8_t>* signature);
|
||||
void FillKeyArray(const MessageData& data, OEMCrypto_KeyObject* key_array);
|
||||
void FillRefreshArray(OEMCrypto_KeyRefreshObject* key_array,
|
||||
size_t key_count);
|
||||
void EncryptCTR(
|
||||
const vector<uint8_t>& in_buffer, const uint8_t *key,
|
||||
const uint8_t* starting_iv, vector<uint8_t>* out_buffer);
|
||||
void EncryptCTR(const vector<uint8_t>& in_buffer, const uint8_t* key,
|
||||
const uint8_t* starting_iv, vector<uint8_t>* out_buffer);
|
||||
void TestDecryptCTR(bool select_key_first = true,
|
||||
OEMCryptoResult expected_result = OEMCrypto_SUCCESS,
|
||||
int key_index = 0);
|
||||
void MakeRSACertificate(
|
||||
struct RSAPrivateKeyMessage* encrypted, std::vector<uint8_t>* signature,
|
||||
uint32_t allowed_schemes, const vector<uint8_t>& rsa_key);
|
||||
void MakeRSACertificate(struct RSAPrivateKeyMessage* encrypted,
|
||||
size_t message_size, std::vector<uint8_t>* signature,
|
||||
uint32_t allowed_schemes,
|
||||
const vector<uint8_t>& rsa_key);
|
||||
void RewrapRSAKey(const struct RSAPrivateKeyMessage& encrypted,
|
||||
const std::vector<uint8_t>& signature,
|
||||
size_t message_size, const std::vector<uint8_t>& signature,
|
||||
vector<uint8_t>* wrapped_key, bool force);
|
||||
void PreparePublicKey(const uint8_t* rsa_key = NULL,
|
||||
size_t rsa_key_length = 0);
|
||||
static bool VerifyPSSSignature(
|
||||
EVP_PKEY* pkey, const uint8_t* message, size_t message_length,
|
||||
const uint8_t* signature, size_t signature_length);
|
||||
void VerifyRSASignature(
|
||||
const vector<uint8_t>& message, const uint8_t* signature,
|
||||
size_t signature_length, RSA_Padding_Scheme padding_scheme);
|
||||
static bool VerifyPSSSignature(EVP_PKEY* pkey, const uint8_t* message,
|
||||
size_t message_length,
|
||||
const uint8_t* signature,
|
||||
size_t signature_length);
|
||||
void VerifyRSASignature(const vector<uint8_t>& message,
|
||||
const uint8_t* signature, size_t signature_length,
|
||||
RSA_Padding_Scheme padding_scheme);
|
||||
bool GenerateRSASessionKey(vector<uint8_t>* enc_session_key);
|
||||
void InstallRSASessionTestKey(const vector<uint8_t>& wrapped_rsa_key);
|
||||
void DisallowDeriveKeys();
|
||||
@@ -180,7 +182,7 @@ class Session {
|
||||
void ForceDeleteEntry(const std::string& pst);
|
||||
|
||||
MessageData& license() { return license_; }
|
||||
MessageData& encrypted_license() { return encrypted_license_; }
|
||||
MessageData& encrypted_license() { return padded_message_; }
|
||||
|
||||
const uint8_t* message_ptr();
|
||||
|
||||
@@ -190,6 +192,9 @@ class Session {
|
||||
void set_num_keys(int num_keys) { num_keys_ = num_keys; }
|
||||
int num_keys() const { return num_keys_; }
|
||||
|
||||
void set_message_size(size_t size);
|
||||
size_t message_size() { return message_size_; }
|
||||
|
||||
private:
|
||||
bool open_;
|
||||
bool forced_session_id_;
|
||||
@@ -201,7 +206,10 @@ class Session {
|
||||
RSA* public_rsa_;
|
||||
vector<uint8_t> pst_report_buffer_;
|
||||
MessageData license_;
|
||||
MessageData encrypted_license_;
|
||||
struct PaddedMessageData : public MessageData {
|
||||
uint8_t padding[kMaxMessageSize - sizeof(MessageData)];
|
||||
} padded_message_;
|
||||
size_t message_size_; // How much of the padded message to use.
|
||||
OEMCrypto_KeyObject key_array_[kMaxNumKeys];
|
||||
std::vector<uint8_t> signature_;
|
||||
int num_keys_;
|
||||
|
||||
Reference in New Issue
Block a user