implement nsec3 label hashing
This commit is contained in:
parent
d3f5e42740
commit
579efc22a0
23
nsec3.go
23
nsec3.go
|
@ -22,28 +22,31 @@ func Nsec3Hash(label string, ha int, iterations int, salt string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
wire = wire[:n]
|
wire = wire[:n]
|
||||||
owner := make([]byte, 255)
|
name := make([]byte, 255)
|
||||||
off, ok1 := packDomainName(strings.ToLower(label), owner, 0)
|
off, ok1 := packDomainName(strings.ToLower(label), name, 0)
|
||||||
if !ok1 {
|
if !ok1 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
owner = owner[:off]
|
name = name[:off]
|
||||||
|
|
||||||
var s hash.Hash
|
var s hash.Hash
|
||||||
switch ha {
|
switch ha {
|
||||||
case HashSHA1:
|
case HashSHA1:
|
||||||
s = sha1.New()
|
s = sha1.New()
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// k = 0
|
// k = 0
|
||||||
h := append(owner, wire...)
|
name = append(name, wire...)
|
||||||
io.WriteString(s, string(h))
|
io.WriteString(s, string(name))
|
||||||
nsec3 := s.Sum()
|
nsec3 := s.Sum()
|
||||||
|
// k > 0
|
||||||
for k := 1; k < iterations; k++ {
|
for k := 0; k < iterations; k++ {
|
||||||
h = append(nsec3, wire...)
|
s.Reset()
|
||||||
io.WriteString(s, string(h))
|
nsec3 = append(nsec3, wire...)
|
||||||
|
io.WriteString(s, string(nsec3))
|
||||||
nsec3 = s.Sum()
|
nsec3 = s.Sum()
|
||||||
}
|
}
|
||||||
return unpackBase32(nsec3)
|
return unpackBase32(nsec3)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPackNsec3(t *testing.T) {
|
func TestPackNsec3(t *testing.T) {
|
||||||
nsec3 := Nsec3Hash("dnsex.nl", 1, 0, "DEAD")
|
nsec3 := Nsec3Hash("dnsex.nl",HashSHA1 , 0, "DEAD")
|
||||||
t.Logf("%v\n", nsec3)
|
if nsec3 != "ROCCJAE8BJJU7HN6T7NG3TNM8ACRS87J" {
|
||||||
t.Fail()
|
t.Logf("%v\n", nsec3)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
nsec3 = Nsec3Hash("a.b.c.example.org",HashSHA1 , 2, "DEAD")
|
||||||
|
if nsec3 != "6LQ07OAHBTOOEU2R9ANI2AT70K5O0RCG" {
|
||||||
|
t.Logf("%v\n", nsec3)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue