Commit 549b66a9 authored by Jan Včelák's avatar Jan Včelák 🚀

[dnssec] signature encoding, consistent allocations

parent 3c62f456
......@@ -77,17 +77,7 @@ static int rsa_copy_signature(dnssec_sign_ctx_t *ctx,
assert(from);
assert(to);
uint8_t *data = malloc(from->size);
if (!data) {
return DNSSEC_ENOMEM;
}
memmove(data, from->data, from->size);
to->size = from->size;
to->data = data;
return DNSSEC_EOK;
return dnssec_binary_dup(from, to);
}
static const algorithm_functions_t rsa_functions = {
......@@ -142,20 +132,16 @@ static int dsa_x509_to_dnssec(dnssec_sign_ctx_t *ctx,
uint8_t value_t = dsa_dnskey_get_t_value(ctx->key);
size_t size = 41;
uint8_t *data = malloc(size);
if (!data) {
return DNSSEC_ENOMEM;
result = dnssec_binary_alloc(dnssec, 41);
if (result != DNSSEC_EOK) {
return result;
}
wire_ctx_t wire = wire_init(data, size);
wire_ctx_t wire = wire_init_binary(dnssec);
wire_write_u8(&wire, value_t);
wire_write_ralign_binary(&wire, 20, &value_r);
wire_write_ralign_binary(&wire, 20, &value_s);
assert(wire_tell(&wire) == size);
dnssec->size = size;
dnssec->data = data;
assert(wire_tell(&wire) == dnssec->size);
return DNSSEC_EOK;
}
......@@ -174,16 +160,8 @@ static int dsa_dnssec_to_x509(dnssec_sign_ctx_t *ctx,
const dnssec_binary_t value_r = { .size = 20, .data = dnssec->data + 1 };
const dnssec_binary_t value_s = { .size = 20, .data = dnssec->data + 21 };
dnssec_binary_t der = { 0 };
int result = dss_sig_value_encode(&value_r, &value_s, &der);
if (result != DNSSEC_EOK) {
return result;
}
*x509 = der;
return DNSSEC_EOK;
return dss_sig_value_encode(&value_r, &value_s, x509);
}
static const algorithm_functions_t dsa_functions = {
......@@ -233,19 +211,16 @@ static int ecdsa_x509_to_dnssec(dnssec_sign_ctx_t *ctx,
return DNSSEC_MALFORMED_DATA;
}
size_t size = 2 * int_size;
uint8_t *data = malloc(size);
if (!data) {
return DNSSEC_ENOMEM;
result = dnssec_binary_alloc(dnssec, 2 * int_size);
if (result != DNSSEC_EOK) {
return result;
}
wire_ctx_t wire = wire_init(data, size);
wire_ctx_t wire = wire_init_binary(dnssec);
wire_write_ralign_binary(&wire, int_size, &value_r);
wire_write_ralign_binary(&wire, int_size, &value_s);
assert(wire_tell(&wire) == size);
dnssec->size = size;
dnssec->data = data;
assert(wire_tell(&wire) == dnssec->size);
return DNSSEC_EOK;
}
......@@ -267,16 +242,8 @@ static int ecdsa_dnssec_to_x509(dnssec_sign_ctx_t *ctx,
const dnssec_binary_t value_r = { .size = int_size, .data = dnssec->data };
const dnssec_binary_t value_s = { .size = int_size, .data = dnssec->data + int_size };
dnssec_binary_t der = { 0 };
int result = dss_sig_value_encode(&value_r, &value_s, &der);
if (result != DNSSEC_EOK) {
return result;
}
*x509 = der;
return DNSSEC_EOK;
return dss_sig_value_encode(&value_r, &value_s, x509);
}
static const algorithm_functions_t ecdsa_functions = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment