Unit test for pointer alignment
Merge from Widevine repo of http://go/wvgerrit/66708 This adds a unit test to verify that LoadKeys still works if the message is not word alligned. Test: unit tests on desktop and taimen (x86 and arm) Bug: 68783727 Change-Id: Ib081a2c21af710b294772513c2c777ef1ac0daf0
This commit is contained in:
@@ -1244,6 +1244,33 @@ TEST_F(OEMCryptoSessionTests, LoadKeyWithBadVerification) {
|
||||
ASSERT_NE(OEMCrypto_SUCCESS, sts);
|
||||
}
|
||||
|
||||
// This test verifies that LoadKeys still works when the message is not aligned
|
||||
// in memory on a word (2 or 4 byte) boundary.
|
||||
TEST_F(OEMCryptoSessionTests, LoadKeyUnalignedMessage) {
|
||||
Session s;
|
||||
ASSERT_NO_FATAL_FAILURE(s.open());
|
||||
ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s));
|
||||
ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage(
|
||||
kDuration, wvoec::kControlNonceEnabled, s.get_nonce()));
|
||||
ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign());
|
||||
std::vector<uint8_t> buffer(1, '0'); // A string of 1 byte long.
|
||||
size_t offset = buffer.size();
|
||||
ASSERT_EQ(1u, offset);
|
||||
// We assume that vectors are allocated on as a small chunk of data that is
|
||||
// aligned on a word boundary. I.e. we assume buffer is word aligned. Next,
|
||||
// we append the message to buffer after the single padding byte.
|
||||
buffer.insert(buffer.end(), s.message_ptr(),
|
||||
s.message_ptr() + s.message_size());
|
||||
// Thus, buffer[offset] is NOT word aligned.
|
||||
const uint8_t* unaligned_message = &buffer[offset];
|
||||
OEMCryptoResult sts = OEMCrypto_LoadKeys(
|
||||
s.session_id(), unaligned_message, s.message_size(), &s.signature()[0],
|
||||
s.signature().size(), s.enc_mac_keys_iv_substr(), s.enc_mac_keys_substr(),
|
||||
s.num_keys(), s.key_array(), GetSubstring(), GetSubstring(),
|
||||
OEMCrypto_ContentLicense);
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, sts);
|
||||
}
|
||||
|
||||
// This tests each key control block verification string in the range kc09-kc1?.
|
||||
class SessionTestAlternateVerification : public OEMCryptoSessionTests,
|
||||
public WithParamInterface<int> {
|
||||
|
||||
Reference in New Issue
Block a user