1 // Copyright 2023 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 #include "tink/daead/aes_siv_parameters.h"
18
19 #include <set>
20
21 namespace crypto {
22 namespace tink {
23
Create(int key_size_in_bytes,Variant variant)24 util::StatusOr<AesSivParameters> AesSivParameters::Create(int key_size_in_bytes,
25 Variant variant) {
26 if (key_size_in_bytes != 32 && key_size_in_bytes != 48 &&
27 key_size_in_bytes != 64) {
28 return util::Status(
29 absl::StatusCode::kInvalidArgument,
30 absl::StrCat("Key size should be 32, 48, or 64 bytes, got ",
31 key_size_in_bytes, " bytes."));
32 }
33 static const std::set<Variant>* supported_variants = new std::set<Variant>(
34 {Variant::kTink, Variant::kCrunchy, Variant::kNoPrefix});
35 if (supported_variants->find(variant) == supported_variants->end()) {
36 return util::Status(
37 absl::StatusCode::kInvalidArgument,
38 "Cannot create AES-SIV parameters with unknown variant.");
39 }
40 return AesSivParameters(key_size_in_bytes, variant);
41 }
42
operator ==(const Parameters & other) const43 bool AesSivParameters::operator==(const Parameters& other) const {
44 const AesSivParameters* that = dynamic_cast<const AesSivParameters*>(&other);
45 if (that == nullptr) {
46 return false;
47 }
48 if (key_size_in_bytes_ != that->key_size_in_bytes_) {
49 return false;
50 }
51 if (variant_ != that->variant_) {
52 return false;
53 }
54 return true;
55 }
56
57 } // namespace tink
58 } // namespace crypto
59