[RFC 3/5] dpp-util: add dpp_append_point

James Prestwood
2024-03-13T17:13:39Z

Any time DPP needs to append a point it has to use a temporary
buffer to copy into, then copy that into the message buffer.
Instead of this add a special purpose API to add the type/length
then copy the data directly into the message buffer.
---
src/dpp-util.c | 13 +++++++++++++
src/dpp-util.h | 2 ++
2 files changed, 15 insertions(+)

diff --git a/src/dpp-util.c b/src/dpp-util.c
index ada7ed96..81f34047 100644
--- a/src/dpp-util.c
+++ b/src/dpp-util.c
@@ -697,6 +697,19 @@ size_t dpp_append_wrapped_data(const uint8_t *frame, size_t frame_len,
return attrs_len + 4 + 16;
}

+size_t dpp_append_point(uint8_t *to, enum dpp_attribute_type type,
+ struct l_ecc_point *point)
+{
+ const struct l_ecc_curve *c = l_ecc_point_get_curve(point);
+ size_t len = l_ecc_curve_get_scalar_bytes(c) * 2;
+
+ l_put_le16(type, to);
+ l_put_le16(len, to + 2);
+ l_ecc_point_get_data(point, to + 4, len);
+
+ return len + 4;
+}
+
/*
* EasyConnect 2.0 Table 3. Key and Nonce Length Dependency on Prime Length
*/
diff --git a/src/dpp-util.h b/src/dpp-util.h
index 387750aa..1ff9004d 100644
--- a/src/dpp-util.h
+++ b/src/dpp-util.h
@@ -151,6 +151,8 @@ size_t dpp_append_attr(uint8_t *to, enum dpp_attribute_type type,
size_t dpp_append_wrapped_data(const uint8_t *frame, size_t frame_len,
uint8_t *to, const void *key, size_t key_len,
size_t num_attrs, ...);
+size_t dpp_append_point(uint8_t *to, enum dpp_attribute_type type,
+ struct l_ecc_point *point);

char *dpp_generate_uri(const uint8_t *asn1, size_t asn1_len, uint8_t version,
const uint8_t *mac, const uint32_t *freqs,
--
2.34.1