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

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

Issue 612323013: QUIC - (no behavior change) s/NULL/nullptr/g in .../quic/... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // workaround. Remove this when we require NSS 3.15. 76 // workaround. Remove this when we require NSS 3.15.
77 CK_MECHANISM_TYPE key_mechanism = aead_mechanism_; 77 CK_MECHANISM_TYPE key_mechanism = aead_mechanism_;
78 if (key_mechanism == CKM_AES_GCM) { 78 if (key_mechanism == CKM_AES_GCM) {
79 key_mechanism = CKM_AES_ECB; 79 key_mechanism = CKM_AES_ECB;
80 } 80 }
81 81
82 // The exact value of the |origin| argument doesn't matter to NSS as long as 82 // The exact value of the |origin| argument doesn't matter to NSS as long as
83 // it's not PK11_OriginFortezzaHack, so pass PK11_OriginUnwrap as a 83 // it's not PK11_OriginFortezzaHack, so pass PK11_OriginUnwrap as a
84 // placeholder. 84 // placeholder.
85 crypto::ScopedPK11SymKey aead_key(PK11_ImportSymKey( 85 crypto::ScopedPK11SymKey aead_key(PK11_ImportSymKey(
86 slot, key_mechanism, PK11_OriginUnwrap, CKA_DECRYPT, &key_item, NULL)); 86 slot, key_mechanism, PK11_OriginUnwrap, CKA_DECRYPT, &key_item, nullptr));
87 PK11_FreeSlot(slot); 87 PK11_FreeSlot(slot);
88 slot = NULL; 88 slot = nullptr;
89 if (!aead_key) { 89 if (!aead_key) {
90 DVLOG(1) << "PK11_ImportSymKey failed"; 90 DVLOG(1) << "PK11_ImportSymKey failed";
91 return false; 91 return false;
92 } 92 }
93 93
94 AeadParams aead_params = {0}; 94 AeadParams aead_params = {0};
95 FillAeadParams(nonce, associated_data, auth_tag_size_, &aead_params); 95 FillAeadParams(nonce, associated_data, auth_tag_size_, &aead_params);
96 96
97 SECItem param; 97 SECItem param;
98 param.type = siBuffer; 98 param.type = siBuffer;
(...skipping 14 matching lines...) Expand all
113 } 113 }
114 *output_length = output_len; 114 *output_length = output_len;
115 return true; 115 return true;
116 } 116 }
117 117
118 QuicData* AeadBaseDecrypter::DecryptPacket( 118 QuicData* AeadBaseDecrypter::DecryptPacket(
119 QuicPacketSequenceNumber sequence_number, 119 QuicPacketSequenceNumber sequence_number,
120 StringPiece associated_data, 120 StringPiece associated_data,
121 StringPiece ciphertext) { 121 StringPiece ciphertext) {
122 if (ciphertext.length() < auth_tag_size_) { 122 if (ciphertext.length() < auth_tag_size_) {
123 return NULL; 123 return nullptr;
124 } 124 }
125 size_t plaintext_size; 125 size_t plaintext_size;
126 scoped_ptr<char[]> plaintext(new char[ciphertext.length()]); 126 scoped_ptr<char[]> plaintext(new char[ciphertext.length()]);
127 127
128 uint8 nonce[sizeof(nonce_prefix_) + sizeof(sequence_number)]; 128 uint8 nonce[sizeof(nonce_prefix_) + sizeof(sequence_number)];
129 const size_t nonce_size = nonce_prefix_size_ + sizeof(sequence_number); 129 const size_t nonce_size = nonce_prefix_size_ + sizeof(sequence_number);
130 DCHECK_LE(nonce_size, sizeof(nonce)); 130 DCHECK_LE(nonce_size, sizeof(nonce));
131 memcpy(nonce, nonce_prefix_, nonce_prefix_size_); 131 memcpy(nonce, nonce_prefix_, nonce_prefix_size_);
132 memcpy(nonce + nonce_prefix_size_, &sequence_number, sizeof(sequence_number)); 132 memcpy(nonce + nonce_prefix_size_, &sequence_number, sizeof(sequence_number));
133 if (!Decrypt(StringPiece(reinterpret_cast<char*>(nonce), nonce_size), 133 if (!Decrypt(StringPiece(reinterpret_cast<char*>(nonce), nonce_size),
134 associated_data, ciphertext, 134 associated_data, ciphertext,
135 reinterpret_cast<uint8*>(plaintext.get()), 135 reinterpret_cast<uint8*>(plaintext.get()),
136 &plaintext_size)) { 136 &plaintext_size)) {
137 return NULL; 137 return nullptr;
138 } 138 }
139 return new QuicData(plaintext.release(), plaintext_size, true); 139 return new QuicData(plaintext.release(), plaintext_size, true);
140 } 140 }
141 141
142 StringPiece AeadBaseDecrypter::GetKey() const { 142 StringPiece AeadBaseDecrypter::GetKey() const {
143 return StringPiece(reinterpret_cast<const char*>(key_), key_size_); 143 return StringPiece(reinterpret_cast<const char*>(key_), key_size_);
144 } 144 }
145 145
146 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { 146 StringPiece AeadBaseDecrypter::GetNoncePrefix() const {
147 if (nonce_prefix_size_ == 0) { 147 if (nonce_prefix_size_ == 0) {
148 return StringPiece(); 148 return StringPiece();
149 } 149 }
150 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), 150 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_),
151 nonce_prefix_size_); 151 nonce_prefix_size_);
152 } 152 }
153 153
154 } // namespace net 154 } // 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