1// Copyright 2015 The Go Authors. 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 5package sha3 6 7import ( 8 "crypto/subtle" 9 "encoding/binary" 10 "unsafe" 11 12 "golang.org/x/sys/cpu" 13) 14 15// xorIn xors the bytes in buf into the state. 16func xorIn(d *state, buf []byte) { 17 if cpu.IsBigEndian { 18 for i := 0; len(buf) >= 8; i++ { 19 a := binary.LittleEndian.Uint64(buf) 20 d.a[i] ^= a 21 buf = buf[8:] 22 } 23 } else { 24 ab := (*[25 * 64 / 8]byte)(unsafe.Pointer(&d.a)) 25 subtle.XORBytes(ab[:], ab[:], buf) 26 } 27} 28 29// copyOut copies uint64s to a byte buffer. 30func copyOut(d *state, b []byte) { 31 if cpu.IsBigEndian { 32 for i := 0; len(b) >= 8; i++ { 33 binary.LittleEndian.PutUint64(b, d.a[i]) 34 b = b[8:] 35 } 36 } else { 37 ab := (*[25 * 64 / 8]byte)(unsafe.Pointer(&d.a)) 38 copy(b, ab[:]) 39 } 40} 41