diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index e3fdb123..3cdaeba6 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -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 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 {