~mcf/dnssec-rr

3a48e9231ff5db50243580fd0b9e6c5694c20171 — Michael Forney 3 years ago 818df37
Add BE16/BE32 macros instead of htons/htonl
5 files changed, 24 insertions(+), 24 deletions(-)

M dnssec.c
M dnssec.h
M ds.c
M rrsig.c
M zone.c
M dnssec.c => dnssec.c +1 -2
@@ 1,4 1,3 @@
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <err.h>


@@ 276,7 275,7 @@ dnskey_new(unsigned flags, const struct key *sk)
		for (k->data[0] = 4; !(e & 0xff000000); --k->data[0])
			e <<= 8;
		k->data_len = 1 + k->data[0] + nlen;
		memcpy(k->data + 1, &(uint32_t){htonl(e)}, k->data[0]);
		memcpy(k->data + 1, BE32(e), k->data[0]);
		br_rsa_compute_modulus_get_default()(k->data + 1 + k->data[0], &sk->rsa);
		break;
	}

M dnssec.h => dnssec.h +3 -0
@@ 1,5 1,8 @@
#include <bearssl.h>

#define BE32(x) (unsigned char[]){x >> 24, x >> 16, x >> 8, x}
#define BE16(x) (unsigned char[]){x >> 8, x}

enum {
	TYPE_A      = 1,
	TYPE_NS     = 2,

M ds.c => ds.c +1 -2
@@ 1,6 1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <err.h>
#include "dnssec.h"
#include "arg.h"


@@ 59,7 58,7 @@ main(int argc, char *argv[])

	hc.vtable->init(&hc.vtable);
	hc.vtable->update(&hc.vtable, dname, dname_len);
	hc.vtable->update(&hc.vtable, &(uint16_t){htons(pk->flags)}, 2);
	hc.vtable->update(&hc.vtable, BE16(pk->flags), 2);
	hc.vtable->update(&hc.vtable, &(uint8_t){pk->protocol}, 1);
	hc.vtable->update(&hc.vtable, &(uint8_t){pk->algorithm}, 1);
	hc.vtable->update(&hc.vtable, pk->data, pk->data_len);

M rrsig.c => rrsig.c +9 -10
@@ 2,7 2,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <arpa/inet.h>
#include <err.h>
#include "dnssec.h"
#include "arg.h"


@@ 119,20 118,20 @@ main(int argc, char *argv[])
		dname_print(z.rr[0]->name);
		putchar(' ');
		hc.vtable->init(&hc.vtable);
		hc.vtable->update(&hc.vtable, &(uint16_t){htons(rr->type)}, 2);
		hc.vtable->update(&hc.vtable, BE16(rr->type), 2);
		hc.vtable->update(&hc.vtable, &(uint8_t){sk->algorithm}, 1);
		hc.vtable->update(&hc.vtable, &(uint8_t){labels}, 1);
		hc.vtable->update(&hc.vtable, &(uint32_t){htonl(rr->ttl)}, 4);
		hc.vtable->update(&hc.vtable, &(uint32_t){htonl(end_time)}, 4);
		hc.vtable->update(&hc.vtable, &(uint32_t){htonl(start_time)}, 4);
		hc.vtable->update(&hc.vtable, &(uint16_t){htons(tag)}, 2);
		hc.vtable->update(&hc.vtable, BE32(rr->ttl), 4);
		hc.vtable->update(&hc.vtable, BE32(end_time), 4);
		hc.vtable->update(&hc.vtable, BE32(start_time), 4);
		hc.vtable->update(&hc.vtable, BE16(tag), 2);
		hc.vtable->update(&hc.vtable, z.rr[0]->name, z.rr[0]->name_len);
		do {
			hc.vtable->update(&hc.vtable, z.rr[j]->name, z.rr[j]->name_len);
			hc.vtable->update(&hc.vtable, &(uint16_t){htons(z.rr[j]->type)}, 2);
			hc.vtable->update(&hc.vtable, &(uint16_t){htons(z.rr[j]->class)}, 2);
			hc.vtable->update(&hc.vtable, &(uint32_t){htonl(z.rr[j]->ttl)}, 4);
			hc.vtable->update(&hc.vtable, &(uint16_t){htons(z.rr[j]->rdata_len)}, 2);
			hc.vtable->update(&hc.vtable, BE16(z.rr[j]->type), 2);
			hc.vtable->update(&hc.vtable, BE16(z.rr[j]->class), 2);
			hc.vtable->update(&hc.vtable, BE32(z.rr[j]->ttl), 4);
			hc.vtable->update(&hc.vtable, BE16(z.rr[j]->rdata_len), 2);
			hc.vtable->update(&hc.vtable, z.rr[j]->rdata, z.rr[j]->rdata_len);
		} while (++j < z.rr_len && dname_compare(rr->name, z.rr[j]->name) == 0 && rr->type == z.rr[j]->type);


M zone.c => zone.c +10 -10
@@ 432,7 432,7 @@ again:
			parse_error(p, p->pos, "invalid SOA: serial: %s", err);
			goto err;
		}
		memcpy(rdata, &(uint32_t){htonl(val)}, 4);
		memcpy(rdata, BE32(val), 4);
		rdata += 4;

		/* refresh */


@@ 441,7 441,7 @@ again:
			parse_error(p, p->pos, "invalid SOA: refresh interval: %s", err);
			goto err;
		}
		memcpy(rdata, &(uint32_t){htonl(val)}, 4);
		memcpy(rdata, BE32(val), 4);
		rdata += 4;

		/* retry */


@@ 450,7 450,7 @@ again:
			parse_error(p, p->pos, "invalid SOA: retry interval: %s", err);
			goto err;
		}
		memcpy(rdata, &(uint32_t){htonl(val)}, 4);
		memcpy(rdata, BE32(val), 4);
		rdata += 4;

		/* expire */


@@ 459,7 459,7 @@ again:
			parse_error(p, p->pos, "invalid SOA: expire interval: %s", err);
			goto err;
		}
		memcpy(rdata, &(uint32_t){htonl(val)}, 4);
		memcpy(rdata, BE32(val), 4);
		rdata += 4;

		/* minimum TTL */


@@ 468,7 468,7 @@ again:
			parse_error(p, p->pos, "invalid SOA: minimum TTL: %s", err);
			goto err;
		}
		memcpy(rdata, &(uint32_t){htonl(val)}, 4);
		memcpy(rdata, BE32(val), 4);
		rdata += 4;
		break;
	}


@@ 486,7 486,7 @@ again:
			parse_error(p, NULL, "%s", strerror(errno));
			goto err;
		}
		memcpy(rr->rdata, &(uint16_t){htons(preference)}, 2);
		memcpy(rr->rdata, BE16(preference), 2);
		memcpy(rr->rdata + 2, dname, dname_len);
		break;
	}


@@ 529,9 529,9 @@ again:
			parse_error(p, NULL, "%s", strerror(errno));
			return NULL;
		}
		memcpy(rr->rdata, &(uint16_t){htons(priority)}, 2);
		memcpy(rr->rdata + 2, &(uint16_t){htons(weight)}, 2);
		memcpy(rr->rdata + 4, &(uint16_t){htons(port)}, 2);
		memcpy(rr->rdata, BE16(priority), 2);
		memcpy(rr->rdata + 2, BE16(weight), 2);
		memcpy(rr->rdata + 4, BE16(port), 2);
		memcpy(rr->rdata + 6, dname, dname_len);
		break;
	}


@@ 602,7 602,7 @@ again:
		if (p->err)
			goto err;
		rr = rr_new(4 + len * 3 / 4);
		memcpy(rr->rdata, &(uint16_t){htons(flags)}, 2);
		memcpy(rr->rdata, BE16(flags), 2);
		rr->rdata[2] = protocol;
		rr->rdata[3] = algorithm;
		len = base64_decode(rr->rdata + 4, p->tmp);