1 // Copyright 2019 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_AES_GCM_HKDF_STREAMING_H_ 18 #define TINK_SUBTLE_AES_GCM_HKDF_STREAMING_H_ 19 20 #include <memory> 21 #include <utility> 22 23 #include "tink/internal/fips_utils.h" 24 #include "tink/subtle/common_enums.h" 25 #include "tink/subtle/nonce_based_streaming_aead.h" 26 #include "tink/util/secret_data.h" 27 #include "tink/util/statusor.h" 28 29 namespace crypto { 30 namespace tink { 31 namespace subtle { 32 33 class AesGcmHkdfStreaming : public NonceBasedStreamingAead { 34 public: 35 struct Params { 36 util::SecretData ikm; 37 HashType hkdf_hash; 38 int derived_key_size; 39 int ciphertext_segment_size; 40 int ciphertext_offset; 41 }; 42 43 static util::StatusOr<std::unique_ptr<AesGcmHkdfStreaming>> New( 44 Params params); 45 46 static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus = 47 crypto::tink::internal::FipsCompatibility::kNotFips; 48 49 protected: 50 util::StatusOr<std::unique_ptr<StreamSegmentEncrypter>> NewSegmentEncrypter( 51 absl::string_view associated_data) const override; 52 53 util::StatusOr<std::unique_ptr<StreamSegmentDecrypter>> NewSegmentDecrypter( 54 absl::string_view associated_data) const override; 55 56 private: AesGcmHkdfStreaming(Params params)57 explicit AesGcmHkdfStreaming(Params params) 58 : ikm_(std::move(params.ikm)), 59 hkdf_hash_(params.hkdf_hash), 60 derived_key_size_(params.derived_key_size), 61 ciphertext_segment_size_(params.ciphertext_segment_size), 62 ciphertext_offset_(params.ciphertext_offset) {} 63 64 const util::SecretData ikm_; 65 const HashType hkdf_hash_; 66 const int derived_key_size_; 67 const int ciphertext_segment_size_; 68 const int ciphertext_offset_; 69 }; 70 71 } // namespace subtle 72 } // namespace tink 73 } // namespace crypto 74 75 #endif // TINK_SUBTLE_AES_GCM_HKDF_STREAMING_H_ 76