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 #ifndef TINK_SIGNATURE_ED25519_PARAMETERS_H_ 18 #define TINK_SIGNATURE_ED25519_PARAMETERS_H_ 19 20 #include "tink/signature/signature_parameters.h" 21 #include "tink/util/statusor.h" 22 23 namespace crypto { 24 namespace tink { 25 26 class Ed25519Parameters : public SignatureParameters { 27 public: 28 // Description of the output prefix prepended to the signature. 29 enum class Variant : int { 30 // Prepends '0x01<big endian key id>' to signature. 31 kTink = 1, 32 // Prepends '0x00<big endian key id>' to signature. 33 kCrunchy = 2, 34 // Appends a 0-byte to input message BEFORE computing the signature, then 35 // prepends '0x00<big endian key id>' to signature. 36 kLegacy = 3, 37 // Does not prepend any prefix (i.e., keys must have no ID requirement). 38 kNoPrefix = 4, 39 // Added to guard from failures that may be caused by future expansions. 40 kDoNotUseInsteadUseDefaultWhenWritingSwitchStatements = 20, 41 }; 42 43 // Copyable and movable. 44 Ed25519Parameters(const Ed25519Parameters& other) = default; 45 Ed25519Parameters& operator=(const Ed25519Parameters& other) = default; 46 Ed25519Parameters(Ed25519Parameters&& other) = default; 47 Ed25519Parameters& operator=(Ed25519Parameters&& other) = default; 48 49 // Creates a new Ed25519 parameters object unless `variant` is invalid. 50 static util::StatusOr<Ed25519Parameters> Create(Variant variant); 51 GetVariant()52 Variant GetVariant() const { return variant_; } 53 HasIdRequirement()54 bool HasIdRequirement() const override { 55 return variant_ != Variant::kNoPrefix; 56 } 57 58 bool operator==(const Parameters& other) const override; 59 60 private: Ed25519Parameters(Variant variant)61 explicit Ed25519Parameters(Variant variant) : variant_(variant) {} 62 63 Variant variant_; 64 }; 65 66 } // namespace tink 67 } // namespace crypto 68 69 #endif // TINK_SIGNATURE_ED25519_PARAMETERS_H_ 70