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

+22
View File
@@ -158,6 +158,7 @@ func splitNonceCiphertext(blob []byte, nonceSize int) ([]byte, []byte, error) {
// EncryptAndMarshalSigningPrivateKey is a simple helper to encrypt and PEM encode a private key
func EncryptAndMarshalSigningPrivateKey(curve Curve, b []byte, passphrase []byte, kdfParams *Argon2Parameters) ([]byte, error) {
pq := len(b) == signingPrivateKeySize(curve)+MLDSA87PrivateKeySize
ciphertext, err := aes256Encrypt(passphrase, kdfParams, b)
if err != nil {
return nil, err
@@ -180,6 +181,13 @@ func EncryptAndMarshalSigningPrivateKey(curve Curve, b []byte, passphrase []byte
return nil, err
}
switch {
case pq && curve == Curve_CURVE25519:
return pem.EncodeToMemory(&pem.Block{Type: EncryptedEd25519MLDSA87PrivateKeyBanner, Bytes: b}), nil
case pq && curve == Curve_P256:
return pem.EncodeToMemory(&pem.Block{Type: EncryptedECDSAP256MLDSA87PrivateKeyBanner, Bytes: b}), nil
}
switch curve {
case Curve_CURVE25519:
return pem.EncodeToMemory(&pem.Block{Type: EncryptedEd25519PrivateKeyBanner, Bytes: b}), nil
@@ -260,11 +268,18 @@ func DecryptAndUnmarshalSigningPrivateKey(passphrase, b []byte) (Curve, []byte,
return curve, nil, r, fmt.Errorf("input did not contain a valid PEM encoded block")
}
pq := false
switch k.Type {
case EncryptedEd25519PrivateKeyBanner:
curve = Curve_CURVE25519
case EncryptedECDSAP256PrivateKeyBanner:
curve = Curve_P256
case EncryptedEd25519MLDSA87PrivateKeyBanner:
curve = Curve_CURVE25519
pq = true
case EncryptedECDSAP256MLDSA87PrivateKeyBanner:
curve = Curve_P256
pq = true
default:
return curve, nil, r, fmt.Errorf("bytes did not contain a proper nebula encrypted Ed25519/ECDSA private key banner")
}
@@ -285,6 +300,13 @@ func DecryptAndUnmarshalSigningPrivateKey(passphrase, b []byte) (Curve, []byte,
return curve, nil, r, fmt.Errorf("unsupported encryption algorithm: %s", ned.EncryptionMetadata.EncryptionAlgorithm)
}
if pq {
if len(bytes) != signingPrivateKeySize(curve)+MLDSA87PrivateKeySize {
return curve, nil, r, fmt.Errorf("key was not %d bytes, is invalid %s ML-DSA-87 private key", signingPrivateKeySize(curve)+MLDSA87PrivateKeySize, curve)
}
return curve, bytes, r, nil
}
switch curve {
case Curve_CURVE25519:
if len(bytes) != ed25519.PrivateKeySize {