| 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_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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool AeadBaseEncrypter::Encrypt(StringPiece nonce, | 76 bool AeadBaseEncrypter::Encrypt(StringPiece nonce, |
| 77 StringPiece associated_data, | 77 StringPiece associated_data, |
| 78 StringPiece plaintext, | 78 StringPiece plaintext, |
| 79 unsigned char* output) { | 79 unsigned char* output) { |
| 80 if (nonce.size() != nonce_prefix_size_ + sizeof(QuicPacketSequenceNumber)) { | 80 if (nonce.size() != nonce_prefix_size_ + sizeof(QuicPacketSequenceNumber)) { |
| 81 return false; | 81 return false; |
| 82 } | 82 } |
| 83 | 83 |
| 84 ssize_t len = EVP_AEAD_CTX_seal( | 84 size_t len; |
| 85 ctx_.get(), output, plaintext.size() + auth_tag_size_, | 85 if (!EVP_AEAD_CTX_seal( |
| 86 reinterpret_cast<const uint8_t*>(nonce.data()), nonce.size(), | 86 ctx_.get(), |
| 87 reinterpret_cast<const uint8_t*>(plaintext.data()), plaintext.size(), | 87 output, |
| 88 reinterpret_cast<const uint8_t*>(associated_data.data()), | 88 &len, |
| 89 associated_data.size()); | 89 plaintext.size() + auth_tag_size_, |
| 90 | 90 reinterpret_cast<const uint8_t*>(nonce.data()), |
| 91 if (len < 0) { | 91 nonce.size(), |
| 92 reinterpret_cast<const uint8_t*>(plaintext.data()), |
| 93 plaintext.size(), |
| 94 reinterpret_cast<const uint8_t*>(associated_data.data()), |
| 95 associated_data.size())) { |
| 92 DLogOpenSslErrors(); | 96 DLogOpenSslErrors(); |
| 93 return false; | 97 return false; |
| 94 } | 98 } |
| 95 | 99 |
| 96 return true; | 100 return true; |
| 97 } | 101 } |
| 98 | 102 |
| 99 QuicData* AeadBaseEncrypter::EncryptPacket( | 103 QuicData* AeadBaseEncrypter::EncryptPacket( |
| 100 QuicPacketSequenceNumber sequence_number, | 104 QuicPacketSequenceNumber sequence_number, |
| 101 StringPiece associated_data, | 105 StringPiece associated_data, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 143 |
| 140 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { | 144 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { |
| 141 if (nonce_prefix_size_ == 0) { | 145 if (nonce_prefix_size_ == 0) { |
| 142 return StringPiece(); | 146 return StringPiece(); |
| 143 } | 147 } |
| 144 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), | 148 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), |
| 145 nonce_prefix_size_); | 149 nonce_prefix_size_); |
| 146 } | 150 } |
| 147 | 151 |
| 148 } // namespace net | 152 } // namespace net |
| OLD | NEW |