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