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

Side by Side Diff: net/quic/crypto/crypto_secret_boxer.cc

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 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
« no previous file with comments | « net/quic/crypto/crypto_protocol.h ('k') | net/quic/crypto/crypto_server_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "net/quic/crypto/crypto_secret_boxer.h" 5 #include "net/quic/crypto/crypto_secret_boxer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "net/quic/crypto/crypto_protocol.h" 9 #include "net/quic/crypto/crypto_protocol.h"
10 #include "net/quic/crypto/quic_decrypter.h" 10 #include "net/quic/crypto/quic_decrypter.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return ret; 67 return ret;
68 } 68 }
69 69
70 bool CryptoSecretBoxer::Unbox(StringPiece ciphertext, 70 bool CryptoSecretBoxer::Unbox(StringPiece ciphertext,
71 string* out_storage, 71 string* out_storage,
72 StringPiece* out) const { 72 StringPiece* out) const {
73 if (ciphertext.size() < kBoxNonceSize) { 73 if (ciphertext.size() < kBoxNonceSize) {
74 return false; 74 return false;
75 } 75 }
76 76
77 char nonce[kBoxNonceSize]; 77 StringPiece nonce(ciphertext.data(), kBoxNonceSize);
78 memcpy(nonce, ciphertext.data(), kBoxNonceSize);
79 ciphertext.remove_prefix(kBoxNonceSize); 78 ciphertext.remove_prefix(kBoxNonceSize);
80 79 QuicPacketSequenceNumber sequence_number;
81 size_t len = ciphertext.size(); 80 StringPiece nonce_prefix(nonce.data(),
82 out_storage->resize(len); 81 nonce.size() - sizeof(sequence_number));
83 char* data = const_cast<char*>(out_storage->data()); 82 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(),
83 sizeof(sequence_number));
84 84
85 scoped_ptr<QuicDecrypter> decrypter(QuicDecrypter::Create(kAESG)); 85 scoped_ptr<QuicDecrypter> decrypter(QuicDecrypter::Create(kAESG));
86 if (!decrypter->SetKey(key_)) { 86 if (!decrypter->SetKey(key_)) {
87 DLOG(DFATAL) << "CryptoSecretBoxer's decrypter->SetKey failed."; 87 DLOG(DFATAL) << "CryptoSecretBoxer's decrypter->SetKey failed.";
88 return false; 88 return false;
89 } 89 }
90 if (!decrypter->Decrypt(StringPiece(nonce, kBoxNonceSize), StringPiece(), 90 decrypter->SetNoncePrefix(nonce_prefix);
91 ciphertext, reinterpret_cast<unsigned char*>(data), 91 scoped_ptr<QuicData> decrypted(
92 &len)) { 92 decrypter->DecryptPacket(sequence_number, StringPiece(), ciphertext));
93 if (!decrypted.get()) {
93 return false; 94 return false;
94 } 95 }
95 96
96 out->set(data, len); 97 out_storage->resize(decrypted->length());
98 out_storage->assign(decrypted->data(), decrypted->length());
99 out->set(out_storage->data(), decrypted->length());
97 return true; 100 return true;
98 } 101 }
99 102
100 } // namespace net 103 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_protocol.h ('k') | net/quic/crypto/crypto_server_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698