OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/cast/transport/transport_encryption_handler.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "crypto/encryptor.h" | |
9 #include "crypto/symmetric_key.h" | |
10 #include "media/cast/transport/cast_transport_defines.h" | |
11 | |
12 namespace media { | |
13 namespace cast { | |
14 namespace transport { | |
15 | |
16 TransportEncryptionHandler::TransportEncryptionHandler() | |
17 : key_(), | |
18 encryptor_(), | |
19 iv_mask_(), | |
20 initialized_(false) {} | |
21 | |
22 TransportEncryptionHandler::~TransportEncryptionHandler() {} | |
23 | |
24 bool TransportEncryptionHandler::Initialize(std::string aes_key, | |
25 std::string aes_iv_mask) { | |
hubbe
2014/01/31 17:46:22
indentation?
mikhal1
2014/01/31 18:22:47
Done.
| |
26 initialized_ = false; | |
27 if (aes_iv_mask.size() == kAesKeySize && aes_key.size() == kAesKeySize) { | |
28 iv_mask_ = aes_iv_mask; | |
29 key_.reset( | |
30 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, aes_key)); | |
31 encryptor_.reset(new crypto::Encryptor()); | |
32 encryptor_->Init(key_.get(), crypto::Encryptor::CTR, std::string()); | |
33 initialized_ = true; | |
34 } else if (aes_iv_mask.size() != 0 || aes_key.size() != 0) { | |
35 DCHECK_EQ(aes_iv_mask.size(), 0u) | |
36 << "Invalid Crypto configuration: aes_iv_mask.size"; | |
37 DCHECK_EQ(aes_key.size(), 0u) | |
38 << "Invalid Crypto configuration: aes_key.size"; | |
39 return false; | |
40 } | |
41 return true; | |
42 } | |
43 | |
44 bool TransportEncryptionHandler::Encrypt(uint32 frame_id, | |
45 std::string data, | |
hubbe
2014/01/31 17:46:22
indentation?
mikhal1
2014/01/31 18:22:47
Done.
| |
46 std::string* encrypted_data) { | |
47 if (!initialized_) | |
48 return false; | |
49 if (!encryptor_->SetCounter(GetAesNonce(frame_id, iv_mask_))) { | |
50 NOTREACHED() << "Failed to set counter"; | |
51 return false; | |
52 } | |
53 if (!encryptor_->Encrypt(data, encrypted_data)) { | |
54 NOTREACHED() << "Encrypt error"; | |
55 return false; | |
56 } | |
57 return true; | |
58 } | |
59 | |
60 } // namespace transport | |
61 } // namespace cast | |
62 } // namespace media | |
OLD | NEW |