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 if (!EVP_AEAD_CTX_open( | 89 ssize_t len = EVP_AEAD_CTX_open( |
90 ctx_.get(), output, output_length, ciphertext.size(), | 90 ctx_.get(), output, 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) { |
95 // Because QuicFramer does trial decryption, decryption errors are expected | 97 // Because QuicFramer does trial decryption, decryption errors are expected |
96 // when encryption level changes. So we don't log decryption errors. | 98 // when encryption level changes. So we don't log decryption errors. |
97 ClearOpenSslErrors(); | 99 ClearOpenSslErrors(); |
98 return false; | 100 return false; |
99 } | 101 } |
100 | 102 |
| 103 *output_length = len; |
101 return true; | 104 return true; |
102 } | 105 } |
103 | 106 |
104 QuicData* AeadBaseDecrypter::DecryptPacket( | 107 QuicData* AeadBaseDecrypter::DecryptPacket( |
105 QuicPacketSequenceNumber sequence_number, | 108 QuicPacketSequenceNumber sequence_number, |
106 StringPiece associated_data, | 109 StringPiece associated_data, |
107 StringPiece ciphertext) { | 110 StringPiece ciphertext) { |
108 if (ciphertext.length() < auth_tag_size_) { | 111 if (ciphertext.length() < auth_tag_size_) { |
109 return NULL; | 112 return NULL; |
110 } | 113 } |
(...skipping 20 matching lines...) Expand all Loading... |
131 | 134 |
132 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { | 135 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { |
133 if (nonce_prefix_size_ == 0) { | 136 if (nonce_prefix_size_ == 0) { |
134 return StringPiece(); | 137 return StringPiece(); |
135 } | 138 } |
136 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), | 139 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), |
137 nonce_prefix_size_); | 140 nonce_prefix_size_); |
138 } | 141 } |
139 | 142 |
140 } // namespace net | 143 } // namespace net |
OLD | NEW |