chore: output vless hash11 in generater

This commit is contained in:
wwqgtxx 2025-08-21 11:25:41 +08:00
parent b56068ee1c
commit e4dfe09744
3 changed files with 11 additions and 7 deletions

View File

@ -51,12 +51,13 @@ func Main(args []string) {
if len(args) > 1 {
seed = args[1]
}
seedBase64, clientBase64, err := encryption.GenMLKEM768(seed)
seedBase64, clientBase64, hash11Base64, err := encryption.GenMLKEM768(seed)
if err != nil {
panic(err)
}
fmt.Println("Seed: " + seedBase64)
fmt.Println("Client: " + clientBase64)
fmt.Println("Hash11: " + hash11Base64)
case "vless-x25519":
var privateKey string
if len(args) > 1 {
@ -66,7 +67,7 @@ func Main(args []string) {
if err != nil {
panic(err)
}
fmt.Println("PrivateKey:" + privateKeyBase64)
fmt.Println("Password:" + passwordBase64)
fmt.Println("PrivateKey: " + privateKeyBase64)
fmt.Println("Password: " + passwordBase64)
}
}

View File

@ -89,7 +89,7 @@ func TestInboundVless_TLS(t *testing.T) {
}
func TestInboundVless_Encryption(t *testing.T) {
seedBase64, clientBase64, err := encryption.GenMLKEM768("")
seedBase64, clientBase64, _, err := encryption.GenMLKEM768("")
if err != nil {
t.Fatal(err)
return

View File

@ -7,6 +7,7 @@ import (
"fmt"
"github.com/metacubex/utls/mlkem"
"golang.org/x/crypto/sha3"
)
const MLKEM768SeedLength = mlkem.SeedSize
@ -14,7 +15,7 @@ const MLKEM768ClientLength = mlkem.EncapsulationKeySize768
const X25519PasswordSize = 32
const X25519PrivateKeySize = 32
func GenMLKEM768(seedStr string) (seedBase64, clientBase64 string, err error) {
func GenMLKEM768(seedStr string) (seedBase64, clientBase64, hash11Base64 string, err error) {
var seed [MLKEM768SeedLength]byte
if len(seedStr) > 0 {
s, _ := base64.RawURLEncoding.DecodeString(seedStr)
@ -31,9 +32,11 @@ func GenMLKEM768(seedStr string) (seedBase64, clientBase64 string, err error) {
}
key, _ := mlkem.NewDecapsulationKey768(seed[:])
pub := key.EncapsulationKey()
client := key.EncapsulationKey().Bytes()
hash32 := sha3.Sum256(client)
seedBase64 = base64.RawURLEncoding.EncodeToString(seed[:])
clientBase64 = base64.RawURLEncoding.EncodeToString(pub.Bytes())
clientBase64 = base64.RawURLEncoding.EncodeToString(client)
hash11Base64 = base64.RawURLEncoding.EncodeToString(hash32[:11])
return
}