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

Side by Side Diff: net/quic/crypto/aead_base_decrypter_nss.cc

Issue 1660593004: Landing Recent QUIC changes until 01/28/2016 18:41 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0202
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
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/aead_base_decrypter.h" 5 #include "net/quic/crypto/aead_base_decrypter.h"
6 6
7 #include <pk11pub.h> 7 #include <pk11pub.h>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "crypto/scoped_nss_types.h" 10 #include "crypto/scoped_nss_types.h"
11 #include "net/quic/quic_flags.h" 11 #include "net/quic/quic_flags.h"
12 #include "net/quic/quic_utils.h"
12 13
13 using base::StringPiece; 14 using base::StringPiece;
14 15
15 namespace net { 16 namespace net {
16 17
17 AeadBaseDecrypter::AeadBaseDecrypter(CK_MECHANISM_TYPE aead_mechanism, 18 AeadBaseDecrypter::AeadBaseDecrypter(CK_MECHANISM_TYPE aead_mechanism,
18 size_t key_size, 19 size_t key_size,
19 size_t auth_tag_size, 20 size_t auth_tag_size,
20 size_t nonce_prefix_size) 21 size_t nonce_prefix_size)
21 : aead_mechanism_(aead_mechanism), 22 : aead_mechanism_(aead_mechanism),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 size_t max_output_length) { 56 size_t max_output_length) {
56 if (ciphertext.length() < auth_tag_size_) { 57 if (ciphertext.length() < auth_tag_size_) {
57 return false; 58 return false;
58 } 59 }
59 60
60 uint8_t nonce[sizeof(nonce_prefix_) + sizeof(packet_number)]; 61 uint8_t nonce[sizeof(nonce_prefix_) + sizeof(packet_number)];
61 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); 62 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number);
62 DCHECK_LE(nonce_size, sizeof(nonce)); 63 DCHECK_LE(nonce_size, sizeof(nonce));
63 memcpy(nonce, nonce_prefix_, nonce_prefix_size_); 64 memcpy(nonce, nonce_prefix_, nonce_prefix_size_);
64 if (FLAGS_quic_include_path_id_in_iv) { 65 if (FLAGS_quic_include_path_id_in_iv) {
65 // Setting the nonce below relies on QuicPathId and QuicPacketNumber being
66 // specific sizes.
67 static_assert(sizeof(path_id) == 1, "Size of QuicPathId changed.");
68 static_assert(sizeof(packet_number) == 8,
69 "Size of QuicPacketNumber changed.");
70 // Use path_id and lower 7 bytes of packet_number as lower 8 bytes of nonce.
71 uint64_t path_id_packet_number = 66 uint64_t path_id_packet_number =
72 (static_cast<uint64_t>(path_id) << 56) | packet_number; 67 QuicUtils::PackPathIdAndPacketNumber(path_id, packet_number);
73 DCHECK(path_id != kDefaultPathId || path_id_packet_number == packet_number);
74 memcpy(nonce + nonce_prefix_size_, &path_id_packet_number, 68 memcpy(nonce + nonce_prefix_size_, &path_id_packet_number,
75 sizeof(path_id_packet_number)); 69 sizeof(path_id_packet_number));
76 } else { 70 } else {
77 memcpy(nonce + nonce_prefix_size_, &packet_number, sizeof(packet_number)); 71 memcpy(nonce + nonce_prefix_size_, &packet_number, sizeof(packet_number));
78 } 72 }
79 73
80 // NSS 3.14.x incorrectly requires an output buffer at least as long as 74 // NSS 3.14.x incorrectly requires an output buffer at least as long as
81 // the ciphertext (NSS bug 75 // the ciphertext (NSS bug
82 // https://bugzilla.mozilla.org/show_bug.cgi?id= 853674). Fortunately 76 // https://bugzilla.mozilla.org/show_bug.cgi?id= 853674). Fortunately
83 // QuicDecrypter::Decrypt() specifies that |output| must be as long as 77 // QuicDecrypter::Decrypt() specifies that |output| must be as long as
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 130
137 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { 131 StringPiece AeadBaseDecrypter::GetNoncePrefix() const {
138 if (nonce_prefix_size_ == 0) { 132 if (nonce_prefix_size_ == 0) {
139 return StringPiece(); 133 return StringPiece();
140 } 134 }
141 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), 135 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_),
142 nonce_prefix_size_); 136 nonce_prefix_size_);
143 } 137 }
144 138
145 } // namespace net 139 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/time_loss_algorithm_test.cc ('k') | net/quic/crypto/aead_base_decrypter_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698