Commits

Eric Roshan Eisner committed d4f2624 Draft

use encoding/binary for serialization

  • Participants
  • Parent commits b7271d1

Comments (0)

Files changed (1)

 package sha3
 
 import (
+	"encoding/binary"
 	"hash"
 )
 
 // KeccakF[1600] permutation.
 func (d *keccak) absorb(chunk []byte) {
 	for i := 0; i < d.blocksize; i += 8 {
-		d.state[i/8] ^= readLane(chunk[i : i+8])
+		d.state[i/8] ^= binary.LittleEndian.Uint64(chunk[i : i+8])
 	}
 	block(&d.state)
 }
 	d.buf[d.blocksize-1] |= 0x80
 
 	for i := 0; i < d.blocksize; i += 8 {
-		d.state[i/8] ^= readLane(d.buf[i : i+8])
+		d.state[i/8] ^= binary.LittleEndian.Uint64(d.buf[i : i+8])
 	}
 	d.closed = true
 }
 	}
 	block(&d.state)
 	for i := 0; i < d.blocksize; i += 8 {
-		writeLane(d.buf[i:i+8], d.state[i/8])
+		binary.LittleEndian.PutUint64(d.buf[i:i+8], d.state[i/8])
 	}
 }
 
 	d.squeeze()
 	return append(in, d.buf[:d.size]...)
 }
-
-func readLane(b []byte) uint64 {
-	return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
-}
-
-func writeLane(b []byte, x uint64) {
-	for i := 0; i < 8; i++ {
-		b[i] = byte(x)
-		x >>= 8
-	}
-}