implement nsec3 label hashing

This commit is contained in:
Miek Gieben 2011-03-09 14:27:41 +01:00
parent d3f5e42740
commit 579efc22a0
2 changed files with 24 additions and 13 deletions

View File

@ -22,28 +22,31 @@ func Nsec3Hash(label string, ha int, iterations int, salt string) string {
return ""
}
wire = wire[:n]
owner := make([]byte, 255)
off, ok1 := packDomainName(strings.ToLower(label), owner, 0)
name := make([]byte, 255)
off, ok1 := packDomainName(strings.ToLower(label), name, 0)
if !ok1 {
return ""
}
owner = owner[:off]
name = name[:off]
var s hash.Hash
switch ha {
case HashSHA1:
s = sha1.New()
default:
return ""
}
// k = 0
h := append(owner, wire...)
io.WriteString(s, string(h))
name = append(name, wire...)
io.WriteString(s, string(name))
nsec3 := s.Sum()
for k := 1; k < iterations; k++ {
h = append(nsec3, wire...)
io.WriteString(s, string(h))
// k > 0
for k := 0; k < iterations; k++ {
s.Reset()
nsec3 = append(nsec3, wire...)
io.WriteString(s, string(nsec3))
nsec3 = s.Sum()
}
}
return unpackBase32(nsec3)
}

View File

@ -5,7 +5,15 @@ import (
)
func TestPackNsec3(t *testing.T) {
nsec3 := Nsec3Hash("dnsex.nl", 1, 0, "DEAD")
t.Logf("%v\n", nsec3)
t.Fail()
nsec3 := Nsec3Hash("dnsex.nl",HashSHA1 , 0, "DEAD")
if nsec3 != "ROCCJAE8BJJU7HN6T7NG3TNM8ACRS87J" {
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()
}
}