github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/proxy/yuubinsya/crypto/auth.go (about) 1 package crypto 2 3 import ( 4 "crypto/cipher" 5 "crypto/sha256" 6 7 "golang.org/x/crypto/chacha20poly1305" 8 ) 9 10 type auth struct { 11 cipher.AEAD 12 } 13 14 func (a *auth) Key() []byte { 15 return nil 16 } 17 18 func (a *auth) KeySize() int { 19 return 0 20 } 21 22 func GetAuth(password []byte) (*auth, error) { 23 salted := append(password, []byte("yuubinsya-salt-")...) 24 key := sha256.Sum256(salted) 25 26 aead, err := chacha20poly1305.New(key[:]) 27 if err != nil { 28 return nil, err 29 } 30 return &auth{ 31 AEAD: aead, 32 }, nil 33 }