Skip to content

Commit

Permalink
Land Recent QUIC changes
Browse files Browse the repository at this point in the history
QUIC: use QuicTag/QuicTagVector throughout.

crypto_protocol.h has had CryptoTag and CryptoTagVector. Then quic_protocol.h
got QuicVersionTag and QuicVersionTagList because it didn't want to depend on
crypto_protocol.h

This change uses a single QuicTag and QuicTagVector throughout the code,
including the crypto code.

Merge internal change: 45230337

QUIC: move random values to the beginning and the certifiate chain to the end.

jar suggested that the certificate chain should have a tag that will cause it
to be sorted at the end of any handshake messages because it's likely to be
large and the client might be able to get everything that it needs from the
small values at the beginning.

Likewise he argued that tags with random values should be towards the beginning
of the message because the server mightn't hold state for a rejected client
hello and therefore the client may have issues reassembling the rejection
message in the event that it sent two client hellos.

This change tweaks the tag values to achieve that ordering.

Merge internal change: 45228375

Removing obselete TODOs

Merge internal change: 45219448

Use the idle connection state timeout negotiated in crypto handshake.

Merge internal change: 45176251

QUIC: address wtc's followup comments on cl/44792710.

This change addresses wtc's comments on cl/44792710. There should be no
semantic differences.

Merge internal change: 45051718

QUIC - Fixed HasRetransmittableData enum to have the correct values.

Fixed comments from rch

Merge internal change: 45143336

Change the QUIC version number to a new value which is amenable to frequent i ncrementing.

Merge internal change: 45111687

QUIC: run clang-format over .../quic/crypto.

I ran:
  for x in $(ls -1 *.cc *.h) ; do clang-format -i $x -style Google; echo $x;
done

And then used git add -p to manually review the changes. In the cases where I
didn't care, I went with what the tool produced.

Merge internal change: 45053104

QUIC: address wtc's followup comments on cl/44792710.

This change addresses wtc's comments on cl/44792710. There should be no
semantic differences.

Merge internal change: 45051718

Minor cleanup of ReliableQuicStreamTest output. Also change MockConnection to create a NiceMock version of the Helper to avoid annoying GMock messages.

Merge internal change: 45010564

QUIC: partly deflake EndToEndTest.LargePost

Since cl/44690884, some runs of this test have timed out. Everything
appears to be working ok, just not fast enough. It's possible that the
additional packet `losses' caused by decryption failures when we lose
the client hello are convincing the congestion control that the loss
rate is very high.

However, since I have a trip to NIST this week, this change removes the
flake by reverting a tiny part of cl/44690884.

Sadly there is another flake in the test which this CL doesn't fix.
Details in the bug.

Merge internal change: 45008247

Fix a bug in QUIC header compression handling where buffered headers were not handled properly.

Merge internal change: 45007035

QUIC: tiny test cleanup.

wtc suggested this in a post-submission comment.

Merge internal change: 44898354

QUIC: add expiry to server configs and have the GFE generate random server configs.

Server configs need an expiry because they are effectively certificates. This
change has the GFE generate server configs with the same expiry as the primary
certificate.

It also switches the GFE to generating random server configs at startup.
(Random in the sense of random keys and orbit values.)

Originally I wanted to have the server config persist over a restart and so
derived them, deterministically, from the primary, private key with a todo to
diversify the orbit. However, since we don't have any shared strike registers
at the moment that doesn't seem to be worth the complexity. Also, figuring out
how to diversify the orbit value in a per-GFE sense is really messy (include
the hostname? include the port? Which port?). So this CL goes for simple and
secure.

Merge internal change: 44898035

QUIC: use 24-bit lengths for public values.

If ideal lattices don't work out then we may end up with Diffie-Hellman public
values that are larger than 16-bits. (Hopefully not, but you never know.)

Merge internal change: 44897191

QUIC: have the client echo the server's nonce.

This reflects a comment from wtc previously that this would be a good idea.

Merge internal change: 44896699

QUIC: steps 12 and 13, forward secure mode.

Merge internal change: 44896363

Fix LOG(DFATAL) when client sends invalid stream frame with fin.

Merge internal change: 44871764

R=rch@chromium.org

Review URL: https://chromiumcodereview.appspot.com/14816006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199190 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rtenneti@chromium.org committed May 9, 2013
1 parent da29a20 commit 2532de1
Show file tree
Hide file tree
Showing 114 changed files with 1,620 additions and 1,042 deletions.
2 changes: 2 additions & 0 deletions net/net.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@
'quic/crypto/crypto_utils.h',
'quic/crypto/curve25519_key_exchange.cc',
'quic/crypto/curve25519_key_exchange.h',
'quic/crypto/ephemeral_key_source.h',
'quic/crypto/key_exchange.h',
'quic/crypto/null_decrypter.cc',
'quic/crypto/null_decrypter.h',
Expand Down Expand Up @@ -2679,6 +2680,7 @@
'tools/quic/quic_epoll_connection_helper_test.cc',
'tools/quic/quic_reliable_client_stream_test.cc',
'tools/quic/quic_reliable_server_stream_test.cc',
'tools/quic/quic_spdy_server_stream_test.cc',
'tools/quic/test_tools/http_message_test_utils.cc',
'tools/quic/test_tools/http_message_test_utils.h',
'tools/quic/test_tools/mock_epoll_server.cc',
Expand Down
2 changes: 1 addition & 1 deletion net/quic/congestion_control/fix_rate_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void FixRateSender::SentPacket(QuicTime sent_time,
Retransmission is_retransmission) {
fix_rate_leaky_bucket_.Add(sent_time, bytes);
paced_sender_.SentPacket(sent_time, bytes);
if (!is_retransmission) {
if (is_retransmission == NOT_RETRANSMISSION) {
data_in_flight_ += bytes;
}
}
Expand Down
16 changes: 8 additions & 8 deletions net/quic/congestion_control/fix_rate_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ TEST_F(FixRateTest, SenderAPI) {
unused_bandwidth_, unused_packet_map_);
EXPECT_EQ(300000, sender_->BandwidthEstimate().ToBytesPerSecond());
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
sender_->SentPacket(clock_.Now(), 1, kMaxPacketSize, NOT_RETRANSMISSION);
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
sender_->SentPacket(clock_.Now(), 2, kMaxPacketSize, NOT_RETRANSMISSION);
sender_->SentPacket(clock_.Now(), 3, 600, NOT_RETRANSMISSION);
EXPECT_EQ(QuicTime::Delta::FromMilliseconds(10), sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA));
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA));
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2));
EXPECT_EQ(QuicTime::Delta::Infinite(), sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA));
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA));
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(8));
sender_->OnIncomingAck(1, kMaxPacketSize, rtt_);
sender_->OnIncomingAck(2, kMaxPacketSize, rtt_);
sender_->OnIncomingAck(3, 600, rtt_);
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
}

TEST_F(FixRateTest, FixRatePacing) {
Expand All @@ -96,15 +96,15 @@ TEST_F(FixRateTest, FixRatePacing) {
QuicPacketSequenceNumber sequence_number = 0;
for (int i = 0; i < num_packets; i += 2) {
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
sender_->SentPacket(clock_.Now(), sequence_number++, packet_size,
NOT_RETRANSMISSION);
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
sender_->SentPacket(clock_.Now(), sequence_number++, packet_size,
NOT_RETRANSMISSION);
QuicTime::Delta advance_time = sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA);
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA);
clock_.AdvanceTime(advance_time);
sender_->OnIncomingAck(sequence_number - 1, packet_size, rtt_);
sender_->OnIncomingAck(sequence_number - 2, packet_size, rtt_);
Expand Down
11 changes: 7 additions & 4 deletions net/quic/congestion_control/quic_congestion_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class QuicCongestionManagerTest : public ::testing::Test {
void SetUpCongestionType(CongestionFeedbackType congestion_type) {
manager_.reset(new QuicCongestionManagerPeer(&clock_, congestion_type));
}

static const HasRetransmittableData kIgnored = HAS_RETRANSMITTABLE_DATA;

MockClock clock_;
scoped_ptr<QuicCongestionManagerPeer> manager_;
};
Expand All @@ -55,10 +58,10 @@ TEST_F(QuicCongestionManagerTest, Bandwidth) {

for (int i = 1; i <= 100; ++i) {
QuicTime::Delta advance_time = manager_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA);
clock_.Now(), NOT_RETRANSMISSION, kIgnored);
clock_.AdvanceTime(advance_time);
EXPECT_TRUE(manager_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero());
manager_->SentPacket(i, clock_.Now(), 1000, NOT_RETRANSMISSION);
// Ack the packet we sent.
ack.received_info.largest_observed = i;
Expand All @@ -83,7 +86,7 @@ TEST_F(QuicCongestionManagerTest, BandwidthWith1SecondGap) {
++sequence_number) {
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10));
EXPECT_TRUE(manager_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero());
manager_->SentPacket(
sequence_number, clock_.Now(), 1000, NOT_RETRANSMISSION);
// Ack the packet we sent.
Expand All @@ -101,7 +104,7 @@ TEST_F(QuicCongestionManagerTest, BandwidthWith1SecondGap) {
EXPECT_TRUE(manager_->SentBandwidth(clock_.Now()).IsZero());
for (int i = 1; i <= 150; ++i) {
EXPECT_TRUE(manager_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero());
manager_->SentPacket(i + 100, clock_.Now(), 1000, NOT_RETRANSMISSION);
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10));
// Ack the packet we sent.
Expand Down
5 changes: 3 additions & 2 deletions net/quic/congestion_control/tcp_cubic_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void TcpCubicSender::SentPacket(QuicTime /*sent_time*/,
QuicByteCount bytes,
Retransmission is_retransmission) {
bytes_in_flight_ += bytes;
if (!is_retransmission && update_end_sequence_number_) {
if (is_retransmission == NOT_RETRANSMISSION && update_end_sequence_number_) {
end_sequence_number_ = sequence_number;
if (AvailableCongestionWindow() == 0) {
update_end_sequence_number_ = false;
Expand All @@ -105,7 +105,8 @@ QuicTime::Delta TcpCubicSender::TimeUntilSend(
QuicTime now,
Retransmission is_retransmission,
HasRetransmittableData has_retransmittable_data) {
if (is_retransmission || !has_retransmittable_data) {
if (is_retransmission == IS_RETRANSMISSION ||
has_retransmittable_data == NO_RETRANSMITTABLE_DATA) {
// For TCP we can always send a retransmission and/or an ACK immediately.
return QuicTime::Delta::Zero();
}
Expand Down
22 changes: 11 additions & 11 deletions net/quic/congestion_control/tcp_cubic_sender_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TcpCubicSenderTest : public ::testing::Test {
bytes_to_send -= bytes_in_packet;
if (bytes_to_send > 0) {
EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), NOT_RETRANSMISSION,
NO_RETRANSMITTABLE_DATA).IsZero());
HAS_RETRANSMITTABLE_DATA).IsZero());
}
}
}
Expand Down Expand Up @@ -75,35 +75,35 @@ TEST_F(TcpCubicSenderTest, SimpleSender) {
sender_->AvailableCongestionWindow());
// At startup make sure we can send.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
// Get default QuicCongestionFeedbackFrame from receiver.
ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
fake_bandwidth_, not_used_);
// Make sure we can send.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
// And that window is un-affected.
EXPECT_EQ(kDefaultWindowTCP, sender_->AvailableCongestionWindow());

// A retransmitt should always retun 0.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), IS_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), IS_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
}

TEST_F(TcpCubicSenderTest, ExponentialSlowStart) {
const int kNumberOfAck = 20;
QuicCongestionFeedbackFrame feedback;
// At startup make sure we can send.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
// Get default QuicCongestionFeedbackFrame from receiver.
ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
fake_bandwidth_, not_used_);
// Make sure we can send.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());

for (int n = 0; n < kNumberOfAck; ++n) {
// Send our full congestion window.
Expand All @@ -125,14 +125,14 @@ TEST_F(TcpCubicSenderTest, SlowStartAckTrain) {
QuicCongestionFeedbackFrame feedback;
// At startup make sure we can send.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
// Get default QuicCongestionFeedbackFrame from receiver.
ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
fake_bandwidth_, not_used_);
// Make sure we can send.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());

for (int n = 0; n < kNumberOfAck; ++n) {
// Send our full congestion window.
Expand Down Expand Up @@ -168,14 +168,14 @@ TEST_F(TcpCubicSenderTest, SlowStartPacketLoss) {
QuicCongestionFeedbackFrame feedback;
// At startup make sure we can send.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
// Get default QuicCongestionFeedbackFrame from receiver.
ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
fake_bandwidth_, not_used_);
// Make sure we can send.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());

for (int i = 0; i < kNumberOfAck; ++i) {
// Send our full congestion window.
Expand All @@ -191,7 +191,7 @@ TEST_F(TcpCubicSenderTest, SlowStartPacketLoss) {

// Make sure that we should not send right now.
EXPECT_TRUE(sender_->TimeUntilSend(
clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsInfinite());
clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsInfinite());

// We should now have fallen out of slow start.
// We expect window to be cut in half.
Expand Down
38 changes: 17 additions & 21 deletions net/quic/crypto/aes_128_gcm_decrypter_openssl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ const size_t kAuthTagSize = 16;

} // namespace

Aes128GcmDecrypter::Aes128GcmDecrypter() {
}
Aes128GcmDecrypter::Aes128GcmDecrypter() {}

// static
bool Aes128GcmDecrypter::IsSupported() {
return true;
}
bool Aes128GcmDecrypter::IsSupported() { return true; }

bool Aes128GcmDecrypter::SetKey(StringPiece key) {
DCHECK_EQ(key.size(), sizeof(key_));
Expand Down Expand Up @@ -63,8 +60,7 @@ bool Aes128GcmDecrypter::Decrypt(StringPiece nonce,
ScopedEVPCipherCtx ctx;

// Set the cipher type and the key. The IV (nonce) is set below.
if (EVP_DecryptInit_ex(ctx.get(), EVP_aes_128_gcm(), NULL, key_,
NULL) == 0) {
if (EVP_DecryptInit_ex(ctx.get(), EVP_aes_128_gcm(), NULL, key_, NULL) == 0) {
return false;
}

Expand All @@ -74,16 +70,16 @@ bool Aes128GcmDecrypter::Decrypt(StringPiece nonce,
return false;
}
// Set the IV (nonce).
if (EVP_DecryptInit_ex(ctx.get(), NULL, NULL, NULL,
reinterpret_cast<const unsigned char*>(
nonce.data())) == 0) {
if (EVP_DecryptInit_ex(
ctx.get(), NULL, NULL, NULL,
reinterpret_cast<const unsigned char*>(nonce.data())) == 0) {
return false;
}

// Set the authentication tag.
if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_TAG, kAuthTagSize,
const_cast<char*>(ciphertext.data()) +
plaintext_size) == 0) {
if (EVP_CIPHER_CTX_ctrl(
ctx.get(), EVP_CTRL_GCM_SET_TAG, kAuthTagSize,
const_cast<char*>(ciphertext.data()) + plaintext_size) == 0) {
return false;
}

Expand All @@ -92,18 +88,18 @@ bool Aes128GcmDecrypter::Decrypt(StringPiece nonce,
if (!associated_data.empty()) {
// Set the associated data. The second argument (output buffer) must be
// NULL.
if (EVP_DecryptUpdate(ctx.get(), NULL, &len,
reinterpret_cast<const unsigned char*>(
associated_data.data()),
associated_data.size()) == 0) {
if (EVP_DecryptUpdate(
ctx.get(), NULL, &len,
reinterpret_cast<const unsigned char*>(associated_data.data()),
associated_data.size()) == 0) {
return false;
}
}

if (EVP_DecryptUpdate(ctx.get(), output, &len,
reinterpret_cast<const unsigned char*>(
ciphertext.data()),
plaintext_size) == 0) {
if (EVP_DecryptUpdate(
ctx.get(), output, &len,
reinterpret_cast<const unsigned char*>(ciphertext.data()),
plaintext_size) == 0) {
return false;
}
output += len;
Expand Down
29 changes: 12 additions & 17 deletions net/quic/crypto/aes_128_gcm_decrypter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,15 @@ TEST(Aes128GcmDecrypterTest, Decrypt) {
const TestGroupInfo& test_info = test_group_info[i];
for (size_t j = 0; test_vector[j].key != NULL; j++) {
// Decode the test vector.
ASSERT_TRUE(DecodeHexString(test_vector[j].key, key, &key_len,
sizeof(key)));
ASSERT_TRUE(DecodeHexString(test_vector[j].iv, iv, &iv_len,
sizeof(iv)));
ASSERT_TRUE(DecodeHexString(test_vector[j].ct, ct, &ct_len,
sizeof(ct)));
ASSERT_TRUE(DecodeHexString(test_vector[j].aad, aad, &aad_len,
sizeof(aad)));
ASSERT_TRUE(DecodeHexString(test_vector[j].tag, tag, &tag_len,
sizeof(tag)));
ASSERT_TRUE(DecodeHexString(test_vector[j].pt, pt, &pt_len,
sizeof(pt)));
ASSERT_TRUE(
DecodeHexString(test_vector[j].key, key, &key_len, sizeof(key)));
ASSERT_TRUE(DecodeHexString(test_vector[j].iv, iv, &iv_len, sizeof(iv)));
ASSERT_TRUE(DecodeHexString(test_vector[j].ct, ct, &ct_len, sizeof(ct)));
ASSERT_TRUE(
DecodeHexString(test_vector[j].aad, aad, &aad_len, sizeof(aad)));
ASSERT_TRUE(
DecodeHexString(test_vector[j].tag, tag, &tag_len, sizeof(tag)));
ASSERT_TRUE(DecodeHexString(test_vector[j].pt, pt, &pt_len, sizeof(pt)));

// The test vector's lengths should look sane. Note that the lengths
// in |test_info| are in bits.
Expand All @@ -365,18 +362,16 @@ TEST(Aes128GcmDecrypterTest, Decrypt) {
&decrypter, StringPiece(iv, iv_len),
// OpenSSL fails if NULL is set as the AAD, as opposed to a
// zero-length, non-NULL pointer.
StringPiece(aad_len ? aad : NULL, aad_len),
ciphertext));
StringPiece(aad_len ? aad : NULL, aad_len), ciphertext));
if (!decrypted.get()) {
EXPECT_EQ((size_t)-1, pt_len);
continue;
}
ASSERT_NE((size_t)-1, pt_len);

ASSERT_EQ(pt_len, decrypted->length());
test::CompareCharArraysWithHexError(
"plaintext", decrypted->data(), pt_len,
pt, pt_len);
test::CompareCharArraysWithHexError("plaintext", decrypted->data(),
pt_len, pt, pt_len);
}
}
}
Expand Down
Loading

0 comments on commit 2532de1

Please sign in to comment.