github.com/consensys/gnark-crypto@v0.14.0/signature/signature.go (about) 1 /* 2 Copyright © 2020 ConsenSys 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package signature defines interfaces for a Signer and a PublicKey similarly to go/crypto standard package. 18 package signature 19 20 import ( 21 "hash" 22 ) 23 24 // PublicKey public key interface. 25 // The public key has a Verify function to check signatures. 26 type PublicKey interface { 27 28 // Verify verifies a signature of a message 29 // If hFunc is not provided, implementation may consider the message 30 // to be pre-hashed, else, will use hFunc to hash the message. 31 Verify(sigBin, message []byte, hFunc hash.Hash) (bool, error) 32 33 // SetBytes sets p from binary representation in buf. 34 // buf represents a public key as x||y where x, y are 35 // interpreted as big endian binary numbers corresponding 36 // to the coordinates of a point on the twisted Edwards. 37 // It returns the number of bytes read from the buffer. 38 SetBytes(buf []byte) (int, error) 39 40 // Bytes returns the binary representation of pk 41 // as x||y where x, y are the coordinates of the point 42 // on the twisted Edwards as big endian integers. 43 Bytes() []byte 44 45 Equal(PublicKey) bool 46 } 47 48 // Signer signer interface. 49 type Signer interface { 50 51 // Public returns the public key associated to 52 // the signer's private key. 53 Public() PublicKey 54 55 // Sign signs a message. If hFunc is not provided, implementation may consider the message 56 // to be pre-hashed, else, will use hFunc to hash the message. 57 // Returns Signature or error 58 Sign(message []byte, hFunc hash.Hash) ([]byte, error) 59 60 // Bytes returns the binary representation of pk, 61 // as byte array publicKey||scalar||randSrc 62 // where publicKey is as publicKey.Bytes(), and 63 // scalar is in big endian, of size sizeFr. 64 Bytes() []byte 65 66 // SetBytes sets pk from buf, where buf is interpreted 67 // as publicKey||scalar||randSrc 68 // where publicKey is as publicKey.Bytes(), and 69 // scalar is in big endian, of size sizeFr. 70 // It returns the number byte read. 71 SetBytes(buf []byte) (int, error) 72 }