1 // Copyright 2020 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 /////////////////////////////////////////////////////////////////////////////// 16 17 #ifndef TINK_AEAD_INTERNAL_CORD_AES_GCM_BORINGSSL_H_ 18 #define TINK_AEAD_INTERNAL_CORD_AES_GCM_BORINGSSL_H_ 19 20 #include <memory> 21 #include <utility> 22 23 #include "openssl/evp.h" 24 #include "tink/aead/cord_aead.h" 25 #include "tink/internal/ssl_unique_ptr.h" 26 #include "tink/util/secret_data.h" 27 #include "tink/util/statusor.h" 28 29 namespace crypto { 30 namespace tink { 31 namespace internal { 32 33 class CordAesGcmBoringSsl : public CordAead { 34 public: 35 static crypto::tink::util::StatusOr<std::unique_ptr<CordAead>> New( 36 const util::SecretData& key_value); 37 38 crypto::tink::util::StatusOr<absl::Cord> Encrypt( 39 absl::Cord plaintext, absl::Cord associated_data) const override; 40 41 crypto::tink::util::StatusOr<absl::Cord> Decrypt( 42 absl::Cord ciphertext, absl::Cord associated_data) const override; 43 44 private: CordAesGcmBoringSsl(internal::SslUniquePtr<EVP_CIPHER_CTX> partial_context,const util::SecretData & key)45 explicit CordAesGcmBoringSsl( 46 internal::SslUniquePtr<EVP_CIPHER_CTX> partial_context, 47 const util::SecretData& key) 48 : partial_context_(std::move(partial_context)), key_(key) {} 49 50 // Partially-initialized EVP_CIPHER_CTX context that is copied for every 51 // Encrypt/Decrypt operation. 52 internal::SslUniquePtr<EVP_CIPHER_CTX> partial_context_; 53 util::SecretData key_; 54 }; 55 56 } // namespace internal 57 } // namespace tink 58 } // namespace crypto 59 60 #endif // TINK_AEAD_INTERNAL_CORD_AES_GCM_BORINGSSL_H_ 61