9 // HashName hashes a string (label) according to RFC 5155. It returns the hashed string in uppercase.
10 func HashName(label string, ha uint8, iter uint16, salt string) string {
15 wireSalt := make([]byte, hex.DecodedLen(len(salt)))
16 n, err := packStringHex(salt, wireSalt, 0)
20 wireSalt = wireSalt[:n]
22 name := make([]byte, 255)
23 off, err := PackDomainName(strings.ToLower(label), name, 0, nil, false)
36 for k := uint16(0); k < iter; k++ {
40 nsec3 = s.Sum(nsec3[:0])
43 return toBase32(nsec3)
46 // Cover returns true if a name is covered by the NSEC3 record
47 func (rr *NSEC3) Cover(name string) bool {
48 nameHash := HashName(name, rr.Hash, rr.Iterations, rr.Salt)
49 owner := strings.ToUpper(rr.Hdr.Name)
50 labelIndices := Split(owner)
51 if len(labelIndices) < 2 {
54 ownerHash := owner[:labelIndices[1]-1]
55 ownerZone := owner[labelIndices[1]:]
56 if !IsSubDomain(ownerZone, strings.ToUpper(name)) { // name is outside owner zone
60 nextHash := rr.NextDomain
62 // if empty interval found, try cover wildcard hashes so nameHash shouldn't match with ownerHash
63 if ownerHash == nextHash && nameHash != ownerHash { // empty interval
66 if ownerHash > nextHash { // end of zone
67 if nameHash > ownerHash { // covered since there is nothing after ownerHash
70 return nameHash < nextHash // if nameHash is before beginning of zone it is covered
72 if nameHash < ownerHash { // nameHash is before ownerHash, not covered
75 return nameHash < nextHash // if nameHash is before nextHash is it covered (between ownerHash and nextHash)
78 // Match returns true if a name matches the NSEC3 record
79 func (rr *NSEC3) Match(name string) bool {
80 nameHash := HashName(name, rr.Hash, rr.Iterations, rr.Salt)
81 owner := strings.ToUpper(rr.Hdr.Name)
82 labelIndices := Split(owner)
83 if len(labelIndices) < 2 {
86 ownerHash := owner[:labelIndices[1]-1]
87 ownerZone := owner[labelIndices[1]:]
88 if !IsSubDomain(ownerZone, strings.ToUpper(name)) { // name is outside owner zone
91 if ownerHash == nameHash {