github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/stdlibs/crypto/chacha20/chacha/chacha_ref.gno (about)

     1  // Copyright (c) 2016 Andreas Auernhammer. All rights reserved.
     2  // Use of this source code is governed by a license that can be
     3  // found in the LICENSE file.
     4  
     5  //go:build (!amd64 && !386) || gccgo || appengine || nacl
     6  
     7  package chacha
     8  
     9  import "encoding/binary"
    10  
    11  func init() {
    12  	useSSE2 = false
    13  	useSSSE3 = false
    14  	useAVX = false
    15  	useAVX2 = false
    16  }
    17  
    18  func initialize(state *[64]byte, key []byte, nonce *[16]byte) {
    19  	binary.LittleEndian.PutUint32(state[0:], sigma[0])
    20  	binary.LittleEndian.PutUint32(state[4:], sigma[1])
    21  	binary.LittleEndian.PutUint32(state[8:], sigma[2])
    22  	binary.LittleEndian.PutUint32(state[12:], sigma[3])
    23  	copy(state[16:], key[:])
    24  	copy(state[48:], nonce[:])
    25  }
    26  
    27  func xorKeyStream(dst, src []byte, block, state *[64]byte, rounds int) int {
    28  	return xorKeyStreamGeneric(dst, src, block, state, rounds)
    29  }
    30  
    31  func hChaCha20(out *[32]byte, nonce *[16]byte, key *[32]byte) {
    32  	hChaCha20Generic(out, nonce, key)
    33  }