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

Side by Side Diff: net/quic/crypto/aead_base_encrypter_openssl.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_encrypter.h" 5 #include "net/quic/crypto/aead_base_encrypter.h"
6 6
7 #include <openssl/err.h> 7 #include <openssl/err.h>
8 #include <openssl/evp.h> 8 #include <openssl/evp.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 bool AeadBaseEncrypter::SetKey(StringPiece key) { 49 bool AeadBaseEncrypter::SetKey(StringPiece key) {
50 DCHECK_EQ(key.size(), key_size_); 50 DCHECK_EQ(key.size(), key_size_);
51 if (key.size() != key_size_) { 51 if (key.size() != key_size_) {
52 return false; 52 return false;
53 } 53 }
54 memcpy(key_, key.data(), key.size()); 54 memcpy(key_, key.data(), key.size());
55 55
56 EVP_AEAD_CTX_cleanup(ctx_.get()); 56 EVP_AEAD_CTX_cleanup(ctx_.get());
57 57
58 if (!EVP_AEAD_CTX_init(ctx_.get(), aead_alg_, key_, key_size_, 58 if (!EVP_AEAD_CTX_init(ctx_.get(), aead_alg_, key_, key_size_,
59 auth_tag_size_, NULL)) { 59 auth_tag_size_, nullptr)) {
60 DLogOpenSslErrors(); 60 DLogOpenSslErrors();
61 return false; 61 return false;
62 } 62 }
63 63
64 return true; 64 return true;
65 } 65 }
66 66
67 bool AeadBaseEncrypter::SetNoncePrefix(StringPiece nonce_prefix) { 67 bool AeadBaseEncrypter::SetNoncePrefix(StringPiece nonce_prefix) {
68 DCHECK_EQ(nonce_prefix.size(), nonce_prefix_size_); 68 DCHECK_EQ(nonce_prefix.size(), nonce_prefix_size_);
69 if (nonce_prefix.size() != nonce_prefix_size_) { 69 if (nonce_prefix.size() != nonce_prefix_size_) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // TODO(ianswett): Introduce a check to ensure that we don't encrypt with the 110 // TODO(ianswett): Introduce a check to ensure that we don't encrypt with the
111 // same sequence number twice. 111 // same sequence number twice.
112 uint8 nonce[sizeof(nonce_prefix_) + sizeof(sequence_number)]; 112 uint8 nonce[sizeof(nonce_prefix_) + sizeof(sequence_number)];
113 const size_t nonce_size = nonce_prefix_size_ + sizeof(sequence_number); 113 const size_t nonce_size = nonce_prefix_size_ + sizeof(sequence_number);
114 DCHECK_LE(nonce_size, sizeof(nonce)); 114 DCHECK_LE(nonce_size, sizeof(nonce));
115 memcpy(nonce, nonce_prefix_, nonce_prefix_size_); 115 memcpy(nonce, nonce_prefix_, nonce_prefix_size_);
116 memcpy(nonce + nonce_prefix_size_, &sequence_number, sizeof(sequence_number)); 116 memcpy(nonce + nonce_prefix_size_, &sequence_number, sizeof(sequence_number));
117 if (!Encrypt(StringPiece(reinterpret_cast<char*>(nonce), nonce_size), 117 if (!Encrypt(StringPiece(reinterpret_cast<char*>(nonce), nonce_size),
118 associated_data, plaintext, 118 associated_data, plaintext,
119 reinterpret_cast<unsigned char*>(ciphertext.get()))) { 119 reinterpret_cast<unsigned char*>(ciphertext.get()))) {
120 return NULL; 120 return nullptr;
121 } 121 }
122 122
123 return new QuicData(ciphertext.release(), ciphertext_size, true); 123 return new QuicData(ciphertext.release(), ciphertext_size, true);
124 } 124 }
125 125
126 size_t AeadBaseEncrypter::GetKeySize() const { return key_size_; } 126 size_t AeadBaseEncrypter::GetKeySize() const { return key_size_; }
127 127
128 size_t AeadBaseEncrypter::GetNoncePrefixSize() const { 128 size_t AeadBaseEncrypter::GetNoncePrefixSize() const {
129 return nonce_prefix_size_; 129 return nonce_prefix_size_;
130 } 130 }
(...skipping 12 matching lines...) Expand all
143 143
144 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { 144 StringPiece AeadBaseEncrypter::GetNoncePrefix() const {
145 if (nonce_prefix_size_ == 0) { 145 if (nonce_prefix_size_ == 0) {
146 return StringPiece(); 146 return StringPiece();
147 } 147 }
148 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), 148 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_),
149 nonce_prefix_size_); 149 nonce_prefix_size_);
150 } 150 }
151 151
152 } // namespace net 152 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/aead_base_encrypter_nss.cc ('k') | net/quic/crypto/aes_128_gcm_12_decrypter_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698