sig

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MLDSA44PublicKeySize = dilithium.PublicKeySize44
	MLDSA44SecretKeySize = dilithium.SecretKeySize44
	MLDSA44SignatureSize = dilithium.SignatureSize44
	MLDSA65PublicKeySize = dilithium.PublicKeySize65
	MLDSA65SecretKeySize = dilithium.SecretKeySize65
	MLDSA65SignatureSize = dilithium.SignatureSize65
	MLDSA87PublicKeySize = dilithium.PublicKeySize87
	MLDSA87SecretKeySize = dilithium.SecretKeySize87
	MLDSA87SignatureSize = dilithium.SignatureSize87
)

Public, secret, and signature sizes for the Dilithium / ML-DSA variants.

View Source
const (
	PublicKeySize  = ed25519.PublicKeySize
	PrivateKeySize = ed25519.PrivateKeySize
	SeedSize       = ed25519.SeedSize
	SignatureSize  = ed25519.SignatureSize
)

Expose standard ed25519 sizes so callers can allocate buffers without importing crypto/ed25519 directly.

View Source
const (
	// ScalarSize is the size in bytes of a P-256 private scalar.
	ScalarSize = 32
)

Variables

This section is empty.

Functions

func FromSeed

func FromSeed(seed []byte) (ed25519.PublicKey, ed25519.PrivateKey, error)

FromSeed derives a deterministic keypair from a 32-byte seed.

func GenerateDeterministicKeyMLDSA44 added in v1.0.1

func GenerateDeterministicKeyMLDSA44(seed []byte) ([]byte, []byte, error)

GenerateDeterministicKeyMLDSA44 derives a deterministic ML-DSA-44 key pair from seed.

func GenerateDeterministicKeyMLDSA65 added in v1.0.1

func GenerateDeterministicKeyMLDSA65(seed []byte) ([]byte, []byte, error)

GenerateDeterministicKeyMLDSA65 derives a deterministic ML-DSA-65 key pair from seed.

func GenerateDeterministicKeyMLDSA87 added in v1.0.1

func GenerateDeterministicKeyMLDSA87(seed []byte) ([]byte, []byte, error)

GenerateDeterministicKeyMLDSA87 derives a deterministic ML-DSA-87 key pair from seed.

func GenerateKey

func GenerateKey() (ed25519.PublicKey, ed25519.PrivateKey, error)

GenerateKey creates a new Ed25519 keypair using crypto/rand.

func GenerateKeyECDSAP256

func GenerateKeyECDSAP256() (public []byte, private []byte, err error)

GenerateKeyECDSAP256 produces a fresh ECDSA P-256 keypair using crypto/rand and returns the encoded public/private material suitable for use with the Signature interface.

func GenerateKeyMLDSA44 added in v1.0.1

func GenerateKeyMLDSA44() ([]byte, []byte, error)

GenerateKeyMLDSA44 creates a randomized key pair for ML-DSA-44.

func GenerateKeyMLDSA65 added in v1.0.1

func GenerateKeyMLDSA65() ([]byte, []byte, error)

GenerateKeyMLDSA65 creates a randomized key pair for ML-DSA-65.

func GenerateKeyMLDSA87 added in v1.0.1

func GenerateKeyMLDSA87() ([]byte, []byte, error)

GenerateKeyMLDSA87 creates a randomized key pair for ML-DSA-87.

func GenerateKeyP256

func GenerateKeyP256() (*ecdsa.PrivateKey, error)

GenerateKeyP256 creates a new ECDSA P-256 keypair using crypto/rand.

func MarshalPrivateKey

func MarshalPrivateKey(p *ecdsa.PrivateKey) []byte

MarshalPrivateKey returns the 32-byte scalar for priv.

func MarshalPublicKey

func MarshalPublicKey(pub *ecdsa.PublicKey) []byte

MarshalPublicKey serialises pub as an uncompressed point.

func NewPrivateKey

func NewPrivateKey(d []byte) (*ecdsa.PrivateKey, error)

NewPrivateKey constructs a private key from a scalar encoded as big-endian bytes.

func ParsePublicKey

func ParsePublicKey(b []byte) (*ecdsa.PublicKey, error)

ParsePublicKey deserializes an uncompressed public key.

func ParseSignature

func ParseSignature(sig []byte) (*big.Int, *big.Int, error)

ParseSignature decodes a DER-encoded ECDSA signature into r and s values.

func Sign

func Sign(priv ed25519.PrivateKey, msg []byte) []byte

Sign produces an Ed25519 signature of msg using priv.

func SignASN1

func SignASN1(p *ecdsa.PrivateKey, hash []byte) ([]byte, error)

SignASN1 generates an ECDSA signature over hash using priv, returning DER encoding.

func SignECDSAP256

func SignECDSAP256(private, msg []byte) ([]byte, error)

SignECDSAP256 signs msg using the provided encoded private scalar. The signature is returned in ASN.1 DER format matching crypto/ecdsa.SignASN1.

func SignWithOptions added in v1.0.1

func SignWithOptions(priv ed25519.PrivateKey, msg []byte, opts *ed25519.Options) ([]byte, error)

SignWithOptions signs msg using priv with the supplied options. The returned signature is copied to a fresh slice.

func Verify

func Verify(pub ed25519.PublicKey, msg, sig []byte) bool

Verify reports whether sig is a valid Ed25519 signature of msg by pub.

func VerifyASN1

func VerifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool

VerifyASN1 reports whether sig is a valid DER-encoded ECDSA signature for hash.

func VerifyECDSAP256

func VerifyECDSAP256(public, msg, signature []byte) bool

VerifyECDSAP256 checks whether signature is a valid ASN.1 DER encoded ECDSA signature over msg under the encoded uncompressed public key.

func VerifyWithOptions added in v1.0.1

func VerifyWithOptions(pub ed25519.PublicKey, msg, signature []byte, opts *ed25519.Options) error

VerifyWithOptions reports whether signature is valid for msg under pub with the supplied options. It returns a nil error when verification succeeds.

Types

type Options added in v1.0.1

type Options = ed25519.Options

Options selects Ed25519 variants when signing or verifying with options.

type Signature

type Signature interface {
	// GenerateKey returns the encoded public and private key material.
	GenerateKey() (public []byte, private []byte, err error)
	// Sign produces a signature over msg using the encoded private key.
	Sign(private []byte, msg []byte) ([]byte, error)
	// Verify reports whether signature is valid for msg under the encoded public key.
	Verify(public []byte, msg, signature []byte) bool
}

Signature defines the minimal single-shot signing API implemented by the signature helpers exposed under sig/.

func New

func New() Signature

New returns a Signature for deterministic ECDSA over P-256 using DER signatures.

func NewDeterministicMLDSA44 added in v1.0.1

func NewDeterministicMLDSA44() Signature

NewDeterministicMLDSA44 returns ML-DSA-44 operating in deterministic mode.

func NewDeterministicMLDSA65 added in v1.0.1

func NewDeterministicMLDSA65() Signature

NewDeterministicMLDSA65 returns ML-DSA-65 operating in deterministic mode.

func NewDeterministicMLDSA87 added in v1.0.1

func NewDeterministicMLDSA87() Signature

NewDeterministicMLDSA87 returns ML-DSA-87 operating in deterministic mode.

func NewECDSAP256

func NewECDSAP256() Signature

NewECDSAP256 returns a Signature implementation backed by the helpers in p256.go. It exposes the P-256 ECDSA functionality under an explicit name without duplicating the underlying logic.

func NewEd25519

func NewEd25519() Signature

NewEd25519 returns a Signature backed by the Ed25519 helpers.

func NewMLDSA44 added in v1.0.1

func NewMLDSA44() Signature

NewMLDSA44 returns a Signature implementation for ML-DSA-44 (Dilithium-2).

func NewMLDSA65 added in v1.0.1

func NewMLDSA65() Signature

NewMLDSA65 returns a Signature implementation for ML-DSA-65 (Dilithium-3).

func NewMLDSA87 added in v1.0.1

func NewMLDSA87() Signature

NewMLDSA87 returns a Signature implementation for ML-DSA-87 (Dilithium-5).

Jump to

Keyboard shortcuts

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