sdsa

package
v1.0.5009 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPublicKey = errors.New("go-cryptobin/sdsa: invalid public key")

ErrInvalidPublicKey results when a public key is not usable by this code. FIPS is quite strict about the format of DSA keys, but other code may be less so. Thus, when using keys which may have been generated by other code, this error must be handled.

View Source
var (
	ErrInvalidSignerOpts = errors.New("go-cryptobin/sdsa: opts must be *SignerOpts")
)

Functions

func GenerateKey

func GenerateKey(priv *PrivateKey, rand io.Reader) error

GenerateKey generates a public&private key pair. The Parameters of the PrivateKey must already be valid (see GenerateParameters).

func GenerateParameters

func GenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes) error

GenerateParameters puts a random, valid set of DSA parameters into params. This function can take many seconds, even on fast machines.

func MarshalXMLPrivateKey

func MarshalXMLPrivateKey(key *PrivateKey) ([]byte, error)

Marshal XML PrivateKey

func MarshalXMLPublicKey

func MarshalXMLPublicKey(key *PublicKey) ([]byte, error)

Marshal XML PublicKey

func Sign

func Sign(rand io.Reader, priv *PrivateKey, hashFunc Hasher, data []byte) (r, s *big.Int, err error)

Sign hash

func SignASN1

func SignASN1(rand io.Reader, priv *PrivateKey, hashFunc Hasher, data []byte) ([]byte, error)

SignASN1 signs a hash (which should be the result of hashing a larger message) using the private key, priv. If the hash is longer than the bit-length of the private key's curve order, the hash will be truncated to that length. It returns the ASN.1 encoded signature.

func SignBytes

func SignBytes(rand io.Reader, priv *PrivateKey, hashFunc Hasher, data []byte) (sig []byte, err error)

Sign data returns the Bytes encoded signature.

func SignUsingK added in v1.0.4006

func SignUsingK(k *big.Int, priv *PrivateKey, hashFunc Hasher, data []byte) (r, s *big.Int, err error)

sign with k

func Verify

func Verify(pub *PublicKey, hashFunc Hasher, data []byte, r, s *big.Int) bool

Verify hash

func VerifyASN1

func VerifyASN1(pub *PublicKey, hashFunc Hasher, data []byte, sig []byte) (bool, error)

VerifyASN1 verifies the ASN.1 encoded signature, sig, of hash using the public key, pub. Its return value records whether the signature is valid.

func VerifyBytes

func VerifyBytes(pub *PublicKey, hashFunc Hasher, data, sig []byte) bool

Verify verifies the Bytes encoded signature

Types

type Hasher

type Hasher = func() hash.Hash

type ParameterSizes

type ParameterSizes int

ParameterSizes is an enumeration of the acceptable bit lengths of the primes in a set of DSA parameters. See FIPS 186-3, section 4.2.

const (
	L1024N160 ParameterSizes = iota
	L2048N224
	L2048N256
	L3072N256
)

type Parameters

type Parameters struct {
	P, Q, G *big.Int
}

Parameters represents the domain parameters for a key. These parameters can be shared across many keys. The bit length of Q must be a multiple of 8.

type PrivateKey

type PrivateKey struct {
	PublicKey

	X *big.Int
}

egdsa PrivateKey

func ParseXMLPrivateKey

func ParseXMLPrivateKey(der []byte) (*PrivateKey, error)

Parse XML PrivateKey

func (*PrivateKey) Equal

func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool

Equal reports whether priv and x have the same value.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() crypto.PublicKey

Public returns the public key corresponding to priv.

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(random io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)

Signature generates signature over the given hash. It returns signature value consisting of two parts "r" and "s" as byte arrays.

type PublicKey

type PublicKey struct {
	Parameters

	Y *big.Int
}

egdsa PublicKey

func ParseXMLPublicKey

func ParseXMLPublicKey(der []byte) (*PublicKey, error)

Parse XML PublicKey

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x crypto.PublicKey) bool

Equal reports whether pub and x have the same value.

func (*PublicKey) Verify

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

Verify verifies signature over the given hash and signature values (r & s). It returns true as a boolean value if signature is verify correctly. Otherwise it returns false along with error message.

type SignerOpts

type SignerOpts struct {
	Hash Hasher
}

SignerOpts contains options for creating and verifying EC-GDSA signatures.

func (*SignerOpts) GetHash

func (opts *SignerOpts) GetHash() Hasher

GetHash returns func() hash.Hash

func (*SignerOpts) HashFunc

func (opts *SignerOpts) HashFunc() crypto.Hash

HashFunc returns opts.Hash

type XMLKey

type XMLKey struct{}

*

  • sdsa xml *
  • @create 2024-9-1
  • @author deatil

func NewXMLKey

func NewXMLKey() XMLKey

NewXMLKey

func (XMLKey) MarshalPrivateKey

func (this XMLKey) MarshalPrivateKey(key *PrivateKey) ([]byte, error)

Marshal XML PrivateKey

func (XMLKey) MarshalPublicKey

func (this XMLKey) MarshalPublicKey(key *PublicKey) ([]byte, error)

Marshal XML PublicKey

func (XMLKey) ParsePrivateKey

func (this XMLKey) ParsePrivateKey(data []byte) (*PrivateKey, error)

Parse XML PrivateKey

func (XMLKey) ParsePublicKey

func (this XMLKey) ParsePublicKey(data []byte) (*PublicKey, error)

Parse XML PublicKey

Jump to

Keyboard shortcuts

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