| 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/crypto/aead_base_decrypter.h" | 5 #include "net/quic/crypto/aead_base_decrypter.h" |
| 6 | 6 |
| 7 #include <openssl/err.h> | 7 #include <openssl/err.h> |
| 8 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 bool AeadBaseDecrypter::Decrypt(StringPiece nonce, | 79 bool AeadBaseDecrypter::Decrypt(StringPiece nonce, |
| 80 StringPiece associated_data, | 80 StringPiece associated_data, |
| 81 StringPiece ciphertext, | 81 StringPiece ciphertext, |
| 82 uint8* output, | 82 uint8* output, |
| 83 size_t* output_length) { | 83 size_t* output_length) { |
| 84 if (ciphertext.length() < auth_tag_size_ || | 84 if (ciphertext.length() < auth_tag_size_ || |
| 85 nonce.size() != nonce_prefix_size_ + sizeof(QuicPacketSequenceNumber)) { | 85 nonce.size() != nonce_prefix_size_ + sizeof(QuicPacketSequenceNumber)) { |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 ssize_t len = EVP_AEAD_CTX_open( | 89 if (!EVP_AEAD_CTX_open( |
| 90 ctx_.get(), output, ciphertext.size(), | 90 ctx_.get(), output, output_length, ciphertext.size(), |
| 91 reinterpret_cast<const uint8_t*>(nonce.data()), nonce.size(), | 91 reinterpret_cast<const uint8_t*>(nonce.data()), nonce.size(), |
| 92 reinterpret_cast<const uint8_t*>(ciphertext.data()), ciphertext.size(), | 92 reinterpret_cast<const uint8_t*>(ciphertext.data()), ciphertext.size(), |
| 93 reinterpret_cast<const uint8_t*>(associated_data.data()), | 93 reinterpret_cast<const uint8_t*>(associated_data.data()), |
| 94 associated_data.size()); | 94 associated_data.size())) { |
| 95 | |
| 96 if (len < 0) { | |
| 97 // Because QuicFramer does trial decryption, decryption errors are expected | 95 // Because QuicFramer does trial decryption, decryption errors are expected |
| 98 // when encryption level changes. So we don't log decryption errors. | 96 // when encryption level changes. So we don't log decryption errors. |
| 99 ClearOpenSslErrors(); | 97 ClearOpenSslErrors(); |
| 100 return false; | 98 return false; |
| 101 } | 99 } |
| 102 | 100 |
| 103 *output_length = len; | |
| 104 return true; | 101 return true; |
| 105 } | 102 } |
| 106 | 103 |
| 107 QuicData* AeadBaseDecrypter::DecryptPacket( | 104 QuicData* AeadBaseDecrypter::DecryptPacket( |
| 108 QuicPacketSequenceNumber sequence_number, | 105 QuicPacketSequenceNumber sequence_number, |
| 109 StringPiece associated_data, | 106 StringPiece associated_data, |
| 110 StringPiece ciphertext) { | 107 StringPiece ciphertext) { |
| 111 if (ciphertext.length() < auth_tag_size_) { | 108 if (ciphertext.length() < auth_tag_size_) { |
| 112 return NULL; | 109 return NULL; |
| 113 } | 110 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 134 | 131 |
| 135 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { | 132 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { |
| 136 if (nonce_prefix_size_ == 0) { | 133 if (nonce_prefix_size_ == 0) { |
| 137 return StringPiece(); | 134 return StringPiece(); |
| 138 } | 135 } |
| 139 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), | 136 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), |
| 140 nonce_prefix_size_); | 137 nonce_prefix_size_); |
| 141 } | 138 } |
| 142 | 139 |
| 143 } // namespace net | 140 } // namespace net |
| OLD | NEW |