1 // Copyright 2021 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_EXPERIMENTAL_PQCRYPTO_SIGNATURE_SUBTLE_SPHINCS_HELPER_PQCLEAN_H_ 18 #define TINK_EXPERIMENTAL_PQCRYPTO_SIGNATURE_SUBTLE_SPHINCS_HELPER_PQCLEAN_H_ 19 20 #include <memory> 21 #include <vector> 22 23 #include "absl/base/attributes.h" 24 25 namespace crypto { 26 namespace tink { 27 namespace subtle { 28 29 class SphincsHelperPqclean { 30 public: SphincsHelperPqclean(int public_key_size,int signature_length)31 SphincsHelperPqclean(int public_key_size, int signature_length) 32 : public_key_size_(public_key_size), 33 signature_length_(signature_length) {} 34 35 SphincsHelperPqclean(const SphincsHelperPqclean &other) = delete; 36 SphincsHelperPqclean &operator=(const SphincsHelperPqclean &other) = delete; 37 virtual ~SphincsHelperPqclean() = default; 38 39 // Arguments: 40 // sig - output signature (allocated buffer of size at least 41 // GetSignatureLength()); siglen - output length of signature; m - message 42 // to be signed; mlen - length of message; sk - bit-packed secret key. 43 // Computes signature. Returns 0 (success). 44 virtual ABSL_MUST_USE_RESULT int Sign(uint8_t *sig, size_t *siglen, 45 const uint8_t *m, size_t mlen, 46 const uint8_t *sk) const = 0; 47 48 // Arguments: 49 // sig - input signature; siglen - length of signature; 50 // m - input message; mlen - length of message; pk - bit-packed public key. 51 // Verifies the signature. Returns 0 (success). 52 virtual ABSL_MUST_USE_RESULT int Verify(const uint8_t *sig, size_t siglen, 53 const uint8_t *m, size_t mlen, 54 const uint8_t *pk) const = 0; 55 56 // Arguments: 57 // pk - output public key (allocated buffer of the corresponding public key 58 // size); sk - output private key (allocated buffer of the corresponding 59 // private key size) 60 // Gnerates the key pair. Returns 0 (success). 61 virtual ABSL_MUST_USE_RESULT int Keygen(uint8_t *pk, uint8_t *sk) const = 0; 62 GetPublicKeySize()63 int GetPublicKeySize() const { return public_key_size_; } GetSignatureLength()64 int GetSignatureLength() const { return signature_length_; } 65 66 private: 67 int public_key_size_; 68 int signature_length_; 69 }; 70 71 // Returns a pointer to the corresponding SphincsHelperPqclean derived class. 72 // Will be used for the key generation, signing and verifing. 73 const SphincsHelperPqclean &GetSphincsHelperPqclean(int hash_type, int variant, 74 int key_size, 75 int signature_length); 76 77 } // namespace subtle 78 } // namespace tink 79 } // namespace crypto 80 81 #endif // TINK_EXPERIMENTAL_PQCRYPTO_SIGNATURE_SUBTLE_SPHINCS_HELPER_PQCLEAN_H_ 82