update gobgp pkg

This commit is contained in:
Ian Azpiazu
2022-05-16 13:40:57 -04:00
parent 878ee3a63e
commit 80d743ffa5
652 changed files with 136451 additions and 98241 deletions

View File

@@ -1,5 +1,10 @@
package farm
import (
"encoding/binary"
"math/bits"
)
func shiftMix(val uint64) uint64 {
return val ^ (val >> 47)
}
@@ -22,17 +27,17 @@ func hashLen0to16(s []byte) uint64 {
slen := uint64(len(s))
if slen >= 8 {
mul := k2 + slen*2
a := fetch64(s, 0) + k2
b := fetch64(s, int(slen-8))
c := rotate64(b, 37)*mul + a
d := (rotate64(a, 25) + b) * mul
a := binary.LittleEndian.Uint64(s[0:0+8]) + k2
b := binary.LittleEndian.Uint64(s[int(slen-8) : int(slen-8)+8])
c := bits.RotateLeft64(b, -37)*mul + a
d := (bits.RotateLeft64(a, -25) + b) * mul
return hashLen16Mul(c, d, mul)
}
if slen >= 4 {
mul := k2 + slen*2
a := fetch32(s, 0)
return hashLen16Mul(slen+(uint64(a)<<3), uint64(fetch32(s, int(slen-4))), mul)
a := binary.LittleEndian.Uint32(s[0 : 0+4])
return hashLen16Mul(slen+(uint64(a)<<3), uint64(binary.LittleEndian.Uint32(s[int(slen-4):int(slen-4)+4])), mul)
}
if slen > 0 {
a := s[0]
@@ -50,31 +55,31 @@ func hashLen0to16(s []byte) uint64 {
func hashLen17to32(s []byte) uint64 {
slen := len(s)
mul := k2 + uint64(slen*2)
a := fetch64(s, 0) * k1
b := fetch64(s, 8)
c := fetch64(s, slen-8) * mul
d := fetch64(s, slen-16) * k2
return hashLen16Mul(rotate64(a+b, 43)+rotate64(c, 30)+d, a+rotate64(b+k2, 18)+c, mul)
a := binary.LittleEndian.Uint64(s[0:0+8]) * k1
b := binary.LittleEndian.Uint64(s[8 : 8+8])
c := binary.LittleEndian.Uint64(s[slen-8:slen-8+8]) * mul
d := binary.LittleEndian.Uint64(s[slen-16:slen-16+8]) * k2
return hashLen16Mul(bits.RotateLeft64(a+b, -43)+bits.RotateLeft64(c, -30)+d, a+bits.RotateLeft64(b+k2, -18)+c, mul)
}
// Return a 16-byte hash for 48 bytes. Quick and dirty.
// Callers do best to use "random-looking" values for a and b.
func weakHashLen32WithSeedsWords(w, x, y, z, a, b uint64) (uint64, uint64) {
a += w
b = rotate64(b+a+z, 21)
b = bits.RotateLeft64(b+a+z, -21)
c := a
a += x
a += y
b += rotate64(a, 44)
b += bits.RotateLeft64(a, -44)
return a + z, b + c
}
// Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
func weakHashLen32WithSeeds(s []byte, a, b uint64) (uint64, uint64) {
return weakHashLen32WithSeedsWords(fetch64(s, 0),
fetch64(s, 8),
fetch64(s, 16),
fetch64(s, 24),
return weakHashLen32WithSeedsWords(binary.LittleEndian.Uint64(s[0:0+8]),
binary.LittleEndian.Uint64(s[8:8+8]),
binary.LittleEndian.Uint64(s[16:16+8]),
binary.LittleEndian.Uint64(s[24:24+8]),
a,
b)
}
@@ -83,17 +88,17 @@ func weakHashLen32WithSeeds(s []byte, a, b uint64) (uint64, uint64) {
func hashLen33to64(s []byte) uint64 {
slen := len(s)
mul := k2 + uint64(slen)*2
a := fetch64(s, 0) * k2
b := fetch64(s, 8)
c := fetch64(s, slen-8) * mul
d := fetch64(s, slen-16) * k2
y := rotate64(a+b, 43) + rotate64(c, 30) + d
z := hashLen16Mul(y, a+rotate64(b+k2, 18)+c, mul)
e := fetch64(s, 16) * mul
f := fetch64(s, 24)
g := (y + fetch64(s, slen-32)) * mul
h := (z + fetch64(s, slen-24)) * mul
return hashLen16Mul(rotate64(e+f, 43)+rotate64(g, 30)+h, e+rotate64(f+a, 18)+g, mul)
a := binary.LittleEndian.Uint64(s[0:0+8]) * k2
b := binary.LittleEndian.Uint64(s[8 : 8+8])
c := binary.LittleEndian.Uint64(s[slen-8:slen-8+8]) * mul
d := binary.LittleEndian.Uint64(s[slen-16:slen-16+8]) * k2
y := bits.RotateLeft64(a+b, -43) + bits.RotateLeft64(c, -30) + d
z := hashLen16Mul(y, a+bits.RotateLeft64(b+k2, -18)+c, mul)
e := binary.LittleEndian.Uint64(s[16:16+8]) * mul
f := binary.LittleEndian.Uint64(s[24 : 24+8])
g := (y + binary.LittleEndian.Uint64(s[slen-32:slen-32+8])) * mul
h := (z + binary.LittleEndian.Uint64(s[slen-24:slen-24+8])) * mul
return hashLen16Mul(bits.RotateLeft64(e+f, -43)+bits.RotateLeft64(g, -30)+h, e+bits.RotateLeft64(f+a, -18)+g, mul)
}
func naHash64(s []byte) uint64 {
@@ -112,7 +117,7 @@ func naHash64(s []byte) uint64 {
// Internal state consists of 56 bytes: v, w, x, y, and z.
v := uint128{0, 0}
w := uint128{0, 0}
x := seed*k2 + fetch64(s, 0)
x := seed*k2 + binary.LittleEndian.Uint64(s[0:0+8])
y := seed*k1 + 113
z := shiftMix(y*k2+113) * k2
// Set end so that after the loop we have 1 to 64 bytes left to process.
@@ -120,13 +125,13 @@ func naHash64(s []byte) uint64 {
last64Idx := endIdx + ((slen - 1) & 63) - 63
last64 := s[last64Idx:]
for len(s) > 64 {
x = rotate64(x+y+v.lo+fetch64(s, 8), 37) * k1
y = rotate64(y+v.hi+fetch64(s, 48), 42) * k1
x = bits.RotateLeft64(x+y+v.lo+binary.LittleEndian.Uint64(s[8:8+8]), -37) * k1
y = bits.RotateLeft64(y+v.hi+binary.LittleEndian.Uint64(s[48:48+8]), -42) * k1
x ^= w.hi
y += v.lo + fetch64(s, 40)
z = rotate64(z+w.lo, 33) * k1
y += v.lo + binary.LittleEndian.Uint64(s[40:40+8])
z = bits.RotateLeft64(z+w.lo, -33) * k1
v.lo, v.hi = weakHashLen32WithSeeds(s, v.hi*k1, x+w.lo)
w.lo, w.hi = weakHashLen32WithSeeds(s[32:], z+w.hi, y+fetch64(s, 16))
w.lo, w.hi = weakHashLen32WithSeeds(s[32:], z+w.hi, y+binary.LittleEndian.Uint64(s[16:16+8]))
x, z = z, x
s = s[64:]
}
@@ -136,13 +141,13 @@ func naHash64(s []byte) uint64 {
w.lo += (uint64(slen-1) & 63)
v.lo += w.lo
w.lo += v.lo
x = rotate64(x+y+v.lo+fetch64(s, 8), 37) * mul
y = rotate64(y+v.hi+fetch64(s, 48), 42) * mul
x = bits.RotateLeft64(x+y+v.lo+binary.LittleEndian.Uint64(s[8:8+8]), -37) * mul
y = bits.RotateLeft64(y+v.hi+binary.LittleEndian.Uint64(s[48:48+8]), -42) * mul
x ^= w.hi * 9
y += v.lo*9 + fetch64(s, 40)
z = rotate64(z+w.lo, 33) * mul
y += v.lo*9 + binary.LittleEndian.Uint64(s[40:40+8])
z = bits.RotateLeft64(z+w.lo, -33) * mul
v.lo, v.hi = weakHashLen32WithSeeds(s, v.hi*mul, x+w.lo)
w.lo, w.hi = weakHashLen32WithSeeds(s[32:], z+w.hi, y+fetch64(s, 16))
w.lo, w.hi = weakHashLen32WithSeeds(s[32:], z+w.hi, y+binary.LittleEndian.Uint64(s[16:16+8]))
x, z = z, x
return hashLen16Mul(hashLen16Mul(v.lo, w.lo, mul)+shiftMix(y)*k0+z, hashLen16Mul(v.hi, w.hi, mul)+x, mul)
}