xor_generic.go 680 B

12345678910111213141516171819202122232425262728
  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. package sha3
  5. import "encoding/binary"
  6. // xorInGeneric xors the bytes in buf into the state; it
  7. // makes no non-portable assumptions about memory layout
  8. // or alignment.
  9. func xorInGeneric(d *state, buf []byte) {
  10. n := len(buf) / 8
  11. for i := 0; i < n; i++ {
  12. a := binary.LittleEndian.Uint64(buf)
  13. d.a[i] ^= a
  14. buf = buf[8:]
  15. }
  16. }
  17. // copyOutGeneric copies ulint64s to a byte buffer.
  18. func copyOutGeneric(d *state, b []byte) {
  19. for i := 0; len(b) >= 8; i++ {
  20. binary.LittleEndian.PutUint64(b, d.a[i])
  21. b = b[8:]
  22. }
  23. }