| OLD | NEW |
| 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/core/crypto/aead_base_encrypter.h" | 5 #include "net/quic/core/crypto/aead_base_encrypter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "net/quic/core/quic_utils.h" | 9 #include "net/quic/core/quic_utils.h" |
| 10 #include "net/quic/platform/api/quic_aligned.h" | 10 #include "net/quic/platform/api/quic_aligned.h" |
| 11 #include "net/quic/platform/api/quic_logging.h" | |
| 12 #include "third_party/boringssl/src/include/openssl/err.h" | 11 #include "third_party/boringssl/src/include/openssl/err.h" |
| 13 #include "third_party/boringssl/src/include/openssl/evp.h" | 12 #include "third_party/boringssl/src/include/openssl/evp.h" |
| 14 | 13 |
| 15 using base::StringPiece; | 14 using base::StringPiece; |
| 16 | 15 |
| 17 namespace net { | 16 namespace net { |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 // The maximum size in bytes of the nonce, including 8 bytes of sequence number. | 20 // The maximum size in bytes of the nonce, including 8 bytes of sequence number. |
| 22 // ChaCha20 uses only the 8 byte sequence number and AES-GCM uses 12 bytes. | 21 // ChaCha20 uses only the 8 byte sequence number and AES-GCM uses 12 bytes. |
| 23 const size_t kMaxNonceSize = 12; | 22 const size_t kMaxNonceSize = 12; |
| 24 | 23 |
| 25 // In debug builds only, log OpenSSL error stack. Then clear OpenSSL error | 24 // In debug builds only, log OpenSSL error stack. Then clear OpenSSL error |
| 26 // stack. | 25 // stack. |
| 27 void DLogOpenSslErrors() { | 26 void DLogOpenSslErrors() { |
| 28 #ifdef NDEBUG | 27 #ifdef NDEBUG |
| 29 while (ERR_get_error()) { | 28 while (ERR_get_error()) { |
| 30 } | 29 } |
| 31 #else | 30 #else |
| 32 while (unsigned long error = ERR_get_error()) { | 31 while (unsigned long error = ERR_get_error()) { |
| 33 char buf[120]; | 32 char buf[120]; |
| 34 ERR_error_string_n(error, buf, arraysize(buf)); | 33 ERR_error_string_n(error, buf, arraysize(buf)); |
| 35 QUIC_DLOG(ERROR) << "OpenSSL error: " << buf; | 34 DLOG(ERROR) << "OpenSSL error: " << buf; |
| 36 } | 35 } |
| 37 #endif | 36 #endif |
| 38 } | 37 } |
| 39 | 38 |
| 40 } // namespace | 39 } // namespace |
| 41 | 40 |
| 42 AeadBaseEncrypter::AeadBaseEncrypter(const EVP_AEAD* aead_alg, | 41 AeadBaseEncrypter::AeadBaseEncrypter(const EVP_AEAD* aead_alg, |
| 43 size_t key_size, | 42 size_t key_size, |
| 44 size_t auth_tag_size, | 43 size_t auth_tag_size, |
| 45 size_t nonce_prefix_size) | 44 size_t nonce_prefix_size) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 153 |
| 155 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { | 154 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { |
| 156 if (nonce_prefix_size_ == 0) { | 155 if (nonce_prefix_size_ == 0) { |
| 157 return StringPiece(); | 156 return StringPiece(); |
| 158 } | 157 } |
| 159 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), | 158 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), |
| 160 nonce_prefix_size_); | 159 nonce_prefix_size_); |
| 161 } | 160 } |
| 162 | 161 |
| 163 } // namespace net | 162 } // namespace net |
| OLD | NEW |