Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1099)

Unified Diff: media/crypto/aes_decryptor.cc

Issue 10800091: Replace memcmp() with HMAC.VerifyTruncated() in aes_decryptor.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing comments from Patch Set 3. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/crypto/aes_decryptor.cc
diff --git a/media/crypto/aes_decryptor.cc b/media/crypto/aes_decryptor.cc
index e69f4062a8afb3f00ee9d609a19785da40269efe..730a9b80c70f03181f0e1eb21f52ceed5532447e 100644
--- a/media/crypto/aes_decryptor.cc
+++ b/media/crypto/aes_decryptor.cc
@@ -66,21 +66,22 @@ static bool CheckData(const DecoderBuffer& input,
if (!hmac.Init(hmac_key))
return false;
- // The HMAC covers the IV and the frame data.
+ // The component that initializes |input.GetDecryptConfig()| is responsible
+ // for checking that |input.GetDecryptConfig()->checksum_size()| matches
+ // what is defined by the format.
+
+ // Here, check that checksum size is not greater than the hash
+ // algorithm's digest length.
+ DCHECK_LE(input.GetDecryptConfig()->checksum_size(),
+ static_cast<int>(hmac.DigestLength()));
+
base::StringPiece data_to_check(
reinterpret_cast<const char*>(input.GetData()), input.GetDataSize());
+ base::StringPiece digest(
+ reinterpret_cast<const char*>(input.GetDecryptConfig()->checksum()),
+ input.GetDecryptConfig()->checksum_size());
- scoped_array<uint8> calculated_hmac(new uint8[hmac.DigestLength()]);
- if (!hmac.Sign(data_to_check, calculated_hmac.get(), hmac.DigestLength()))
- return false;
-
- DCHECK(input.GetDecryptConfig()->checksum_size() <=
- static_cast<int>(hmac.DigestLength()));
- if (memcmp(input.GetDecryptConfig()->checksum(),
- calculated_hmac.get(),
- input.GetDecryptConfig()->checksum_size()) != 0)
- return false;
- return true;
+ return hmac.VerifyTruncated(data_to_check, digest);
}
// Decrypts |input| using |key|. |encrypted_data_offset| is the number of bytes
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698