Perform allocation outside of mulBitRightPure

This commit is contained in:
Evgenii 2019-07-19 19:04:44 +03:00
parent 6c75cc0871
commit 7c12188650

View file

@ -43,15 +43,16 @@ func (d *digestp) Reset() {
func (d *digestp) Write(data []byte) (n int, err error) {
n = len(data)
tmp := new(gogf127.GF127)
for _, b := range data {
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x80 != 0)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x40 != 0)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x20 != 0)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x10 != 0)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x08 != 0)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x04 != 0)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x02 != 0)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x01 != 0)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x80 != 0, tmp)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x40 != 0, tmp)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x20 != 0, tmp)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x10 != 0, tmp)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x08 != 0, tmp)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x04 != 0, tmp)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x02 != 0, tmp)
mulBitRightPure(&d.x[0], &d.x[1], &d.x[2], &d.x[3], b&0x01 != 0, tmp)
}
return
}
@ -64,29 +65,28 @@ func (d *digestp) BlockSize() int {
return hashBlockSize
}
func mulBitRightPure(c00, c01, c10, c11 *gogf127.GF127, bit bool) {
var tmp gogf127.GF127
func mulBitRightPure(c00, c01, c10, c11 *gogf127.GF127, bit bool, tmp *gogf127.GF127) {
if bit {
tmp = *c00
*tmp = *c00
gogf127.Mul10(c00, c00)
gogf127.Add(c00, c01, c00)
gogf127.Mul11(&tmp, &tmp)
gogf127.Add(c01, &tmp, c01)
gogf127.Mul11(tmp, tmp)
gogf127.Add(c01, tmp, c01)
tmp = *c10
*tmp = *c10
gogf127.Mul10(c10, c10)
gogf127.Add(c10, c11, c10)
gogf127.Mul11(&tmp, &tmp)
gogf127.Add(c11, &tmp, c11)
gogf127.Mul11(tmp, tmp)
gogf127.Add(c11, tmp, c11)
} else {
tmp = *c00
*tmp = *c00
gogf127.Mul10(c00, c00)
gogf127.Add(c00, c01, c00)
*c01 = tmp
*c01 = *tmp
tmp = *c10
*tmp = *c10
gogf127.Mul10(c10, c10)
gogf127.Add(c10, c11, c10)
*c11 = tmp
*c11 = *tmp
}
}