Compare commits

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