OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cdm/aes_decryptor.h" | 5 #include "media/cdm/aes_decryptor.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return NULL; | 134 return NULL; |
135 } | 135 } |
136 | 136 |
137 DCHECK_EQ(input.decrypt_config()->iv().size(), | 137 DCHECK_EQ(input.decrypt_config()->iv().size(), |
138 static_cast<size_t>(DecryptConfig::kDecryptionKeySize)); | 138 static_cast<size_t>(DecryptConfig::kDecryptionKeySize)); |
139 if (!encryptor.SetCounter(input.decrypt_config()->iv())) { | 139 if (!encryptor.SetCounter(input.decrypt_config()->iv())) { |
140 DVLOG(1) << "Could not set counter block."; | 140 DVLOG(1) << "Could not set counter block."; |
141 return NULL; | 141 return NULL; |
142 } | 142 } |
143 | 143 |
144 const int data_offset = input.decrypt_config()->data_offset(); | 144 const char* sample = reinterpret_cast<const char*>(input.data()); |
145 const char* sample = | 145 size_t sample_size = static_cast<size_t>(input.data_size()); |
146 reinterpret_cast<const char*>(input.data() + data_offset); | |
147 DCHECK_GT(input.data_size(), data_offset); | |
148 size_t sample_size = static_cast<size_t>(input.data_size() - data_offset); | |
149 | 146 |
150 DCHECK_GT(sample_size, 0U) << "No sample data to be decrypted."; | 147 DCHECK_GT(sample_size, 0U) << "No sample data to be decrypted."; |
151 if (sample_size == 0) | 148 if (sample_size == 0) |
152 return NULL; | 149 return NULL; |
153 | 150 |
154 if (input.decrypt_config()->subsamples().empty()) { | 151 if (input.decrypt_config()->subsamples().empty()) { |
155 std::string decrypted_text; | 152 std::string decrypted_text; |
156 base::StringPiece encrypted_text(sample, sample_size); | 153 base::StringPiece encrypted_text(sample, sample_size); |
157 if (!encryptor.Decrypt(encrypted_text, &decrypted_text)) { | 154 if (!encryptor.Decrypt(encrypted_text, &decrypted_text)) { |
158 DVLOG(1) << "Could not decrypt data."; | 155 DVLOG(1) << "Could not decrypt data."; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 323 } |
327 | 324 |
328 void AesDecryptor::Decrypt(StreamType stream_type, | 325 void AesDecryptor::Decrypt(StreamType stream_type, |
329 const scoped_refptr<DecoderBuffer>& encrypted, | 326 const scoped_refptr<DecoderBuffer>& encrypted, |
330 const DecryptCB& decrypt_cb) { | 327 const DecryptCB& decrypt_cb) { |
331 CHECK(encrypted->decrypt_config()); | 328 CHECK(encrypted->decrypt_config()); |
332 | 329 |
333 scoped_refptr<DecoderBuffer> decrypted; | 330 scoped_refptr<DecoderBuffer> decrypted; |
334 // An empty iv string signals that the frame is unencrypted. | 331 // An empty iv string signals that the frame is unencrypted. |
335 if (encrypted->decrypt_config()->iv().empty()) { | 332 if (encrypted->decrypt_config()->iv().empty()) { |
336 int data_offset = encrypted->decrypt_config()->data_offset(); | 333 decrypted = DecoderBuffer::CopyFrom(encrypted->data(), |
337 decrypted = DecoderBuffer::CopyFrom(encrypted->data() + data_offset, | 334 encrypted->data_size()); |
338 encrypted->data_size() - data_offset); | |
339 } else { | 335 } else { |
340 const std::string& key_id = encrypted->decrypt_config()->key_id(); | 336 const std::string& key_id = encrypted->decrypt_config()->key_id(); |
341 DecryptionKey* key = GetKey(key_id); | 337 DecryptionKey* key = GetKey(key_id); |
342 if (!key) { | 338 if (!key) { |
343 DVLOG(1) << "Could not find a matching key for the given key ID."; | 339 DVLOG(1) << "Could not find a matching key for the given key ID."; |
344 decrypt_cb.Run(kNoKey, NULL); | 340 decrypt_cb.Run(kNoKey, NULL); |
345 return; | 341 return; |
346 } | 342 } |
347 | 343 |
348 crypto::SymmetricKey* decryption_key = key->decryption_key(); | 344 crypto::SymmetricKey* decryption_key = key->decryption_key(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 bool AesDecryptor::DecryptionKey::Init() { | 460 bool AesDecryptor::DecryptionKey::Init() { |
465 CHECK(!secret_.empty()); | 461 CHECK(!secret_.empty()); |
466 decryption_key_.reset(crypto::SymmetricKey::Import( | 462 decryption_key_.reset(crypto::SymmetricKey::Import( |
467 crypto::SymmetricKey::AES, secret_)); | 463 crypto::SymmetricKey::AES, secret_)); |
468 if (!decryption_key_) | 464 if (!decryption_key_) |
469 return false; | 465 return false; |
470 return true; | 466 return true; |
471 } | 467 } |
472 | 468 |
473 } // namespace media | 469 } // namespace media |
OLD | NEW |