Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 |
| 81 size_t len = ciphertext.size(); | 80 size_t len = ciphertext.size(); |
| 82 out_storage->resize(len); | 81 out_storage->resize(len); |
| 83 char* data = const_cast<char*>(out_storage->data()); | 82 char* data = const_cast<char*>(out_storage->data()); |
| 84 | 83 |
| 85 scoped_ptr<QuicDecrypter> decrypter(QuicDecrypter::Create(kAESG)); | 84 scoped_ptr<QuicDecrypter> decrypter(QuicDecrypter::Create(kAESG)); |
| 86 if (!decrypter->SetKey(key_)) { | 85 if (!decrypter->SetKey(key_)) { |
| 87 DLOG(DFATAL) << "CryptoSecretBoxer's decrypter->SetKey failed."; | 86 DLOG(DFATAL) << "CryptoSecretBoxer's decrypter->SetKey failed."; |
| 88 return false; | 87 return false; |
| 89 } | 88 } |
| 90 if (!decrypter->Decrypt(StringPiece(nonce, kBoxNonceSize), StringPiece(), | 89 |
| 91 ciphertext, reinterpret_cast<unsigned char*>(data), | 90 QuicPacketSequenceNumber sequence_number; |
| 92 &len)) { | 91 StringPiece nonce_prefix(nonce.data(), |
| 92 nonce.size() - sizeof(sequence_number)); | |
| 93 decrypter->SetNoncePrefix(nonce_prefix); | |
| 94 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(), | |
| 95 sizeof(sequence_number)); | |
| 96 scoped_ptr<QuicData> decrypted( | |
| 97 decrypter->DecryptPacket(sequence_number, StringPiece(), ciphertext)); | |
| 98 if (!decrypted.get()) { | |
| 93 return false; | 99 return false; |
| 94 } | 100 } |
| 95 | 101 |
| 96 out->set(data, len); | 102 memcpy(data, decrypted->data(), decrypted->length()); |
| 103 out->set(data, decrypted->length()); | |
|
Ryan Hamilton
2015/01/23 00:29:13
consider using out->assign(decrypted->data(), decr
ramant (doing other things)
2015/01/23 00:47:54
Used std::string's assign to copy the data in the
| |
| 97 return true; | 104 return true; |
| 98 } | 105 } |
| 99 | 106 |
| 100 } // namespace net | 107 } // namespace net |
| OLD | NEW |