signature

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2019 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHash

func GetHash(scheme SignatureScheme) hash.Hash

func Serialize

func Serialize(sig *Signature) ([]byte, error)

Serialize the signature object to byte array as the following format:

|---------------------------|-----------------|
| signature_scheme (1 byte) | signature_data  |
|---------------------------|-----------------|

signature_data differs in the signature algorithm.

  • For ECDSA, it is the concatenation of two byte arrays of equal length converted from R and S.
  • For SM2, it starts with the user ID (empty if not specified) with a `0` as termination, and followed by the R and S data as described in ECDSA.
  • For EdDSA, it is just the signature data which could be handled by package ed25519.

func Verify

func Verify(pub crypto.PublicKey, msg []byte, sig *Signature) bool

Verify checks whether @sig is a valid signature for @msg with the public key @pub, and return true/false as the result.

Types

type DSASignature

type DSASignature struct {
	R, S  *big.Int
	Curve elliptic.Curve
}

type SM2Signature

type SM2Signature struct {
	DSASignature
	ID string
}

type Signature

type Signature struct {
	Scheme SignatureScheme
	Value  interface{}
}

func Deserialize

func Deserialize(buf []byte) (*Signature, error)

Deserialize the input data into a Signature object.

func Sign

func Sign(scheme SignatureScheme, pri crypto.PrivateKey, msg []byte, opt interface{}) (sig *Signature, err error)

Sign generates the signature for the input message @msg, using private key @pri and the signature scheme @scheme.

Some signature scheme may use extra parameters, which could be inputted via the last argument @opt:

  • SM2 signature needs the user ID (string). If it is an empty string, the default ID ("1234567812345678") would be used.

type SignatureScheme

type SignatureScheme byte
const (
	SHA224withECDSA SignatureScheme = iota
	SHA256withECDSA
	SHA384withECDSA
	SHA512withECDSA
	SHA3_224withECDSA
	SHA3_256withECDSA
	SHA3_384withECDSA
	SHA3_512withECDSA
	RIPEMD160withECDSA

	SM3withSM2

	SHA512withEDDSA
)

func GetScheme

func GetScheme(name string) (SignatureScheme, error)

func (SignatureScheme) Name

func (s SignatureScheme) Name() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL