handshake: Add ix_hybrid_mlkem1024, DefinedNet/noise hybrid IX with ML-KEM-1024 over version 3 certificates

This commit is contained in:
JackDoan committed 2026-10-14 10:50:33 -05:00
1 parent 1a8fb8d67e
commit ab89556c5c
8 files changed
+401 -31

No files matched your search

+39
View File
@@ -6,6 +6,9 @@ import (
"crypto/sha256"
"errors"
"fmt"
"io"
"github.com/DefinedNet/noise"
)
// kemPSKSalt separates the psk derivation from any other use of the secret.
@@ -66,3 +69,39 @@ func (m *Machine) kemDecapsulate(msg []byte) ([]byte, error) {
}
return msg[mlkem.CiphertextSize1024:], nil
}
// KEMMLKEM1024 is ML-KEM-1024 for the noise library's hybrid patterns. Private
// keys are the 64 byte seed, the same form v3 private keys store.
var KEMMLKEM1024 noise.KEMFunc = kemMLKEM1024{}
type kemMLKEM1024 struct{}
// GenerateKeypair ignores random, crypto/mlkem always draws from crypto/rand.
func (kemMLKEM1024) GenerateKeypair(_ io.Reader) (noise.KEMKey, error) {
dk, err := mlkem.GenerateKey1024()
if err != nil {
return noise.KEMKey{}, fmt.Errorf("mlkem1024: GenerateKey: %w", err)
}
return noise.KEMKey{Private: dk.Bytes(), Public: dk.EncapsulationKey().Bytes()}, nil
}
func (kemMLKEM1024) Encapsulate(pubkey []byte) ([]byte, []byte, error) {
ek, err := mlkem.NewEncapsulationKey1024(pubkey)
if err != nil {
return nil, nil, fmt.Errorf("%w: %w", ErrInvalidKEMKey, err)
}
ss, ct := ek.Encapsulate()
return ct, ss, nil
}
func (kemMLKEM1024) Decapsulate(privkey, ciphertext []byte) ([]byte, error) {
dk, err := mlkem.NewDecapsulationKey1024(privkey)
if err != nil {
return nil, fmt.Errorf("mlkem1024: NewDecapsulationKey: %w", err)
}
return dk.Decapsulate(ciphertext)
}
func (kemMLKEM1024) PublicKeyLen() int { return mlkem.EncapsulationKeySize1024 }
func (kemMLKEM1024) CiphertextLen() int { return mlkem.CiphertextSize1024 }
func (kemMLKEM1024) KEMName() string { return "MLKEM1024" }