123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package salsa20
- import (
- "golang.org/x/crypto/salsa20/salsa"
- )
- func XORKeyStream(out, in []byte, nonce []byte, key *[32]byte) {
- if len(out) < len(in) {
- in = in[:len(out)]
- }
- var subNonce [16]byte
- if len(nonce) == 24 {
- var subKey [32]byte
- var hNonce [16]byte
- copy(hNonce[:], nonce[:16])
- salsa.HSalsa20(&subKey, &hNonce, key, &salsa.Sigma)
- copy(subNonce[:], nonce[16:])
- key = &subKey
- } else if len(nonce) == 8 {
- copy(subNonce[:], nonce[:])
- } else {
- panic("salsa20: nonce must be 8 or 24 bytes")
- }
- salsa.XORKeyStream(out, in, &subNonce, key)
- }
|