Use standard mldsa65

This commit is contained in:
Fangliding
2026-08-31 01:00:35 +08:00
parent 5e245b082e
commit 6803531ce2
4 changed files with 14 additions and 10 deletions
+2 -2
View File
@@ -1,10 +1,9 @@
module github.com/xtls/xray-core
go 1.26
go 1.27
require (
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e
github.com/cloudflare/circl v1.6.5
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344
github.com/golang/mock v1.7.0-rc.1
github.com/google/go-cmp v0.7.0
@@ -41,6 +40,7 @@ require (
require (
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/cloudflare/circl v1.6.5 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/huin/goupnp v1.2.0 // indirect
+5 -3
View File
@@ -1,11 +1,12 @@
package all
import (
"crypto/mldsa"
"crypto/rand"
"encoding/base64"
"fmt"
"github.com/cloudflare/circl/sign/mldsa/mldsa65"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/main/commands/base"
)
@@ -39,8 +40,9 @@ func executeMLDSA65(cmd *base.Command, args []string) {
} else {
rand.Read(seed[:])
}
pub, _ := mldsa65.NewKeyFromSeed(&seed)
priv := common.Must2(mldsa.NewPrivateKey(mldsa.MLDSA65(), seed[:]))
fmt.Printf("Seed: %v\nVerify: %v\n",
base64.RawURLEncoding.EncodeToString(seed[:]),
base64.RawURLEncoding.EncodeToString(pub.Bytes()))
base64.RawURLEncoding.EncodeToString(priv.PublicKey().Bytes()),
)
}
+3 -2
View File
@@ -2,13 +2,14 @@ package reality
import (
"context"
"crypto/mldsa"
"io"
"net"
"os"
"time"
"github.com/cloudflare/circl/sign/mldsa/mldsa65"
"github.com/xtls/reality"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/transport/internet"
)
@@ -34,7 +35,7 @@ func (c *Config) GetREALITYConfig() *reality.Config {
KeyLogWriter: KeyLogWriterFromConfig(c),
}
if c.Mldsa65Seed != nil {
_, key := mldsa65.NewKeyFromSeed((*[32]byte)(c.Mldsa65Seed))
key := common.Must2(mldsa.NewPrivateKey(mldsa.MLDSA65(), c.Mldsa65Seed))
config.Mldsa65Key = key.Bytes()
}
if c.LimitFallbackUpload != nil {
+4 -3
View File
@@ -6,6 +6,7 @@ import (
"crypto/ecdh"
"crypto/ed25519"
"crypto/hmac"
"crypto/mldsa"
"crypto/sha256"
"crypto/sha512"
gotls "crypto/tls"
@@ -21,9 +22,9 @@ import (
"time"
"unsafe"
"github.com/cloudflare/circl/sign/mldsa/mldsa65"
utls "github.com/refraction-networking/utls"
"github.com/xtls/reality"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/crypto"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
@@ -89,8 +90,8 @@ func (c *UConn) VerifyPeerCertificate(rawCerts [][]byte, verifiedChains [][]*x50
if len(certs[0].Extensions) > 0 {
h.Write(c.HandshakeState.Hello.Raw)
h.Write(c.HandshakeState.ServerHello.Raw)
verify, _ := mldsa65.Scheme().UnmarshalBinaryPublicKey(c.Config.Mldsa65Verify)
if mldsa65.Verify(verify.(*mldsa65.PublicKey), h.Sum(nil), nil, certs[0].Extensions[0].Value) {
pub := common.Must2(mldsa.NewPublicKey(mldsa.MLDSA65(), c.Config.Mldsa65Verify))
if err := mldsa.Verify(pub, h.Sum(nil), certs[0].Extensions[0].Value, nil); err == nil {
c.Verified = true
return nil
}