1 // Copyright 2017 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_CTR_BORINGSSL_H_ 18 #define TINK_SUBTLE_AES_CTR_BORINGSSL_H_ 19 20 #include <memory> 21 #include <string> 22 #include <utility> 23 24 #include "openssl/evp.h" 25 #include "tink/internal/fips_utils.h" 26 #include "tink/subtle/ind_cpa_cipher.h" 27 #include "tink/util/secret_data.h" 28 #include "tink/util/statusor.h" 29 30 namespace crypto { 31 namespace tink { 32 namespace subtle { 33 34 class AesCtrBoringSsl : public IndCpaCipher { 35 public: 36 static crypto::tink::util::StatusOr<std::unique_ptr<IndCpaCipher>> New( 37 util::SecretData key, int iv_size); 38 39 crypto::tink::util::StatusOr<std::string> Encrypt( 40 absl::string_view plaintext) const override; 41 42 crypto::tink::util::StatusOr<std::string> Decrypt( 43 absl::string_view ciphertext) const override; 44 45 static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus = 46 crypto::tink::internal::FipsCompatibility::kRequiresBoringCrypto; 47 48 private: 49 static constexpr int kMinIvSizeInBytes = 12; 50 static constexpr int kBlockSize = 16; 51 AesCtrBoringSsl(util::SecretData key,int iv_size,const EVP_CIPHER * cipher)52 AesCtrBoringSsl(util::SecretData key, int iv_size, const EVP_CIPHER* cipher) 53 : key_(std::move(key)), iv_size_(iv_size), cipher_(cipher) {} 54 55 const util::SecretData key_; 56 const int iv_size_; 57 // cipher_ is a singleton owned by BoringSsl. 58 const EVP_CIPHER *cipher_; 59 }; 60 61 } // namespace subtle 62 } // namespace tink 63 } // namespace crypto 64 65 #endif // TINK_SUBTLE_AES_CTR_BORINGSSL_H_ 66