OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/crypto/aes_decryptor.h" | 5 #include "media/crypto/aes_decryptor.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "crypto/encryptor.h" | 10 #include "crypto/encryptor.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 const base::StringPiece& hmac_key) { | 59 const base::StringPiece& hmac_key) { |
60 CHECK(input.GetDataSize()); | 60 CHECK(input.GetDataSize()); |
61 CHECK(input.GetDecryptConfig()); | 61 CHECK(input.GetDecryptConfig()); |
62 CHECK_GT(input.GetDecryptConfig()->checksum_size(), 0); | 62 CHECK_GT(input.GetDecryptConfig()->checksum_size(), 0); |
63 CHECK(!hmac_key.empty()); | 63 CHECK(!hmac_key.empty()); |
64 | 64 |
65 crypto::HMAC hmac(crypto::HMAC::SHA1); | 65 crypto::HMAC hmac(crypto::HMAC::SHA1); |
66 if (!hmac.Init(hmac_key)) | 66 if (!hmac.Init(hmac_key)) |
67 return false; | 67 return false; |
68 | 68 |
69 DCHECK(input.GetDecryptConfig()->checksum_size() <= | |
Ryan Sleevi
2012/07/24 05:49:56
nit: DCHECK_LE
fgalligan1
2012/07/24 15:27:25
Done.
| |
70 static_cast<int>(hmac.DigestLength())); | |
71 | |
69 // The HMAC covers the IV and the frame data. | 72 // The HMAC covers the IV and the frame data. |
70 base::StringPiece data_to_check( | 73 base::StringPiece data_to_check( |
71 reinterpret_cast<const char*>(input.GetData()), input.GetDataSize()); | 74 reinterpret_cast<const char*>(input.GetData()), input.GetDataSize()); |
75 base::StringPiece digest( | |
76 reinterpret_cast<const char*>(input.GetDecryptConfig()->checksum()), | |
Ryan Sleevi
2012/07/24 05:49:56
Are there checks elsewhere that make sure that inp
fgalligan1
2012/07/24 15:27:25
In webm_cluster_parser we explicitly set the size
Ryan Sleevi
2012/07/24 15:45:25
No, quite the opposite. I was wondering if the att
| |
77 input.GetDecryptConfig()->checksum_size()); | |
72 | 78 |
73 scoped_array<uint8> calculated_hmac(new uint8[hmac.DigestLength()]); | 79 return hmac.VerifyTruncated(data_to_check, digest); |
74 if (!hmac.Sign(data_to_check, calculated_hmac.get(), hmac.DigestLength())) | |
75 return false; | |
76 | |
77 DCHECK(input.GetDecryptConfig()->checksum_size() <= | |
78 static_cast<int>(hmac.DigestLength())); | |
79 if (memcmp(input.GetDecryptConfig()->checksum(), | |
80 calculated_hmac.get(), | |
81 input.GetDecryptConfig()->checksum_size()) != 0) | |
82 return false; | |
83 return true; | |
84 } | 80 } |
85 | 81 |
86 // Decrypts |input| using |key|. |encrypted_data_offset| is the number of bytes | 82 // Decrypts |input| using |key|. |encrypted_data_offset| is the number of bytes |
87 // into |input| that the encrypted data starts. | 83 // into |input| that the encrypted data starts. |
88 // Returns a DecoderBuffer with the decrypted data if decryption succeeded or | 84 // Returns a DecoderBuffer with the decrypted data if decryption succeeded or |
89 // NULL if decryption failed. | 85 // NULL if decryption failed. |
90 static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, | 86 static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, |
91 crypto::SymmetricKey* key, | 87 crypto::SymmetricKey* key, |
92 int encrypted_data_offset) { | 88 int encrypted_data_offset) { |
93 CHECK(input.GetDataSize()); | 89 CHECK(input.GetDataSize()); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 | 295 |
300 decryption_key_.reset( | 296 decryption_key_.reset( |
301 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_)); | 297 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, secret_)); |
302 if (!decryption_key_.get()) { | 298 if (!decryption_key_.get()) { |
303 return false; | 299 return false; |
304 } | 300 } |
305 return true; | 301 return true; |
306 } | 302 } |
307 | 303 |
308 } // namespace media | 304 } // namespace media |
OLD | NEW |