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

Unified Diff: net/quic/crypto/aead_base_encrypter_openssl.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_nss.cc ('k') | net/quic/crypto/aes_128_gcm_12_decrypter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/crypto/aead_base_encrypter_openssl.cc
diff --git a/net/quic/crypto/aead_base_encrypter_openssl.cc b/net/quic/crypto/aead_base_encrypter_openssl.cc
index 25d996799cca56c10eac412fa2a6a9b5bb534621..be4b1e8d9d4e7065f51ba9fc6f767dadf48ef36f 100644
--- a/net/quic/crypto/aead_base_encrypter_openssl.cc
+++ b/net/quic/crypto/aead_base_encrypter_openssl.cc
@@ -81,16 +81,12 @@ bool AeadBaseEncrypter::Encrypt(StringPiece nonce,
return false;
}
- size_t len;
+ size_t ciphertext_len;
if (!EVP_AEAD_CTX_seal(
- ctx_.get(),
- output,
- &len,
+ ctx_.get(), output, &ciphertext_len,
plaintext.size() + auth_tag_size_,
- reinterpret_cast<const uint8_t*>(nonce.data()),
- nonce.size(),
- reinterpret_cast<const uint8_t*>(plaintext.data()),
- plaintext.size(),
+ reinterpret_cast<const uint8_t*>(nonce.data()), nonce.size(),
+ reinterpret_cast<const uint8_t*>(plaintext.data()), plaintext.size(),
reinterpret_cast<const uint8_t*>(associated_data.data()),
associated_data.size())) {
DLogOpenSslErrors();
@@ -100,27 +96,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_nss.cc ('k') | net/quic/crypto/aes_128_gcm_12_decrypter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698