| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "crypto/aead_openssl.h" | 5 #include "crypto/aead_openssl.h" |
| 6 | 6 |
| 7 #if defined(USE_OPENSSL) | 7 #if defined(USE_OPENSSL) |
| 8 | 8 |
| 9 #include <openssl/aes.h> | 9 #include <openssl/aes.h> |
| 10 #include <openssl/evp.h> | 10 #include <openssl/evp.h> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 reinterpret_cast<const uint8*>(key_->data()), | 46 reinterpret_cast<const uint8*>(key_->data()), |
| 47 key_->size(), EVP_AEAD_DEFAULT_TAG_LENGTH, nullptr)) { | 47 key_->size(), EVP_AEAD_DEFAULT_TAG_LENGTH, nullptr)) { |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 | 50 |
| 51 std::string result; | 51 std::string result; |
| 52 const size_t max_output_length = | 52 const size_t max_output_length = |
| 53 EVP_AEAD_max_overhead(aead_) + plaintext.size(); | 53 EVP_AEAD_max_overhead(aead_) + plaintext.size(); |
| 54 size_t output_length; | 54 size_t output_length; |
| 55 uint8* out_ptr = | 55 uint8* out_ptr = |
| 56 reinterpret_cast<uint8*>(WriteInto(&result, max_output_length + 1)); | 56 reinterpret_cast<uint8*>(base::WriteInto(&result, max_output_length + 1)); |
| 57 | 57 |
| 58 if (!EVP_AEAD_CTX_seal( | 58 if (!EVP_AEAD_CTX_seal( |
| 59 &ctx, out_ptr, &output_length, max_output_length, | 59 &ctx, out_ptr, &output_length, max_output_length, |
| 60 reinterpret_cast<const uint8*>(nonce.data()), nonce.size(), | 60 reinterpret_cast<const uint8*>(nonce.data()), nonce.size(), |
| 61 reinterpret_cast<const uint8*>(plaintext.data()), plaintext.size(), | 61 reinterpret_cast<const uint8*>(plaintext.data()), plaintext.size(), |
| 62 reinterpret_cast<const uint8*>(additional_data.data()), | 62 reinterpret_cast<const uint8*>(additional_data.data()), |
| 63 additional_data.size())) { | 63 additional_data.size())) { |
| 64 EVP_AEAD_CTX_cleanup(&ctx); | 64 EVP_AEAD_CTX_cleanup(&ctx); |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 84 if (!EVP_AEAD_CTX_init(&ctx, aead_, | 84 if (!EVP_AEAD_CTX_init(&ctx, aead_, |
| 85 reinterpret_cast<const uint8*>(key_->data()), | 85 reinterpret_cast<const uint8*>(key_->data()), |
| 86 key_->size(), EVP_AEAD_DEFAULT_TAG_LENGTH, nullptr)) { | 86 key_->size(), EVP_AEAD_DEFAULT_TAG_LENGTH, nullptr)) { |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 89 | 89 |
| 90 std::string result; | 90 std::string result; |
| 91 const size_t max_output_length = ciphertext.size(); | 91 const size_t max_output_length = ciphertext.size(); |
| 92 size_t output_length; | 92 size_t output_length; |
| 93 uint8* out_ptr = | 93 uint8* out_ptr = |
| 94 reinterpret_cast<uint8*>(WriteInto(&result, max_output_length + 1)); | 94 reinterpret_cast<uint8*>(base::WriteInto(&result, max_output_length + 1)); |
| 95 | 95 |
| 96 if (!EVP_AEAD_CTX_open( | 96 if (!EVP_AEAD_CTX_open( |
| 97 &ctx, out_ptr, &output_length, max_output_length, | 97 &ctx, out_ptr, &output_length, max_output_length, |
| 98 reinterpret_cast<const uint8*>(nonce.data()), nonce.size(), | 98 reinterpret_cast<const uint8*>(nonce.data()), nonce.size(), |
| 99 reinterpret_cast<const uint8*>(ciphertext.data()), ciphertext.size(), | 99 reinterpret_cast<const uint8*>(ciphertext.data()), ciphertext.size(), |
| 100 reinterpret_cast<const uint8*>(additional_data.data()), | 100 reinterpret_cast<const uint8*>(additional_data.data()), |
| 101 additional_data.size())) { | 101 additional_data.size())) { |
| 102 EVP_AEAD_CTX_cleanup(&ctx); | 102 EVP_AEAD_CTX_cleanup(&ctx); |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 116 return EVP_AEAD_key_length(aead_); | 116 return EVP_AEAD_key_length(aead_); |
| 117 } | 117 } |
| 118 | 118 |
| 119 size_t Aead::NonceLength() const { | 119 size_t Aead::NonceLength() const { |
| 120 return EVP_AEAD_nonce_length(aead_); | 120 return EVP_AEAD_nonce_length(aead_); |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace | 123 } // namespace |
| 124 | 124 |
| 125 #endif | 125 #endif |
| OLD | NEW |