diff /home/ceti/Delphinusdns/delphinusdnsd
commit - 1db469f3c1061122504f19e239119d624028b88d
path + /home/ceti/Delphinusdns/delphinusdnsd
blob - /dev/null
file + base32.c (mode 644)
--- /dev/null
+++ base32.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2015-2025 Peter J. Philipp <pbug44@delphinusdns.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+#include <ctype.h>
+
+char *			base32hex_encode(u_char *, int);
+int			base32hex_decode(u_char *, u_char *, int);
+static uint64_t		stuff64(uint64_t, uint64_t, int);
+
+#define BASE32_ENCODE_IN	8	/* encode in */
+#define BASE32_ENCODE_OUT	5	/* encode out */
+
+#define BASE32_DECODE_IN	5	/* decode in */
+#define BASE32_DECODE_OUT	8	/* decode out */
+
+#define TABLE_ELEMENTS	256
+
+/* base32 lookup table */
+struct b32_table {
+	uint8_t trans;
+};
+
+struct b32_dectable {
+	short trans;
+};
+
+static struct b32_table encode_table[] = {
+	{0x30} , { 0x31} , { 0x32} , { 0x33} , { 0x34} , { 0x35} , { 0x36} , { 0x37},
+	{0x38} , { 0x39} , { 0x61} , { 0x62} , { 0x63} , { 0x64} , { 0x65} , { 0x66},
+	{0x67} , { 0x68} , { 0x69} , { 0x6a} , { 0x6b} , { 0x6c} , { 0x6d} , { 0x6e},
+	{0x6f} , { 0x70} , { 0x71} , { 0x72} , { 0x73} , { 0x74} , { 0x75} , { 0x76}
+};
+
+struct b32_dectable decode_table[] = {
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+
+	{ 0} , { 1 } , {  2} , {  3} , {  4} , {  5} , {  6} , {  7},
+	{ 8} , { 9 } , { -1} , { -1} , { -1} , { 32} , { -1} , { -1},
+
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1},
+
+	{-1} , { 10} , { 11} , { 12} , { 13} , { 14} , { 15} , { 16},
+	{17} , { 18} , { 19} , { 20} , { 21} , { 22} , { 23} , { 24},
+
+	{25} , { 26} , { 27} , { 28} , { 29} , { 30 }, { 31} , { -1},
+	{-1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1} , { -1}
+};
+
+int
+base32hex_decode(u_char *input, u_char *output, int output_len)
+{
+	struct b32_dectable lookup[TABLE_ELEMENTS];
+
+	u_char *q = output, *p;
+
+	int i, j, retlen = 0;
+	int k, len, clen = 0;
+	short tmp;
+	uint64_t tb;
+
+	/* patch the lookup table with -1's */
+	memset((char *)&lookup, -1, sizeof(lookup));
+	memcpy((char *)&lookup, (char *)&decode_table, sizeof(decode_table));
+
+	memset(output, 0, output_len);
+	tb = 0;
+	len = strlen(input);
+	p = strchr(input, '=');
+	if (p != NULL)
+		clen = (((p - input) * 5) / 8);
+	else
+		clen = (len * 5) / 8;
+
+	for (i = 0; i < len; i += 8) {
+		for (j = 0; j < 8; j++) {
+			if ((i + j) > len) {
+				tb <<= BASE32_DECODE_IN;
+				continue;
+			}
+
+			tmp = lookup[input[i + j]].trans;
+			switch (tmp) {
+			case -1:
+				return -1;
+			case 32:
+				tb <<= BASE32_DECODE_IN;
+				break;
+			default:
+				tb = stuff64(tmp & 0x1f, tb, BASE32_DECODE_IN);
+				break;
+			}
+		}
+
+		for (k = 4; k >= 0; k--, retlen++) {
+			if ((retlen + 1) > output_len) {
+				return -1;
+			}
+
+			*(q + k) = (tb & ((1 << BASE32_DECODE_OUT) - 1));
+			tb >>= BASE32_DECODE_OUT;
+		}
+
+
+		q += 5;
+		tb = 0;
+	}
+
+	return (clen);
+}
+
+/*
+ * this function all of a sudden needs to free the result!  this is version 2 of it!
+ */
+
+char *
+base32hex_encode(u_char *input, int len)
+{
+	struct b32_table lookup[32];
+
+	char *ret = NULL, *p = NULL;
+
+	uint8_t *ui = (uint8_t *)&input[0];
+
+	uint64_t tb = 0;
+	int i, j;
+	int k, outlen;
+	uint8_t tmp;
+
+	outlen = (((len * BASE32_ENCODE_IN) / BASE32_ENCODE_OUT) + 16);
+
+	ret = calloc(1, outlen);
+	if (ret == NULL)
+		return NULL;
+
+	outlen = (((len * BASE32_ENCODE_IN) / BASE32_ENCODE_OUT) + 1);
+	
+	p = ret;
+
+	memcpy((char *)&lookup, (char *)&encode_table, sizeof(lookup));
+
+	tb = 0;
+	for (i = 0; i < len; i += 5) {
+		for (j = 0, k = 1; j < 5; j++) {
+			if ((i + j) >= len) {
+				tb <<= 8;
+				k++;
+			} else {
+				tb = stuff64(*ui, tb, BASE32_ENCODE_IN); /* in is 8 */
+				ui++;
+			}
+
+		}
+
+		/* check for buffer overflow on return, not likely to happen */
+		if (((p + 8) - ret) > (outlen + 8)) {
+			free(ret);
+			return NULL;
+		}
+			
+		for (k = 7; k >= 0; k--) {
+			tmp = (tb & ((1 << BASE32_ENCODE_OUT) - 1));
+			if (((p + k) - ret) >= outlen) {
+				*(p + k) = '=';
+			} else {
+				*(p + k) = lookup[tmp].trans;
+			}
+
+			tb >>= 5;
+		}
+
+		p += 8;
+		tb = 0;
+	}
+
+	return (ret);
+}
+
+static uint64_t
+stuff64(uint64_t input, uint64_t num, int bitshift) {
+	num <<= bitshift;
+	num |= (input & ((1 << bitshift) - 1));
+
+	return (num);
+}
blob - fb0ad715ae2d4cebbbab6b45e15caf589b231b2e
file + dddctl/Makefile.freebsd
--- dddctl/Makefile.freebsd
+++ dddctl/Makefile.freebsd
@@ -2,12 +2,16 @@
 
 PROG=dddctl
 
-OPENBSD_COMPAT=openbsd-compat/getdtablecount.c openbsd-compat/getdtablesize.c openbsd-compat/imsg-buffer.c openbsd-compat/imsg.c openbsd-compat/vis.c
+OPENBSD_COMPAT=  openbsd-compat/getdtablecount.c openbsd-compat/getdtablesize.c
+OPENBSD_COMPAT+= openbsd-compat/imsg-buffer.c openbsd-compat/imsg.c openbsd-compat/vis.c
 
-SRCS=dddctl.c parse.y base64.c dnssec.c util.c ent.c db.c raxfr.c tsig.c region.c  sign.c query.c crypto.c ${OPENBSD_COMPAT}
+SRCS=  dddctl.c parse.y base64.c dnssec.c util.c ent.c db.c raxfr.c 
+SRCS+= tsig.c region.c  sign.c query.c crypto.c base32.c
+SRCS+= ${OPENBSD_COMPAT}
 
-CFLAGS= -Wall -g  -I${.CURDIR}/.. -I/usr/local/include 
+CFLAGS=  -Wall -g  -I${.CURDIR}/.. -I/usr/local/include 
 CFLAGS+= -L/usr/local/lib -DUSE_OPENSSL -I$(.CURDIR)/../openbsd-compat/
+
 LDFLAGS= -Wall -g -L /usr/local/lib -DUSE_OPENSSL
 LDADD= -lcrypto -lssl -ltls
 
blob - 0e2a443bf9f360d5a4d67f8b2b17cc14a6fd2efc
file + dddctl/Makefile.netbsd
--- dddctl/Makefile.netbsd
+++ dddctl/Makefile.netbsd
@@ -2,12 +2,14 @@
 
 PROG=dddctl
 
-SRCS=dddctl.c parse.y base64.c dnssec.c util.c ent.c db.c raxfr.c tsig.c region.c imsg-buffer.c imsg.c sign.c query.c crypto.c
+SRCS=  dddctl.c parse.y base64.c dnssec.c util.c ent.c db.c raxfr.c tsig.c region.c 
+SRCS+= imsg-buffer.c imsg.c sign.c query.c crypto.c base32.c
 
-CFLAGS= -g 
+CFLAGS=  -g 
 CFLAGS+= -I${.CURDIR}/..  -I/usr/pkg/libressl/include -DUSE_OPENSSL
+
 LDFLAGS= -g -L/usr/pkg/lib -L/usr/pkg/libressl/lib  -R/usr/pkg/lib -DUSE_OPENSSL
-LDADD= -lcrypto -lssl -ltls
+LDADD=   -lcrypto -lssl -ltls
 
 # take out -Werror
 NOGCCERROR=
blob - 1e708e3b76c54db809618c647de7ade1de491fa2
file + dddctl/Makefile.openbsd
--- dddctl/Makefile.openbsd
+++ dddctl/Makefile.openbsd
@@ -2,12 +2,14 @@
 
 PROG=dddctl
 
-SRCS=dddctl.c parse.y base64.c dnssec.c util.c ent.c db.c raxfr.c tsig.c region.c query.c sign.c crypto.c
+SRCS=  dddctl.c parse.y base64.c dnssec.c util.c ent.c db.c raxfr.c
+SRCS+= tsig.c region.c query.c sign.c crypto.c base32.c
 
-CFLAGS= -Wall -g  -I${.CURDIR}/.. -DUSE_OPENSSL
+CFLAGS=  -Wall -g  -I${.CURDIR}/.. -DUSE_OPENSSL
 LDFLAGS= -Wall -g 
-LDADD= -lcrypto -lssl -lutil -ltls
 
+LDADD=   -lcrypto -lssl -lutil -ltls
+
 OBJDIR=.
 BINDIR=/usr/local/bin
 MANDIR=/usr/local/man/man
blob - 08286564fb33f086f38400d77ccf9e591a5f41ba
file + dddctl.c
--- dddctl.c
+++ dddctl.c
@@ -1094,6 +1094,7 @@ print_rbt_bind(FILE *of, struct rbtree *rbt)
 	struct rr *rrp2 = NULL;
 
 	char buf[4096];
+	char *base32 = NULL, *tmp = NULL;
 
 	if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
 		if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
@@ -1636,6 +1637,15 @@ print_rbt_bind(FILE *of, struct rbtree *rbt)
 			return -1;
 		}
 		
+		base32 = base32hex_encode((u_char *)((struct nsec3 *)rrp->rdata)->next, ((struct nsec3 *)rrp->rdata)->nextlen);
+		if (base32 == NULL) {
+			dolog(LOG_INFO, "base32hex_encode: %s\n", strerror(errno));
+			return -1;
+		}
+		if ((tmp = strchr(base32, '=')) != NULL) {
+			*tmp = '\0';
+		}
+
 		fprintf(of, "%s %d IN NSEC3 %d %d %d %s %s %s\n",
 			convert_name(rbt->zone, rbt->zonelen),
 			rrset->ttl,
@@ -1643,8 +1653,10 @@ print_rbt_bind(FILE *of, struct rbtree *rbt)
 			((struct nsec3 *)rrp->rdata)->flags,
 			((struct nsec3 *)rrp->rdata)->iterations,
 			(((struct nsec3 *)rrp->rdata)->saltlen == 0) ? "-" : bin2hex(((struct nsec3 *)rrp->rdata)->salt, ((struct nsec3 *)rrp->rdata)->saltlen),
-			base32hex_encode((u_char *)((struct nsec3 *)rrp->rdata)->next, ((struct nsec3 *)rrp->rdata)->nextlen),
+			base32, 
 			bitmap2human(((struct nsec3 *)rrp->rdata)->bitmap, ((struct nsec3 *)rrp->rdata)->bitmap_len));
+
+		free(base32);
 	}
 	if ((rrset = find_rr(rbt, DNS_TYPE_NSEC)) != NULL) {
 		if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
blob - 18b9cf90c1894893d9beb232310330c473ab66c4
file + delphinusdnsd/Makefile.freebsd
--- delphinusdnsd/Makefile.freebsd
+++ delphinusdnsd/Makefile.freebsd
@@ -2,15 +2,23 @@
 
 PROG=delphinusdnsd
 
-OPENBSD_COMPAT=openbsd-compat/vis.c openbsd-compat/getdtablecount.c openbsd-compat/getdtablesize.c openbsd-compat/imsg-buffer.c openbsd-compat/imsg.c
+OPENBSD_COMPAT=  openbsd-compat/vis.c openbsd-compat/getdtablecount.c 
+OPENBSD_COMPAT+= openbsd-compat/getdtablesize.c openbsd-compat/imsg-buffer.c 
+OPENBSD_COMPAT+= openbsd-compat/imsg.c
 
-SRCS=delphinusdnsd.c do53.c do53t.c dot.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c passlist.c base64.c dnssec.c util.c ent.c db.c tsig.c raxfr.c forward.c cache.c zone.c passname.c siphash.c crypto.c ${OPENBSD_COMPAT}
+SRCS=  delphinusdnsd.c do53.c do53t.c dot.c parse.y reply.c 
+SRCS+= additional.c region.c log.c axfr.c filter.c ratelimit.c 
+SRCS+= passlist.c base64.c dnssec.c util.c ent.c db.c tsig.c
+SRCS+= raxfr.c forward.c cache.c zone.c passname.c siphash.c crypto.c 
+SRCS+= base32.c
+SRCS+= ${OPENBSD_COMPAT}
 
 
 CFLAGS= -Wall -g -L/usr/local/lib -DUSE_OPENSSL -DBROKEN_STRNVIS -D_VIS_H_
 CFLAGS+= -I${.CURDIR}/..  -I$(.CURDIR)/../openbsd-compat -I/usr/local/include
+
 LDFLAGS= -Wall -g -L/usr/local/lib -DUSE_OPENSSL
-LDADD= -lcrypto -lssl -ltls
+LDADD=   -lcrypto -lssl -ltls
 LDLIBS= 
 
 OBJDIR=.
blob - f4808d0065464790fcc67546e4d1316b2c2762ea
file + delphinusdnsd/Makefile.netbsd
--- delphinusdnsd/Makefile.netbsd
+++ delphinusdnsd/Makefile.netbsd
@@ -2,12 +2,17 @@
 
 PROG=delphinusdnsd
 
-SRCS=delphinusdnsd.c do53.c do53t.c dot.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c passlist.c base64.c dnssec.c util.c ent.c db.c imsg-buffer.c imsg.c tsig.c raxfr.c forward.c cache.c zone.c passname.c siphash.c crypto.c
+SRCS=  delphinusdnsd.c do53.c do53t.c dot.c parse.y reply.c
+SRCS+= additional.c region.c log.c axfr.c filter.c ratelimit.c
+SRCS+= passlist.c base64.c dnssec.c util.c ent.c db.c
+SRCS+= imsg-buffer.c imsg.c tsig.c raxfr.c forward.c cache.c
+SRCS+= zone.c passname.c siphash.c crypto.c base32.c
 
-CFLAGS= -g
+CFLAGS=  -g
 CFLAGS+= -I${.CURDIR}/..  -I/usr/pkg/libressl/include -DUSE_OPENSSL
+
 LDFLAGS= -g -L/usr/pkg/lib -L/usr/pkg/libressl/lib -R/usr/pkg/lib -DUSE_OPENSSL
-LDADD= -lcrypto -lssl -ltls
+LDADD=   -lcrypto -lssl -ltls
 
 OBJDIR=.
 BINDIR=/usr/local/sbin
blob - 8832f091bf29ff6fcd285e5338e3a94bf8a2d012
file + delphinusdnsd/Makefile.openbsd
--- delphinusdnsd/Makefile.openbsd
+++ delphinusdnsd/Makefile.openbsd
@@ -2,13 +2,19 @@
 
 PROG=delphinusdnsd
 
-SRCS=delphinusdnsd.c do53.c do53t.c dot.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c passlist.c base64.c dnssec.c util.c ent.c db.c tsig.c raxfr.c forward.c cache.c zone.c passname.c crypto.c
+SRCS=  delphinusdnsd.c do53.c do53t.c dot.c parse.y reply.c
+SRCS+= additional.c region.c log.c axfr.c filter.c ratelimit.c
+SRCS+= passlist.c base64.c dnssec.c util.c ent.c db.c tsig.c
+SRCS+= raxfr.c forward.c cache.c zone.c passname.c crypto.c
+SRCS+= base32.c
 
 #CFLAGS= -DDEBUG  -g -Wall
-CFLAGS= -Wall -g -DUSE_OPENSSL
+
+CFLAGS=  -Wall -g -DUSE_OPENSSL
 CFLAGS+= -I${.CURDIR}/.. 
+
 LDFLAGS= -Wall -g
-LDADD= -lcrypto -lssl -lutil -ltls 
+LDADD=   -lcrypto -lssl -lutil -ltls 
 LDLIBS= 
 
 OBJDIR=.
blob - bf3b4071efdcd4f6619684c5b4bedb41ec81c966
file + dnssec.c
--- dnssec.c
+++ dnssec.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2024 Peter J. Philipp <pbug44@delphinusdns.org>
+ * Copyright (c) 2015-2025 Peter J. Philipp <pbug44@delphinusdns.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -75,9 +75,6 @@ int nsec3_comp(const void *a, const void *b);
 int count_dots(char *name);
 char * next_closer_name(char *, int, char *, int, int *);
 char * hash_name(char *name, int len, struct nsec3param *n3p);
-char * base32hex_encode(u_char *input, int len);
-int 	base32hex_decode(u_char *, u_char *);
-void 	mysetbit(u_char *, int);
 int finalize_nsec3(void);
 struct rbtree * nsec3_closest_encloser(char *, int, struct rbtree *, ddDB *);
 struct rbtree * nsec3_closest_encloser_wild(char *, int, struct rbtree *, ddDB *);
@@ -102,6 +99,9 @@ extern size_t 		plength(void *, void *);
 extern char *		advance_label(char *, int *);
 extern struct zoneentry *      zone_findzone(struct rbtree *);
 
+extern char * 		base32hex_encode(u_char *input, int len);
+extern int		base32hex_decode(u_char *, u_char *, int);
+
 extern int debug;
 
 SLIST_HEAD(listhead, dnssecentry) dnssechead;
@@ -562,6 +562,7 @@ hash_name(char *name, int len, struct nsec3param *n3p)
 {
 	SHA_CTX ctx;
 	u_char md[20];
+	char *tmp = NULL, *base32 = NULL;
 	int i;
 
 	if (n3p->algorithm != 1) {
@@ -581,168 +582,19 @@ hash_name(char *name, int len, struct nsec3param *n3p)
 		SHA1_Final(md, &ctx);
 	}
 
-	
-	return(base32hex_encode(md, sizeof(md)));
-}
-
-void
-mysetbit(u_char *input, int pos)
-{
-	int bit;
-	int byte;
-
-	byte = pos / 8;
-	bit = pos % 8;
-	
-	switch (bit) {
-	case 0:
-		input[byte] |= 128;
-		break;
-	case 1:
-		input[byte] |= 64;
-		break;
-	case 2:
-		input[byte] |= 32;
-		break;
-	case 3:
-		input[byte] |= 16;
-		break;
-	case 4:
-		input[byte] |= 8;
-		break;
-	case 5:
-		input[byte] |= 4;
-		break;
-	case 6:
-		input[byte] |= 2;
-		break;
-	case 7:
-		input[byte] |= 1;
-		break;
+	base32 = base32hex_encode(md, sizeof(md));
+	if (base32 == NULL) {
+		return NULL;
 	}
-
-	return;
-}
-
-int
-base32hex_decode(u_char *input, u_char *output)
-{
-	uint8_t tmp;
-	char *character = "0123456789abcdefghijklmnopqrstuv=";
-	char *start = character, *p = character;
-	int i, j;
-	int len;
-	int bit = 0;
-
-	len = (strlen((const char *)input) * 5) / 8;
-
-	memset(output, 0, len);
-
-	for (i = 0; i < strlen((const char*)input); i++) {
-		if (input[i] == '=')
-			continue;
-
-		input[i] = tolower(input[i]);
-		for (p = character; *p && *p != input[i]; p++);
-		if (*p == '\0')
-			return 0;
-		
-		tmp = (plength(p, start));
-		tmp <<= 3;
-
-		for (j = 0; j < 5; j++) {
-			if (tmp & 128)
-				mysetbit(output, bit);
-			
-			bit++;
-			tmp <<= 1;
-		}
-	}
-		
-	return (len);
-}
-
-
-
-char *
-base32hex_encode(u_char *input, int len)
-{
-	u_char *ui;
-	uint64_t tb = 0;
-	int i;
-	u_char *p;
-	static char ret[64];
 	
-	char *character = "0123456789abcdefghijklmnopqrstuv=";
+	if ((tmp = strchr(base32, '=')) != NULL)
+		*tmp = '\0';
 
-	memset(&ret, 0, sizeof(ret));
-	p = (u_char *)&ret[0];
-	ui = input;
-
-	for (i = 0; i < len; i += 5) {
-		tb = (*ui & 0xff);	
-		tb <<= 8;
-
-		if (i < len) 
-			ui++;
-		else 
-			*ui = 0;
 	
-		tb |= (*ui & 0xff);
-		tb <<= 8;
-
-		if (i < len) 
-			ui++;
-		else 
-			*ui = 0;
-
-		tb |= (*ui & 0xff);
-
-		tb <<= 8;
-
-		if (i < len) 
-			ui++;
-		else 
-			*ui = 0;
-
-		tb |= (*ui & 0xff);
-
-		tb <<= 8;
-
-		if (i < len) 
-			ui++;
-		else 
-			*ui = 0;
-
-		tb |= (*ui & 0xff);
-
-		if (i < len) 
-			ui++;
-		else 
-			*ui = 0;
-
-		*(p + 7) = character[(tb & 0x1f)];
-		tb >>= 5;
-		*(p + 6) = character[(tb & 0x1f)];
-		tb >>= 5;
-		*(p + 5) = character[(tb & 0x1f)];
-		tb >>= 5;
-		*(p + 4) = character[(tb & 0x1f)];
-		tb >>= 5;
-		*(p + 3) = character[(tb & 0x1f)];
-		tb >>= 5;
-		*(p + 2) = character[(tb & 0x1f)];
-		tb >>= 5;
-		*(p + 1) = character[(tb & 0x1f)];
-		tb >>= 5;
-		*(p + 0) = character[(tb & 0x1f)];
-
-		p += 8;
-	}
-
-	return (ret);
+	return (base32);
 }
 
+
 /*
  * NSEC3_MATCH_CLOSEST - find the closest matching encloser 
  *
@@ -886,9 +738,12 @@ nsec3_cover_next_closer(char *name, int namelen, struc
 
 	dname = nsec3_next_closer(rbt->zone, rbt->zonelen, hashname);
 	if (dname == NULL) {
+		free(hashname);
 		return NULL;
 	}
 
+	free(hashname);
+
 #ifdef DEBUG
 	dolog(LOG_INFO, "converting %s\n", dname);
 #endif
blob - 49197dd247d792e5f5dad95ec7c0bcf529950507
file + parse.y
--- parse.y
+++ parse.y
@@ -85,7 +85,7 @@ extern void 	unpack(char *, char *, int);
 
 extern int	memcasecmp(u_char *, u_char *, int);
 extern struct rrtab 	*rrlookup(char *);
-extern int	base32hex_decode(u_char *, u_char *);
+extern int	base32hex_decode(u_char *, u_char *, int);
 extern void 	dolog(int, char *, ...);
 extern char 	*dns_label(char *, int *);
 extern uint8_t find_region(struct sockaddr_storage *, int);
@@ -3121,7 +3121,7 @@ fill_nsec3(ddDB *db, char *name, char *type, uint32_t 
 {
 	struct nsec3 *nsec3;
 	struct rbtree *rbt;
-	int i;
+	int i, t;
 	int tmpbitmap;
 
 	for (i = 0; i < strlen(name); i++) {
@@ -3160,12 +3160,15 @@ fill_nsec3(ddDB *db, char *name, char *type, uint32_t 
 		hex2bin(salt, strlen(salt), nsec3->salt);
 	}
 
-	nsec3->nextlen = base32hex_decode((u_char *)nextname, (u_char*)&nsec3->next);
-	if (nsec3->nextlen == 0) {
-		dolog(LOG_INFO, "base32_decode faulty");
+	t = base32hex_decode((u_char *)nextname, (u_char*)&nsec3->next, sizeof(nsec3->next));
+	if (t == -1) {
+		dolog(LOG_INFO, "%s \n", nextname);
+		dolog(LOG_INFO, "base32hex_decode failed %d %d", sizeof(nsec3->next), t);
 		return -1;
 	}
+	nsec3->nextlen = t;
 
+
 	/* XXX create/manage bitmap */
 	create_nsec_bitmap(bitmap, nsec3->bitmap, &tmpbitmap);
 		
blob - 3028204636dda12c4afa33bf81cfc8c72a23db22
file + query.c
--- query.c
+++ query.c
@@ -119,7 +119,6 @@ extern char * dns_label(char *, int *);
 extern int label_count(char *);
 extern char *get_dns_type(int, int);
 extern char * hash_name(char *, int, struct nsec3param *);
-extern char * base32hex_encode(u_char *input, int len);
 extern int  	init_entlist(ddDB *);
 extern int	check_ent(char *, int);
 extern struct question          *build_question(char *, int, uint16_t, char *);
blob - 62709d434af5cde77df57086e6e854ff83ace68c
file + raxfr.c
--- raxfr.c
+++ raxfr.c
@@ -148,24 +148,27 @@ extern int		fill_nsec3param(ddDB *, char *, char *, ui
 extern int		fill_nsec3(ddDB *, char *, char *, uint32_t, uint8_t, uint8_t, uint16_t, char *, char *, char *);
 extern int		fill_ds(ddDB *, char *, char *, uint32_t, uint16_t, uint8_t, uint8_t, char *);
 
-extern int                     memcasecmp(u_char *, u_char *, int);
-extern char * dns_label(char *, int *);
-extern char                    *get_dns_type(int, int);
-extern int mybase64_encode(u_char const *, size_t, char *, size_t);
-extern char *bin2hex(char *, int);
-extern char *bitmap2human(char *, int);
-extern char *convert_name(char *, int);
-extern char *base32hex_encode(u_char *, int);
-extern uint64_t timethuman(time_t);
-extern char * expand_compression(u_char *, u_char *, u_char *, u_char *, int *, int);
-extern void	dolog(int, char *, ...);
-extern struct rbtree * find_rrset(ddDB *db, char *name, int namelen);               
-extern struct rrset * find_rr(struct rbtree *rbt, uint16_t rrtype);    
-extern struct question         *build_question(char *, int, uint16_t, char *);
-extern int                      lookup_axfr(FILE *, int, char *, struct soa *, uint32_t, char *, char *, int *, int *, int *, struct soa_constraints *, uint32_t, int);
-extern int     find_tsig_key(char *, int, char *, int);
-extern int tsig_pseudoheader(char *, uint16_t, time_t, DDD_HMAC_CTX *);
+extern int		memcasecmp(u_char *, u_char *, int);
+extern char * 		dns_label(char *, int *);
+extern char		*get_dns_type(int, int);
+extern int 		mybase64_encode(u_char const *, size_t, char *, size_t);
+extern char *		bin2hex(char *, int);
+extern char *		bitmap2human(char *, int);
+extern char *		convert_name(char *, int);
+extern char *		base32hex_encode(u_char *, int);
+extern uint64_t 	timethuman(time_t);
+extern char * 		expand_compression(u_char *, u_char *, u_char *, u_char *, int *, int);
+extern void		dolog(int, char *, ...);
+extern struct rbtree *	find_rrset(ddDB *db, char *name, int namelen);               
+extern struct rrset *	find_rr(struct rbtree *rbt, uint16_t rrtype);    
+extern struct question *build_question(char *, int, uint16_t, char *);
 
+extern int		lookup_axfr(FILE *, int, char *, struct soa *, uint32_t, char *, char *, int *, int *, int *, struct soa_constraints *, uint32_t, int);
+
+extern int		find_tsig_key(char *, int, char *, int);
+extern int		tsig_pseudoheader(char *, uint16_t, time_t, DDD_HMAC_CTX *);
+
+
 extern void 	pack(char *, char *, int);
 extern void 	pack32(char *, uint32_t);
 extern void 	pack16(char *, uint16_t);
@@ -1211,6 +1214,7 @@ raxfr_nsec3(FILE *f, u_char *p, u_char *estart, u_char
 	struct nsec3 n;
 	uint16_t iter;
 	u_char *brr = p;	/* begin of rd record :-) */
+	char *base32 = NULL, *tmp = NULL;
 
 	BOUNDS_CHECK((p + 1), brr, rdlen, end);
 	n.algorithm = *p++;
@@ -1250,12 +1254,20 @@ raxfr_nsec3(FILE *f, u_char *p, u_char *estart, u_char
 #endif
 
 	if (f != NULL) {
+		base32 = base32hex_encode((u_char *)n.next, n.nextlen);
+		if (base32 == NULL)
+			return -1;
+		
+		if ((tmp = strchr(base32, '=')) != NULL)
+			*tmp = '\0';
+
 		safe_fprintf(f, "%u,%u,%u,\"%s\",\"%s\",\"%s\"\n", n.algorithm, 
 			n.flags, n.iterations, 
 			(n.saltlen == 0 ? "-" : 
-				bin2hex(n.salt, n.saltlen)), 
-			base32hex_encode((u_char *)n.next, n.nextlen), 
+				bin2hex(n.salt, n.saltlen)), base32,
 			bitmap2human(n.bitmap, n.bitmap_len));
+
+		free(base32);
 	}
 
 	if (ctx != NULL)
blob - b94f18f8b7190b6c42d4014996298db67561b535
file + reply.c
--- reply.c
+++ reply.c
@@ -158,7 +158,6 @@ int		reply_notify(struct sreply *, int *, ddDB *);
 struct rbtree * find_nsec(char *name, int namelen, struct rbtree *, ddDB *db);
 int 		nsec_comp(const void *a, const void *b);
 int 		count_dots(char *name);
-char * 		base32hex_encode(u_char *input, int len);
 void 		set_reply_flags(struct rbtree *, struct dns_header *, struct question *);
 int		reply_sendpacket(char *, uint16_t, struct sreply *, int *);
 int		reply_generic_dnskey(struct sreply *, int *, ddDB *, uint16_t);
blob - f522c6f5fbe5c41b5c43664381bde30319c2cd84
file + sign.c
--- sign.c
+++ sign.c
@@ -354,8 +354,8 @@ extern void			zonemd_hash_txt(SHA512_CTX *, struct rrs
 #define DDD_RSA_F5			0x100000001
 
 #define PROVIDED_SIGNTIME			0
-#define	SIGNEDON				20161230073133
-#define EXPIREDON 				20170228073133
+#define	SIGNEDON				20241223104231
+#define EXPIREDON				20250307104231
 
 #define SIGNEDON_DRIFT				(14 * 86400)
 #define DEFAULT_EXPIRYTIME			(60 * 86400)
@@ -10872,6 +10872,7 @@ print_rbt(FILE *of, struct rbtree *rbt)
 	struct rr *rrp2 = NULL;
 
 	char buf[4096];
+	char *base32 = NULL, *tmp = NULL;
 
 	if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
 		if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
@@ -11383,6 +11384,17 @@ print_rbt(FILE *of, struct rbtree *rbt)
 			dolog(LOG_INFO, "no nsec3 in zone!\n");
 			return -1;
 		}
+
+		base32 = base32hex_encode((u_char *)((struct nsec3 *)rrp->rdata)->next, 
+				((struct nsec3 *)rrp->rdata)->nextlen);
+
+		if (base32 == NULL) {
+			dolog(LOG_INFO, "base32hex_encode: %s\n", strerror(errno));
+			return -1;
+		}
+
+		if ((tmp = strchr(base32, '=')) != NULL)
+			*tmp = '\0';
 		
 		fprintf(of, "  ; H(%.*s) = %s\n  %s,nsec3,%d,%d,%d,%d,\"%s\",\"%s\",\"%s\"\n",
 			(strlen(rbt->unhashed_name) <= 40) ? (int)strlen(rbt->unhashed_name) : 40,
@@ -11393,10 +11405,13 @@ print_rbt(FILE *of, struct rbtree *rbt)
 			((struct nsec3 *)rrp->rdata)->algorithm, 
 			((struct nsec3 *)rrp->rdata)->flags,
 			((struct nsec3 *)rrp->rdata)->iterations,
-			(((struct nsec3 *)rrp->rdata)->saltlen == 0) ? "-" : bin2hex(((struct nsec3 *)rrp->rdata)->salt, ((struct nsec3 *)rrp->rdata)->saltlen),
-			base32hex_encode((u_char *)((struct nsec3 *)rrp->rdata)->next, ((struct nsec3 *)rrp->rdata)->nextlen),
+			(((struct nsec3 *)rrp->rdata)->saltlen == 0) ? "-" : \
+			bin2hex(((struct nsec3 *)rrp->rdata)->salt, ((struct nsec3 *)rrp->rdata)->saltlen),
+			base32,
 			bitmap2human(((struct nsec3 *)rrp->rdata)->bitmap, ((struct nsec3 *)rrp->rdata)->bitmap_len));
 
+		free(base32);
+
 	}
 	if ((rrset = find_rr(rbt, DNS_TYPE_NSEC)) != NULL) {
 		if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
