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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: media/cast/utility/cast_decryption_handler.cc
diff --git a/media/cast/utility/cast_decryption_handler.cc b/media/cast/utility/cast_decryption_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..21a6d69deb65c3a5f9be3f8573394b6a65a1382f
--- /dev/null
+++ b/media/cast/utility/cast_decryption_handler.cc
@@ -0,0 +1,57 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/cast/utility/cast_decryption_handler.h"
+
+#include "base/logging.h"
+#include "crypto/encryptor.h"
+#include "crypto/symmetric_key.h"
+#include "media/cast/cast_defines.h"
+#include "media/cast/transport/cast_transport_defines.h"
+
+namespace media {
+namespace cast {
+
+CastDecryptionHandler::CastDecryptionHandler()
+ : key_(), iv_mask_(), decryptor_(), initialized_(false) {}
+
+CastDecryptionHandler::~CastDecryptionHandler() {}
+
+bool CastDecryptionHandler::Initialize(std::string aes_key,
+ 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
+ initialized_ = false;
+ if (aes_iv_mask.size() == transport::kAesKeySize &&
+ aes_key.size() == transport::kAesKeySize) {
+ iv_mask_ = aes_iv_mask;
+ key_.reset(
+ crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, aes_key));
+ decryptor_.reset(new crypto::Encryptor());
+ decryptor_->Init(key_.get(), crypto::Encryptor::CTR, std::string());
+ initialized_ = true;
+ } else if (aes_iv_mask.size() != 0 || aes_key.size() != 0) {
+ DCHECK(false) << "Invalid crypto configuration";
+ return false;
+ }
+ return true;
+}
+
+bool CastDecryptionHandler::Decrypt(uint32 frame_id,
+ const base::StringPiece& ciphertext,
+ std::string* plaintext) {
+ if (!initialized_) {
+ return false;
+ }
+ if (!decryptor_->SetCounter(transport::GetAesNonce(frame_id, iv_mask_))) {
+ NOTREACHED() << "Failed to set counter";
+ return false;
+ }
+ if (!decryptor_->Decrypt(ciphertext, plaintext)) {
+ VLOG(1) << "Decryption error";
+ return false;
+ }
+ return true;
+}
+
+} // namespace cast
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698