All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] dpp-util: fix dpp_point_to_asn1 compressed type
@ 2022-01-18 19:59 James Prestwood
  0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2022-01-18 19:59 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1636 bytes --]

The point type was being hard coded to 0x3 (BIT1) which may have resulted
in the peer subtracting Y from P when reading in the point (depending on
if Y was odd or not).

Instead set the compressed type to whatever avoids the subtraction which
both saves IWD from needing to do it, as well as the peer.
---
 src/dpp-util.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/dpp-util.c b/src/dpp-util.c
index 8ea3d498..029fbf6f 100644
--- a/src/dpp-util.c
+++ b/src/dpp-util.c
@@ -725,6 +725,7 @@ uint8_t *dpp_point_to_asn1(const struct l_ecc_point *p, size_t *len_out)
 	uint64_t x[L_ECC_MAX_DIGITS];
 	ssize_t ret;
 	size_t len;
+	uint8_t point_type;
 
 	switch (key_size) {
 	case 32:
@@ -745,6 +746,17 @@ uint8_t *dpp_point_to_asn1(const struct l_ecc_point *p, size_t *len_out)
 
 	len = 2 + sizeof(ec_oid) + 2 + type_oid_len + 2 + key_size + 4;
 
+	/*
+	 * Set the type to whatever avoids doing p - y when reading in the
+	 * key. Working backwards from l_ecc_point_from_data if Y is odd and
+	 * the type is BIT0 there is no subtraction. Similarly if Y is even
+	 * and the type is BIT1.
+	 */
+	if (l_ecc_point_y_isodd(p))
+		point_type = L_ECC_POINT_TYPE_COMPRESSED_BIT0;
+	else
+		point_type = L_ECC_POINT_TYPE_COMPRESSED_BIT1;
+
 	if (L_WARN_ON(len > 128))
 		return NULL;
 
@@ -774,7 +786,7 @@ uint8_t *dpp_point_to_asn1(const struct l_ecc_point *p, size_t *len_out)
 	*ptr++ = ASN1_ID_BIT_STRING;
 	*ptr++ = key_size + 2;
 	*ptr++ = 0x00;
-	*ptr++ = 0x03;
+	*ptr++ = point_type;
 	memcpy(ptr, x, key_size);
 	ptr += key_size;
 
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] dpp-util: fix dpp_point_to_asn1 compressed type
@ 2022-01-18 21:02 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2022-01-18 21:02 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

Hi James,

On 1/18/22 13:59, James Prestwood wrote:
> The point type was being hard coded to 0x3 (BIT1) which may have resulted
> in the peer subtracting Y from P when reading in the point (depending on
> if Y was odd or not).
> 
> Instead set the compressed type to whatever avoids the subtraction which
> both saves IWD from needing to do it, as well as the peer.
> ---
>   src/dpp-util.c | 14 +++++++++++++-
>   1 file changed, 13 insertions(+), 1 deletion(-)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-18 21:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 19:59 [PATCH v2] dpp-util: fix dpp_point_to_asn1 compressed type James Prestwood
2022-01-18 21:02 Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.