1 // Copyright 2018 Google Inc. 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_SUBTLE_XCHACHA20_POLY1305_BORINGSSL_H_ 18 #define TINK_SUBTLE_XCHACHA20_POLY1305_BORINGSSL_H_ 19 20 #include <memory> 21 #include <string> 22 #include <utility> 23 24 #include "absl/strings/string_view.h" 25 #include "tink/aead.h" 26 #include "tink/aead/internal/ssl_aead.h" 27 #include "tink/internal/fips_utils.h" 28 #include "tink/util/secret_data.h" 29 #include "tink/util/status.h" 30 #include "tink/util/statusor.h" 31 32 namespace crypto { 33 namespace tink { 34 namespace subtle { 35 36 class XChacha20Poly1305BoringSsl : public Aead { 37 public: 38 // Constructs a new Aead cipher for XChacha20-Poly1305. 39 // Currently supported key size is 256 bits. 40 // Currently supported nonce size is 24 bytes. 41 // The tag size is fixed to 16 bytes. 42 static crypto::tink::util::StatusOr<std::unique_ptr<Aead>> New( 43 util::SecretData key); 44 45 crypto::tink::util::StatusOr<std::string> Encrypt( 46 absl::string_view plaintext, 47 absl::string_view associated_data) const override; 48 49 crypto::tink::util::StatusOr<std::string> Decrypt( 50 absl::string_view ciphertext, 51 absl::string_view associated_data) const override; 52 53 static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus = 54 crypto::tink::internal::FipsCompatibility::kNotFips; 55 56 private: XChacha20Poly1305BoringSsl(std::unique_ptr<internal::SslOneShotAead> aead)57 explicit XChacha20Poly1305BoringSsl( 58 std::unique_ptr<internal::SslOneShotAead> aead) 59 : aead_(std::move(aead)) {} 60 61 const std::unique_ptr<internal::SslOneShotAead> aead_; 62 }; 63 64 } // namespace subtle 65 } // namespace tink 66 } // namespace crypto 67 68 #endif // TINK_SUBTLE_XCHACHA20_POLY1305_BORINGSSL_H_ 69