github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/crypto/sha3/xor_unaligned.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:37</date> 10 //</624342628749545472> 11 12 //版权所有2015 The Go作者。版权所有。 13 //此源代码的使用受BSD样式的控制 14 //可以在许可文件中找到的许可证。 15 16 //+构建AMD64 386 PPC64LE 17 //+建设!应用程序引擎 18 19 package sha3 20 21 import "unsafe" 22 23 func xorInUnaligned(d *state, buf []byte) { 24 bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0])) 25 n := len(buf) 26 if n >= 72 { 27 d.a[0] ^= bw[0] 28 d.a[1] ^= bw[1] 29 d.a[2] ^= bw[2] 30 d.a[3] ^= bw[3] 31 d.a[4] ^= bw[4] 32 d.a[5] ^= bw[5] 33 d.a[6] ^= bw[6] 34 d.a[7] ^= bw[7] 35 d.a[8] ^= bw[8] 36 } 37 if n >= 104 { 38 d.a[9] ^= bw[9] 39 d.a[10] ^= bw[10] 40 d.a[11] ^= bw[11] 41 d.a[12] ^= bw[12] 42 } 43 if n >= 136 { 44 d.a[13] ^= bw[13] 45 d.a[14] ^= bw[14] 46 d.a[15] ^= bw[15] 47 d.a[16] ^= bw[16] 48 } 49 if n >= 144 { 50 d.a[17] ^= bw[17] 51 } 52 if n >= 168 { 53 d.a[18] ^= bw[18] 54 d.a[19] ^= bw[19] 55 d.a[20] ^= bw[20] 56 } 57 } 58 59 func copyOutUnaligned(d *state, buf []byte) { 60 ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0])) 61 copy(buf, ab[:]) 62 } 63 64 var ( 65 xorIn = xorInUnaligned 66 copyOut = copyOutUnaligned 67 ) 68 69 const xorImplementationUnaligned = "unaligned" 70