handshake: Keep the static ML-KEM-1024 key expanded in the Credential, instead of expanding it from its seed in every handshake

This commit is contained in:
JackDoan committed 2026-10-15 10:41:51 -05:00
1 parent 6c6bf5e486
commit cb9ab9c516
2 files changed
+32 -6

No files matched your search

+17
View File
@@ -2,6 +2,7 @@ package handshake
import (
"crypto/mlkem"
"crypto/subtle"
"errors"
"fmt"
"io"
@@ -43,6 +44,22 @@ func (kemMLKEM1024) Decapsulate(privkey, ciphertext []byte) ([]byte, error) {
return dk.Decapsulate(ciphertext)
}
// mlkem1024Keys is KEMMLKEM1024 for one handshake. It decapsulates with the
// static key the Credential holds expanded, rather than expanding it again from
// the seed noise hands back; any other private key is expanded as usual.
type mlkem1024Keys struct {
kemMLKEM1024
static *mlkem.DecapsulationKey1024
staticSeed []byte
}
func (k *mlkem1024Keys) Decapsulate(privkey, ciphertext []byte) ([]byte, error) {
if k.static != nil && subtle.ConstantTimeCompare(privkey, k.staticSeed) == 1 {
return k.static.Decapsulate(ciphertext)
}
return k.kemMLKEM1024.Decapsulate(privkey, ciphertext)
}
func (kemMLKEM1024) PublicKeyLen() int { return mlkem.EncapsulationKeySize1024 }
func (kemMLKEM1024) CiphertextLen() int { return mlkem.CiphertextSize1024 }
func (kemMLKEM1024) KEMName() string { return "MLKEM1024" }