xor_unaligned.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // +build amd64 386 ppc64le
  5. // +build !appengine
  6. package sha3
  7. import "unsafe"
  8. func xorInUnaligned(d *state, buf []byte) {
  9. bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0]))
  10. n := len(buf)
  11. if n >= 72 {
  12. d.a[0] ^= bw[0]
  13. d.a[1] ^= bw[1]
  14. d.a[2] ^= bw[2]
  15. d.a[3] ^= bw[3]
  16. d.a[4] ^= bw[4]
  17. d.a[5] ^= bw[5]
  18. d.a[6] ^= bw[6]
  19. d.a[7] ^= bw[7]
  20. d.a[8] ^= bw[8]
  21. }
  22. if n >= 104 {
  23. d.a[9] ^= bw[9]
  24. d.a[10] ^= bw[10]
  25. d.a[11] ^= bw[11]
  26. d.a[12] ^= bw[12]
  27. }
  28. if n >= 136 {
  29. d.a[13] ^= bw[13]
  30. d.a[14] ^= bw[14]
  31. d.a[15] ^= bw[15]
  32. d.a[16] ^= bw[16]
  33. }
  34. if n >= 144 {
  35. d.a[17] ^= bw[17]
  36. }
  37. if n >= 168 {
  38. d.a[18] ^= bw[18]
  39. d.a[19] ^= bw[19]
  40. d.a[20] ^= bw[20]
  41. }
  42. }
  43. func copyOutUnaligned(d *state, buf []byte) {
  44. ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0]))
  45. copy(buf, ab[:])
  46. }
  47. var (
  48. xorIn = xorInUnaligned
  49. copyOut = copyOutUnaligned
  50. )
  51. const xorImplementationUnaligned = "unaligned"