Test Simultaneous decrypt and remove NULL pointer comparison

[ Merge of http://go/wvgerrit/16544, http://go/wvgerrit/16639 ]

* This fixes the oemcrypto unit tests to build with the ce cdm.

The unit tests do not build when it is detected that a long (NULL)
is compared to a pointer.

* Remove NULL pointer comparison

On some platforms ASSERT_NE(NULL, ptr) does not work.  This CL
replaces it with ASSERT_TRUE(NULL != ptr).

* Test Simultaneous Decrypt

With the increasing number of devices that support multiple screens or
windows, it is desireable to verify that OEMCrypto can have several
sessions open and actively decrypting at the same time.

Calls to OEMCrypto are still serialized -- this is not a threading
test -- but we still have multiple sessions open and decrypt from each
of them.

* Remove unused variable in initialization_data

Change-Id: I1a4be38fb30a14f610544416db653a81342f16b3
This commit is contained in:
Rahul Frias
2016-02-10 14:49:09 -08:00
parent c7e92b68e6
commit 3e5b6d7489
2 changed files with 58 additions and 8 deletions

View File

@@ -526,7 +526,7 @@ static void dump_openssl_error() {
// is different from the OpenSSL implementation, so we implement the CTR loop
// ourselves.
void ctr128_inc64(int64_t increaseBy, uint8_t* iv) {
ASSERT_TRUE(NULL != iv);
ASSERT_NE(static_cast<void*>(NULL), iv);
uint64_t* counterBuffer = reinterpret_cast<uint64_t*>(&iv[8]);
(*counterBuffer) =
wvcdm::htonll64(wvcdm::ntohll64(*counterBuffer) + increaseBy);
@@ -877,9 +877,9 @@ class Session {
void EncryptCTR(const vector<uint8_t>& in_buffer,const uint8_t *key,
const uint8_t* starting_iv,
vector<uint8_t>* out_buffer) {
ASSERT_TRUE(NULL != key);
ASSERT_TRUE(NULL != starting_iv);
ASSERT_TRUE(NULL != out_buffer);
ASSERT_NE(static_cast<void*>(NULL), key);
ASSERT_NE(static_cast<void*>(NULL), starting_iv);
ASSERT_NE(static_cast<void*>(NULL), out_buffer);
AES_KEY aes_key;
AES_set_encrypt_key(key, AES_BLOCK_SIZE * 8, &aes_key);
out_buffer->resize(in_buffer.size());
@@ -1646,9 +1646,7 @@ TEST_F(OEMCryptoKeyboxTest, NormalGetKeyData) {
ASSERT_EQ(OEMCrypto_SUCCESS, sts);
}
// TODO(fredgc): warn people that this will be turned on. It causes a
// seg fault on some devices at the moment.
TEST_F(OEMCryptoKeyboxTest, DISABLED_GetKeyDataNullPointer) {
TEST_F(OEMCryptoKeyboxTest, GetKeyDataNullPointer) {
OEMCryptoResult sts;
uint8_t key_data[256];
sts = OEMCrypto_GetKeyData(key_data, NULL);
@@ -2366,6 +2364,59 @@ TEST_F(OEMCryptoSessionTests, DecryptZeroDuration) {
ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR());
}
TEST_F(OEMCryptoSessionTests, SimultaneousDecrypt) {
vector<Session> s(8);
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].open());
}
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].GenerateTestSessionKeys());
ASSERT_NO_FATAL_FAILURE(s[i].FillSimpleMessage(kDuration, 0,
s[i].get_nonce()));
ASSERT_NO_FATAL_FAILURE(s[i].EncryptAndSign());
}
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].LoadTestKeys());
}
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].TestDecryptCTR());
}
// Second call to decrypt for each session.
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].TestDecryptCTR());
}
}
TEST_F(OEMCryptoSessionTests, SimultaneousDecryptWithLostMessage) {
vector<Session> s(8);
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].open());
}
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].GenerateTestSessionKeys());
ASSERT_NO_FATAL_FAILURE(s[i].FillSimpleMessage(kDuration, 0,
s[i].get_nonce()));
ASSERT_NO_FATAL_FAILURE(s[i].EncryptAndSign());
}
// First set of messages are lost. Generate second set.
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].GenerateTestSessionKeys());
ASSERT_NO_FATAL_FAILURE(s[i].FillSimpleMessage(kDuration, 0,
s[i].get_nonce()));
ASSERT_NO_FATAL_FAILURE(s[i].EncryptAndSign());
}
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].LoadTestKeys());
}
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].TestDecryptCTR());
}
// Second call to decrypt for each session.
for (int i = 0; i < 8; i++) {
ASSERT_NO_FATAL_FAILURE(s[i].TestDecryptCTR());
}
}
struct SampleSize {
size_t clear_size;
size_t encrypted_size;