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

Side by Side Diff: media/cast/utility/cast_decryption_handler.cc

Issue 138843011: Cast: Adding helper crypto classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/utility/cast_decryption_handler.h"
6
7 #include "base/logging.h"
8 #include "crypto/encryptor.h"
9 #include "crypto/symmetric_key.h"
10 #include "media/cast/cast_defines.h"
11 #include "media/cast/transport/cast_transport_defines.h"
12
13 namespace media {
14 namespace cast {
15
16 CastDecryptionHandler::CastDecryptionHandler()
17 : key_(), iv_mask_(), decryptor_(), initialized_(false) {}
18
19 CastDecryptionHandler::~CastDecryptionHandler() {}
20
21 bool CastDecryptionHandler::Initialize(std::string aes_key,
22 std::string aes_iv_mask) {
hubbe 2014/01/31 17:46:22 It looks like the Encryptor and Decryptor have the
mikhal1 2014/01/31 18:22:47 Good point.Done. On 2014/01/31 17:46:22, hubbe wro
23 initialized_ = false;
24 if (aes_iv_mask.size() == transport::kAesKeySize &&
25 aes_key.size() == transport::kAesKeySize) {
26 iv_mask_ = aes_iv_mask;
27 key_.reset(
28 crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, aes_key));
29 decryptor_.reset(new crypto::Encryptor());
30 decryptor_->Init(key_.get(), crypto::Encryptor::CTR, std::string());
31 initialized_ = true;
32 } else if (aes_iv_mask.size() != 0 || aes_key.size() != 0) {
33 DCHECK(false) << "Invalid crypto configuration";
34 return false;
35 }
36 return true;
37 }
38
39 bool CastDecryptionHandler::Decrypt(uint32 frame_id,
40 const base::StringPiece& ciphertext,
41 std::string* plaintext) {
42 if (!initialized_) {
43 return false;
44 }
45 if (!decryptor_->SetCounter(transport::GetAesNonce(frame_id, iv_mask_))) {
46 NOTREACHED() << "Failed to set counter";
47 return false;
48 }
49 if (!decryptor_->Decrypt(ciphertext, plaintext)) {
50 VLOG(1) << "Decryption error";
51 return false;
52 }
53 return true;
54 }
55
56 } // namespace cast
57 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698