github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/crypto/sha3/xor_unaligned.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //版权所有2015 The Go作者。版权所有。
    10  //此源代码的使用受BSD样式的控制
    11  //可以在许可文件中找到的许可证。
    12  
    13  //+构建AMD64 386 PPC64LE
    14  //+建设!应用程序引擎
    15  
    16  package sha3
    17  
    18  import "unsafe"
    19  
    20  func xorInUnaligned(d *state, buf []byte) {
    21  	bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0]))
    22  	n := len(buf)
    23  	if n >= 72 {
    24  		d.a[0] ^= bw[0]
    25  		d.a[1] ^= bw[1]
    26  		d.a[2] ^= bw[2]
    27  		d.a[3] ^= bw[3]
    28  		d.a[4] ^= bw[4]
    29  		d.a[5] ^= bw[5]
    30  		d.a[6] ^= bw[6]
    31  		d.a[7] ^= bw[7]
    32  		d.a[8] ^= bw[8]
    33  	}
    34  	if n >= 104 {
    35  		d.a[9] ^= bw[9]
    36  		d.a[10] ^= bw[10]
    37  		d.a[11] ^= bw[11]
    38  		d.a[12] ^= bw[12]
    39  	}
    40  	if n >= 136 {
    41  		d.a[13] ^= bw[13]
    42  		d.a[14] ^= bw[14]
    43  		d.a[15] ^= bw[15]
    44  		d.a[16] ^= bw[16]
    45  	}
    46  	if n >= 144 {
    47  		d.a[17] ^= bw[17]
    48  	}
    49  	if n >= 168 {
    50  		d.a[18] ^= bw[18]
    51  		d.a[19] ^= bw[19]
    52  		d.a[20] ^= bw[20]
    53  	}
    54  }
    55  
    56  func copyOutUnaligned(d *state, buf []byte) {
    57  	ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0]))
    58  	copy(buf, ab[:])
    59  }
    60  
    61  var (
    62  	xorIn   = xorInUnaligned
    63  	copyOut = copyOutUnaligned
    64  )
    65  
    66  const xorImplementationUnaligned = "unaligned"