github.com/turingchain2020/turingchain@v1.1.21/common/crypto/sha3/xor_generic.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Copyright 2015 The Go Authors. All rights reserved.
     6  // Use of this source code is governed by a BSD-style
     7  // license that can be found in the LICENSE file.
     8  
     9  package sha3
    10  
    11  import "encoding/binary"
    12  
    13  // xorInGeneric xors the bytes in buf into the state; it
    14  // makes no non-portable assumptions about memory layout
    15  // or alignment.
    16  func xorInGeneric(d *state, buf []byte) {
    17  	n := len(buf) / 8
    18  
    19  	for i := 0; i < n; i++ {
    20  		a := binary.LittleEndian.Uint64(buf)
    21  		d.a[i] ^= a
    22  		buf = buf[8:]
    23  	}
    24  }
    25  
    26  // copyOutGeneric copies ulint64s to a byte buffer.
    27  func copyOutGeneric(d *state, b []byte) {
    28  	for i := 0; len(b) >= 8; i++ {
    29  		binary.LittleEndian.PutUint64(b, d.a[i])
    30  		b = b[8:]
    31  	}
    32  }