git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/crypto/chacha/hchacha20_amd64.go (about) 1 //go:build amd64 && gc && !purego 2 3 package chacha 4 5 // This function is implemented in hchacha20_amd64.s 6 // 7 //go:noescape 8 func hChaCha20AVX(out *[32]byte, nonce *[16]byte, key *[32]byte) 9 10 // This function is implemented in hchacha20_amd64.s 11 // 12 //go:noescape 13 func hChaCha20SSE2(out *[32]byte, nonce *[16]byte, key *[32]byte) 14 15 // This function is implemented in hchacha20_amd64.s 16 // 17 //go:noescape 18 func hChaCha20SSSE3(out *[32]byte, nonce *[16]byte, key *[32]byte) 19 20 func hChaCha20(out, key, nonce []byte) ([]byte, error) { 21 if len(key) != HChaCha20KeySize { 22 return nil, ErrBadHChaCha20KeySize 23 } 24 if len(nonce) != HChaCha20NonceSize { 25 return nil, ErrBadHChaCha20NonceSize 26 } 27 28 switch { 29 case useAVX: 30 hChaCha20AVX((*[32]byte)(out), (*[16]byte)(nonce), (*[32]byte)(key)) 31 case useSSSE3: 32 hChaCha20SSSE3((*[32]byte)(out), (*[16]byte)(nonce), (*[32]byte)(key)) 33 case useSSE2: 34 hChaCha20SSE2((*[32]byte)(out), (*[16]byte)(nonce), (*[32]byte)(key)) 35 default: 36 hChaCha20Generic((*[32]byte)(out), (*[16]byte)(nonce), (*[32]byte)(key)) 37 } 38 39 return out, nil 40 }