forked from TrueCloudLab/tzhash
Perform allocation outside of mulBitRightPure
This commit is contained in:
parent
6c75cc0871
commit
7c12188650
1 changed files with 20 additions and 20 deletions
40
tz/pure.go
40
tz/pure.go
|
@ -43,15 +43,16 @@ func (d *digestp) Reset() {
|
||||||
|
|
||||||
func (d *digestp) Write(data []byte) (n int, err error) {
|
func (d *digestp) Write(data []byte) (n int, err error) {
|
||||||
n = len(data)
|
n = len(data)
|
||||||
|
tmp := new(gogf127.GF127)
|
||||||
for _, b := range data {
|
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&0x80 != 0, tmp)
|
||||||
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&0x40 != 0, tmp)
|
||||||
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&0x20 != 0, tmp)
|
||||||
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&0x10 != 0, tmp)
|
||||||
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&0x08 != 0, tmp)
|
||||||
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&0x04 != 0, tmp)
|
||||||
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&0x02 != 0, tmp)
|
||||||
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&0x01 != 0, tmp)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -64,29 +65,28 @@ func (d *digestp) BlockSize() int {
|
||||||
return hashBlockSize
|
return hashBlockSize
|
||||||
}
|
}
|
||||||
|
|
||||||
func mulBitRightPure(c00, c01, c10, c11 *gogf127.GF127, bit bool) {
|
func mulBitRightPure(c00, c01, c10, c11 *gogf127.GF127, bit bool, tmp *gogf127.GF127) {
|
||||||
var tmp gogf127.GF127
|
|
||||||
if bit {
|
if bit {
|
||||||
tmp = *c00
|
*tmp = *c00
|
||||||
gogf127.Mul10(c00, c00)
|
gogf127.Mul10(c00, c00)
|
||||||
gogf127.Add(c00, c01, c00)
|
gogf127.Add(c00, c01, c00)
|
||||||
gogf127.Mul11(&tmp, &tmp)
|
gogf127.Mul11(tmp, tmp)
|
||||||
gogf127.Add(c01, &tmp, c01)
|
gogf127.Add(c01, tmp, c01)
|
||||||
|
|
||||||
tmp = *c10
|
*tmp = *c10
|
||||||
gogf127.Mul10(c10, c10)
|
gogf127.Mul10(c10, c10)
|
||||||
gogf127.Add(c10, c11, c10)
|
gogf127.Add(c10, c11, c10)
|
||||||
gogf127.Mul11(&tmp, &tmp)
|
gogf127.Mul11(tmp, tmp)
|
||||||
gogf127.Add(c11, &tmp, c11)
|
gogf127.Add(c11, tmp, c11)
|
||||||
} else {
|
} else {
|
||||||
tmp = *c00
|
*tmp = *c00
|
||||||
gogf127.Mul10(c00, c00)
|
gogf127.Mul10(c00, c00)
|
||||||
gogf127.Add(c00, c01, c00)
|
gogf127.Add(c00, c01, c00)
|
||||||
*c01 = tmp
|
*c01 = *tmp
|
||||||
|
|
||||||
tmp = *c10
|
*tmp = *c10
|
||||||
gogf127.Mul10(c10, c10)
|
gogf127.Mul10(c10, c10)
|
||||||
gogf127.Add(c10, c11, c10)
|
gogf127.Add(c10, c11, c10)
|
||||||
*c11 = tmp
|
*c11 = *tmp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue