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