cert: Add version 3 certificates, a v2 certificate extended with ML-KEM-1024 or ML-DSA-87 keys and an ML-DSA-87 CA signature

This commit is contained in:
JackDoan committed 2026-10-14 10:47:41 -05:00
1 parent 73ddb56c34
commit 1a8fb8d67e
9 files changed
+1255 -10

No files matched your search

+28
View File
@@ -4,6 +4,8 @@ import (
"crypto/ecdh"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/mldsa"
"crypto/mlkem"
"crypto/rand"
"io"
"net/netip"
@@ -39,6 +41,10 @@ func NewTestCaCert(version Version, curve Curve, before, after time.Time, networ
// There is no default to allow the underlying lib to respond with an error
}
if version == Version3 {
pub, priv = appendPQSigningKey(pub, priv)
}
if before.IsZero() {
before = testCertNow.Add(time.Second * -60)
}
@@ -97,6 +103,10 @@ func NewTestCert(v Version, curve Curve, ca Certificate, key []byte, name string
panic("unknown curve")
}
if v == Version3 {
pub, priv = appendPQKey(pub, priv)
}
nc := &TBSCertificate{
Version: v,
Curve: curve,
@@ -123,6 +133,24 @@ func NewTestCert(v Version, curve Curve, ca Certificate, key []byte, name string
return c, pub, MarshalPrivateKeyToPEM(curve, priv), pem
}
// appendPQSigningKey makes a classical CA keypair into a version 3 composite one with a fresh ML-DSA-87 key.
func appendPQSigningKey(pub, priv []byte) ([]byte, []byte) {
sk, err := mldsa.GenerateKey(mldsa.MLDSA87())
if err != nil {
panic(err)
}
return append(pub, sk.PublicKey().Bytes()...), append(priv, sk.Bytes()...)
}
// appendPQKey makes a classical host keypair into a version 3 composite one with a fresh ML-KEM-1024 key.
func appendPQKey(pub, priv []byte) ([]byte, []byte) {
dk, err := mlkem.GenerateKey1024()
if err != nil {
panic(err)
}
return append(pub, dk.EncapsulationKey().Bytes()...), append(priv, dk.Bytes()...)
}
func X25519Keypair() ([]byte, []byte) {
privkey := make([]byte, 32)
if _, err := io.ReadFull(rand.Reader, privkey); err != nil {