slhdsa

package
v1.17.6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: BSD-3-Clause Imports: 12 Imported by: 9

Documentation

Index

Examples

Constants

View Source
const (
	// SLH-DSA-SHA2-128s (Small signatures, Level 1 security)
	SLHDSA128sPublicKeySize  = 32
	SLHDSA128sPrivateKeySize = 64
	SLHDSA128sSignatureSize  = 7856

	// SLH-DSA-SHA2-128f (Fast signing, Level 1 security)
	SLHDSA128fPublicKeySize  = 32
	SLHDSA128fPrivateKeySize = 64
	SLHDSA128fSignatureSize  = 17088

	// SLH-DSA-SHA2-192s (Small signatures, Level 3 security)
	SLHDSA192sPublicKeySize  = 48
	SLHDSA192sPrivateKeySize = 96
	SLHDSA192sSignatureSize  = 16224

	// SLH-DSA-SHA2-192f (Fast signing, Level 3 security)
	SLHDSA192fPublicKeySize  = 48
	SLHDSA192fPrivateKeySize = 96
	SLHDSA192fSignatureSize  = 35664

	// SLH-DSA-SHA2-256s (Small signatures, Level 5 security)
	SLHDSA256sPublicKeySize  = 64
	SLHDSA256sPrivateKeySize = 128
	SLHDSA256sSignatureSize  = 29792

	// SLH-DSA-SHA2-256f (Fast signing, Level 5 security)
	SLHDSA256fPublicKeySize  = 64
	SLHDSA256fPrivateKeySize = 128
	SLHDSA256fSignatureSize  = 49856
)

Security parameters for SLH-DSA (Stateless Hash-Based Digital Signature Algorithm)

Variables

This section is empty.

Functions

func InitPrecomputation added in v1.17.3

func InitPrecomputation()

InitPrecomputation initializes precomputed tables

Types

type BenchmarkConfig added in v1.17.3

type BenchmarkConfig struct {
	Mode        Mode
	MessageSize int
	Iterations  int
	Parallel    bool
}

BenchmarkConfig contains benchmark configuration

type BenchmarkResult added in v1.17.3

type BenchmarkResult struct {
	Mode            Mode
	MessageSize     int
	SignTime        int64 // nanoseconds
	VerifyTime      int64 // nanoseconds
	SignOpsPerSec   float64
	VerifyOpsPerSec float64
}

BenchmarkResult contains benchmark results

type CachedSLHDSA

type CachedSLHDSA struct {
	// contains filtered or unexported fields
}

CachedSLHDSA caches intermediate computations

func NewCachedSLHDSA

func NewCachedSLHDSA(privKey *PrivateKey) *CachedSLHDSA

NewCachedSLHDSA creates a cached SLH-DSA instance

func (*CachedSLHDSA) SignWithCache

func (c *CachedSLHDSA) SignWithCache(message []byte) ([]byte, error)

SignWithCache signs using cached computations

type MerkleTree

type MerkleTree struct {
	// contains filtered or unexported fields
}

MerkleTree represents an optimized Merkle tree for SLH-DSA

func NewMerkleTree

func NewMerkleTree(height int) *MerkleTree

NewMerkleTree creates a new Merkle tree

func (*MerkleTree) ComputeRoot

func (mt *MerkleTree) ComputeRoot(leaves [][]byte) []byte

ComputeRoot computes the Merkle tree root

type Mode

type Mode int

Mode represents the SLH-DSA parameter set

const (
	SLHDSA128s Mode = iota + 1 // Small signatures, Level 1
	SLHDSA128f                 // Fast signing, Level 1
	SLHDSA192s                 // Small signatures, Level 3
	SLHDSA192f                 // Fast signing, Level 3
	SLHDSA256s                 // Small signatures, Level 5
	SLHDSA256f                 // Fast signing, Level 5
)

type OptimizedSLHDSA added in v1.17.3

type OptimizedSLHDSA struct {
	// contains filtered or unexported fields
}

OptimizedSLHDSA provides performance-optimized SLH-DSA operations

Example

Example usage showing the optimization API

// Initialize precomputed tables for best performance
InitPrecomputation()

// Create optimized instance
opt := NewOptimized(SLHDSA128f)

// Generate keys
priv, _ := GenerateKey(rand.Reader, SLHDSA128f)
sk := priv
pk := &priv.PublicKey

// Sign message with optimizations
message := []byte("Hello, Post-Quantum World!")
signature, _ := opt.OptimizedSign(sk, message)

// Verify with optimizations
valid := opt.OptimizedVerify(pk, message, signature)

fmt.Printf("Signature valid: %v\n", valid)
fmt.Printf("Signature size: %d bytes\n", len(signature))
Output:

Signature valid: true
Signature size: 17088 bytes

func NewOptimized added in v1.17.3

func NewOptimized(mode Mode) *OptimizedSLHDSA

NewOptimized creates an optimized SLH-DSA instance

func (*OptimizedSLHDSA) OptimizedSign added in v1.17.3

func (o *OptimizedSLHDSA) OptimizedSign(privateKey *PrivateKey, message []byte) ([]byte, error)

OptimizedSign performs optimized signing with parallel hash computations

func (*OptimizedSLHDSA) OptimizedVerify added in v1.17.3

func (o *OptimizedSLHDSA) OptimizedVerify(publicKey *PublicKey, message []byte, signature []byte) bool

OptimizedVerify performs optimized signature verification

func (*OptimizedSLHDSA) RunBenchmark added in v1.17.3

func (o *OptimizedSLHDSA) RunBenchmark(config BenchmarkConfig) BenchmarkResult

RunBenchmark runs performance benchmarks

type ParallelSLHDSA

type ParallelSLHDSA struct {
	// contains filtered or unexported fields
}

ParallelSLHDSA provides parallel signing for multiple messages

func NewParallelSLHDSA

func NewParallelSLHDSA(mode Mode, numKeys, workers int) (*ParallelSLHDSA, error)

NewParallelSLHDSA creates a parallel SLH-DSA processor

func (*ParallelSLHDSA) SignMessages

func (p *ParallelSLHDSA) SignMessages(messages [][]byte) ([][]byte, error)

SignMessages signs multiple messages in parallel

type PrivateKey

type PrivateKey struct {
	PublicKey
	// contains filtered or unexported fields
}

PrivateKey represents an SLH-DSA private key

func GenerateKey

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

GenerateKey generates a new SLH-DSA key pair using REAL implementation

func OptimizedGenerateKey

func OptimizedGenerateKey(rand io.Reader, mode Mode) (*PrivateKey, error)

OptimizedGenerateKey generates keys with optimized memory usage

func PrivateKeyFromBytes

func PrivateKeyFromBytes(data []byte, mode Mode) (*PrivateKey, error)

PrivateKeyFromBytes reconstructs a private key from bytes

func (*PrivateKey) Bytes

func (priv *PrivateKey) Bytes() []byte

Bytes returns the private key as bytes

func (*PrivateKey) OptimizedSign

func (priv *PrivateKey) OptimizedSign(rand io.Reader, message []byte, opts crypto.SignerOpts) ([]byte, error)

OptimizedSign performs signing with buffer pooling

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) ([]byte, error)

Sign signs a message using the REAL SPHINCS+ implementation

type PublicKey

type PublicKey struct {
	// contains filtered or unexported fields
}

PublicKey represents an SLH-DSA public key

func PublicKeyFromBytes

func PublicKeyFromBytes(data []byte, mode Mode) (*PublicKey, error)

PublicKeyFromBytes reconstructs a public key from bytes

func (*PublicKey) Bytes

func (pub *PublicKey) Bytes() []byte

Bytes returns the public key as bytes

func (*PublicKey) Verify

func (pub *PublicKey) Verify(message, signature []byte, opts crypto.SignerOpts) bool

Verify verifies a signature using the REAL SPHINCS+ implementation

Jump to

Keyboard shortcuts

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