From 579efc22a0344f64e99d096d18fe8f6fa9698d97 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Wed, 9 Mar 2011 14:27:41 +0100 Subject: [PATCH] implement nsec3 label hashing --- nsec3.go | 23 +++++++++++++---------- nsec3_test.go | 14 +++++++++++--- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/nsec3.go b/nsec3.go index d0b0d44a..cdcbf629 100644 --- a/nsec3.go +++ b/nsec3.go @@ -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) } diff --git a/nsec3_test.go b/nsec3_test.go index 8fb0fdf3..c287a73a 100644 --- a/nsec3_test.go +++ b/nsec3_test.go @@ -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() + } }