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

Unified Diff: net/quic/crypto/aead_base_encrypter_nss.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/crypto/aead_base_encrypter.h ('k') | net/quic/crypto/aead_base_encrypter_openssl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/crypto/aead_base_encrypter_nss.cc
diff --git a/net/quic/crypto/aead_base_encrypter_nss.cc b/net/quic/crypto/aead_base_encrypter_nss.cc
index 1e408ad36f4b25dbda0e7e6242fd80acb5c4de72..ca2e2a9cca9d870de655c3b39f9aef7891c2c1e1 100644
--- a/net/quic/crypto/aead_base_encrypter_nss.cc
+++ b/net/quic/crypto/aead_base_encrypter_nss.cc
@@ -110,27 +110,28 @@ bool AeadBaseEncrypter::Encrypt(StringPiece nonce,
return true;
}
-QuicData* AeadBaseEncrypter::EncryptPacket(
- QuicPacketSequenceNumber sequence_number,
- StringPiece associated_data,
- StringPiece plaintext) {
+bool AeadBaseEncrypter::EncryptPacket(QuicPacketSequenceNumber sequence_number,
+ StringPiece associated_data,
+ StringPiece plaintext,
+ char* output,
+ size_t* output_length,
+ size_t max_output_length) {
size_t ciphertext_size = GetCiphertextSize(plaintext.length());
- scoped_ptr<char[]> ciphertext(new char[ciphertext_size]);
-
+ if (max_output_length < ciphertext_size) {
+ return false;
+ }
// TODO(ianswett): Introduce a check to ensure that we don't encrypt with the
// same sequence number twice.
- uint8 nonce[sizeof(nonce_prefix_) + sizeof(sequence_number)];
const size_t nonce_size = nonce_prefix_size_ + sizeof(sequence_number);
- DCHECK_LE(nonce_size, sizeof(nonce));
- memcpy(nonce, nonce_prefix_, nonce_prefix_size_);
- memcpy(nonce + nonce_prefix_size_, &sequence_number, sizeof(sequence_number));
- if (!Encrypt(StringPiece(reinterpret_cast<char*>(nonce), nonce_size),
- associated_data, plaintext,
- reinterpret_cast<unsigned char*>(ciphertext.get()))) {
- return nullptr;
+ memcpy(output, nonce_prefix_, nonce_prefix_size_);
+ memcpy(output + nonce_prefix_size_, &sequence_number,
+ sizeof(sequence_number));
+ if (!Encrypt(StringPiece(output, nonce_size), associated_data, plaintext,
+ reinterpret_cast<unsigned char*>(output))) {
+ return false;
}
-
- return new QuicData(ciphertext.release(), ciphertext_size, true);
+ *output_length = ciphertext_size;
+ return true;
}
size_t AeadBaseEncrypter::GetKeySize() const { return key_size_; }
« no previous file with comments | « net/quic/crypto/aead_base_encrypter.h ('k') | net/quic/crypto/aead_base_encrypter_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698