1 // Copyright 2021 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_ZERO_COPY_AES_GCM_BORINGSSL_H_ 18 #define TINK_AEAD_INTERNAL_ZERO_COPY_AES_GCM_BORINGSSL_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <utility> 23 24 #include "absl/base/macros.h" 25 #include "tink/aead/internal/ssl_aead.h" 26 #include "tink/aead/internal/zero_copy_aead.h" 27 #include "tink/util/secret_data.h" 28 #include "tink/util/statusor.h" 29 30 namespace crypto { 31 namespace tink { 32 namespace internal { 33 34 class ZeroCopyAesGcmBoringSsl : public ZeroCopyAead { 35 public: 36 static crypto::tink::util::StatusOr<std::unique_ptr<ZeroCopyAead>> New( 37 const util::SecretData &key); 38 39 int64_t MaxEncryptionSize(int64_t plaintext_size) const override; 40 41 crypto::tink::util::StatusOr<int64_t> Encrypt( 42 absl::string_view plaintext, absl::string_view associated_data, 43 absl::Span<char> buffer) const override; 44 45 int64_t MaxDecryptionSize(int64_t ciphertext_size) const override; 46 47 crypto::tink::util::StatusOr<int64_t> Decrypt( 48 absl::string_view ciphertext, absl::string_view associated_data, 49 absl::Span<char> buffer) const override; 50 51 private: ZeroCopyAesGcmBoringSsl(std::unique_ptr<SslOneShotAead> aead)52 explicit ZeroCopyAesGcmBoringSsl(std::unique_ptr<SslOneShotAead> aead) 53 : aead_(std::move(aead)) {} 54 55 const std::unique_ptr<SslOneShotAead> aead_; 56 }; 57 58 } // namespace internal 59 } // namespace tink 60 } // namespace crypto 61 62 #endif // TINK_AEAD_INTERNAL_ZERO_COPY_AES_GCM_BORINGSSL_H_ 63