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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 nonce.size() - sizeof(sequence_number)); | 81 nonce.size() - sizeof(sequence_number)); |
82 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(), | 82 memcpy(&sequence_number, nonce.data() + nonce_prefix.size(), |
83 sizeof(sequence_number)); | 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 decrypter->SetNoncePrefix(nonce_prefix); | 90 decrypter->SetNoncePrefix(nonce_prefix); |
91 scoped_ptr<QuicData> decrypted( | 91 char plaintext[kMaxPacketSize]; |
92 decrypter->DecryptPacket(sequence_number, StringPiece(), ciphertext)); | 92 size_t plaintext_length = 0; |
93 if (!decrypted.get()) { | 93 const bool success = decrypter->DecryptPacket( |
| 94 sequence_number, StringPiece() /* associated data */, ciphertext, |
| 95 plaintext, &plaintext_length, kMaxPacketSize); |
| 96 if (!success) { |
94 return false; | 97 return false; |
95 } | 98 } |
96 | 99 |
97 out_storage->resize(decrypted->length()); | 100 out_storage->resize(plaintext_length); |
98 out_storage->assign(decrypted->data(), decrypted->length()); | 101 out_storage->assign(plaintext, plaintext_length); |
99 out->set(out_storage->data(), decrypted->length()); | 102 out->set(out_storage->data(), plaintext_length); |
100 return true; | 103 return true; |
101 } | 104 } |
102 | 105 |
103 } // namespace net | 106 } // namespace net |
OLD | NEW |