Source

sha3 / bits_lsb.go

Full commit
// Copyright 2012 Eric Roshan-Eisner. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build amd64 386 !appengine

package sha3

import "unsafe"

func readUint64(b []byte) uint64 {
	return *(*uint64)(unsafe.Pointer(&b[0]))
}

func writeUint64(b []byte, v uint64) {
	*(*uint64)(unsafe.Pointer(&b[0])) = v
}

// Alternative to looping, but only provides 1% benchmark speedup.
func (d *keccak) tableapply(chunk []byte) {
	switch d.blocksize {
	case 144: // 224 bit
		d.state[136/8] ^= readUint64(chunk[136:])
		fallthrough
	case 136: // 256 bit
		d.state[128/8] ^= readUint64(chunk[128:])
		d.state[120/8] ^= readUint64(chunk[120:])
		d.state[112/8] ^= readUint64(chunk[112:])
		d.state[104/8] ^= readUint64(chunk[104:])
		fallthrough
	case 104: // 384 bit
		d.state[96/8] ^= readUint64(chunk[96:])
		d.state[88/8] ^= readUint64(chunk[88:])
		d.state[80/8] ^= readUint64(chunk[80:])
		d.state[72/8] ^= readUint64(chunk[72:])
		fallthrough
	case 72: // 512 bit
		d.state[64/8] ^= readUint64(chunk[64:])
		d.state[56/8] ^= readUint64(chunk[56:])
		d.state[48/8] ^= readUint64(chunk[48:])
		d.state[40/8] ^= readUint64(chunk[40:])
		d.state[32/8] ^= readUint64(chunk[32:])
		d.state[24/8] ^= readUint64(chunk[24:])
		d.state[16/8] ^= readUint64(chunk[16:])
		d.state[8/8] ^= readUint64(chunk[8:])
		d.state[0/8] ^= readUint64(chunk[0:])
	}
}