| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cast/common/transport_encryption_handler.h" | 5 #include "media/cast/common/transport_encryption_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "crypto/encryptor.h" | 10 #include "crypto/encryptor.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 TransportEncryptionHandler::TransportEncryptionHandler() | 44 TransportEncryptionHandler::TransportEncryptionHandler() |
| 45 : key_(), encryptor_(), iv_mask_(), is_activated_(false) {} | 45 : key_(), encryptor_(), iv_mask_(), is_activated_(false) {} |
| 46 | 46 |
| 47 TransportEncryptionHandler::~TransportEncryptionHandler() {} | 47 TransportEncryptionHandler::~TransportEncryptionHandler() {} |
| 48 | 48 |
| 49 bool TransportEncryptionHandler::Initialize(const std::string& aes_key, | 49 bool TransportEncryptionHandler::Initialize(const std::string& aes_key, |
| 50 const std::string& aes_iv_mask) { | 50 const std::string& aes_iv_mask) { |
| 51 is_activated_ = false; | 51 is_activated_ = false; |
| 52 if (aes_iv_mask.size() == kAesKeySize && aes_key.size() == kAesKeySize) { | 52 if (aes_iv_mask.size() == kAesKeySize && aes_key.size() == kAesKeySize) { |
| 53 iv_mask_ = aes_iv_mask; | 53 iv_mask_ = aes_iv_mask; |
| 54 key_.reset( | 54 key_ = crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, aes_key); |
| 55 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, aes_key)); | |
| 56 encryptor_.reset(new crypto::Encryptor()); | 55 encryptor_.reset(new crypto::Encryptor()); |
| 57 encryptor_->Init(key_.get(), crypto::Encryptor::CTR, std::string()); | 56 encryptor_->Init(key_.get(), crypto::Encryptor::CTR, std::string()); |
| 58 is_activated_ = true; | 57 is_activated_ = true; |
| 59 } else if (aes_iv_mask.size() != 0 || aes_key.size() != 0) { | 58 } else if (aes_iv_mask.size() != 0 || aes_key.size() != 0) { |
| 60 DCHECK_EQ(aes_iv_mask.size(), 0u) | 59 DCHECK_EQ(aes_iv_mask.size(), 0u) |
| 61 << "Invalid Crypto configuration: aes_iv_mask.size"; | 60 << "Invalid Crypto configuration: aes_iv_mask.size"; |
| 62 DCHECK_EQ(aes_key.size(), 0u) | 61 DCHECK_EQ(aes_key.size(), 0u) |
| 63 << "Invalid Crypto configuration: aes_key.size"; | 62 << "Invalid Crypto configuration: aes_key.size"; |
| 64 return false; | 63 return false; |
| 65 } | 64 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 94 } | 93 } |
| 95 if (!encryptor_->Decrypt(ciphertext, plaintext)) { | 94 if (!encryptor_->Decrypt(ciphertext, plaintext)) { |
| 96 VLOG(1) << "Decryption error"; | 95 VLOG(1) << "Decryption error"; |
| 97 return false; | 96 return false; |
| 98 } | 97 } |
| 99 return true; | 98 return true; |
| 100 } | 99 } |
| 101 | 100 |
| 102 } // namespace cast | 101 } // namespace cast |
| 103 } // namespace media | 102 } // namespace media |
| OLD | NEW |