1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use fnv1-a to construct the SPI

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch 2016-07-19 11:51:29 -07:00
parent 253c103b8c
commit ddff1b5a87

View file

@ -5,6 +5,7 @@ import (
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"hash/fnv"
"net" "net"
"sync" "sync"
"syscall" "syscall"
@ -353,13 +354,13 @@ func spExists(sp *netlink.XfrmPolicy) (bool, error) {
} }
func buildSPI(src, dst net.IP, st uint32) int { func buildSPI(src, dst net.IP, st uint32) int {
spi := int(st) b := make([]byte, 4)
f := src[len(src)-4:] binary.BigEndian.PutUint32(b, st)
t := dst[len(dst)-4:] h := fnv.New32a()
for i := 0; i < 4; i++ { h.Write(src)
spi = spi ^ (int(f[i])^int(t[3-i]))<<uint32(8*i) h.Write(b)
} h.Write(dst)
return spi return int(binary.BigEndian.Uint32(h.Sum(nil)))
} }
func buildAeadAlgo(k *key, s int) *netlink.XfrmStateAlgo { func buildAeadAlgo(k *key, s int) *netlink.XfrmStateAlgo {