From 7191cda6d330ceb474769edbf56c80c598018082 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Tue, 11 Mar 2025 18:43:08 +0100 Subject: [PATCH] Add PHY option to enable specific curves. It's in the app side the management. Signed-off-by: Pol Henarejos --- src/fs/phy.c | 9 +++++++++ src/fs/phy.h | 28 ++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/fs/phy.c b/src/fs/phy.c index 21302c7..414a714 100644 --- a/src/fs/phy.c +++ b/src/fs/phy.c @@ -54,6 +54,10 @@ int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len) { p += strlen(phy->usb_product); *p++ = '\0'; } + if (phy->enabled_curves_present) { + *p++ = PHY_ENABLED_CURVES; + p += put_uint32_t_be(phy->enabled_curves, p); + } *len = p - data; return PICOKEY_OK; @@ -96,6 +100,11 @@ int phy_unserialize_data(const uint8_t *data, uint16_t len, phy_data_t *phy) { phy->usb_product_present = true; p += strlen(phy->usb_product) + 1; break; + case PHY_ENABLED_CURVES: + phy->enabled_curves = get_uint32_t_be(p); + p += sizeof(uint32_t); + phy->enabled_curves_present = true; + break; } } return PICOKEY_OK; diff --git a/src/fs/phy.h b/src/fs/phy.h index 8dac2db..bd85dc3 100644 --- a/src/fs/phy.h +++ b/src/fs/phy.h @@ -26,13 +26,25 @@ #define PHY_OPTS 0x6 #define PHY_UP_BTN 0x8 #define PHY_USB_PRODUCT 0x9 - +#define PHY_ENABLED_CURVES 0xA #define PHY_OPT_WCID 0x1 #define PHY_OPT_DIMM 0x2 #define PHY_OPT_DISABLE_POWER_RESET 0x4 #define PHY_OPT_LED_STEADY 0x8 +#define PHY_CURVE_SECP256R1 0x1 +#define PHY_CURVE_SECP384R1 0x2 +#define PHY_CURVE_SECP521R1 0x4 +#define PHY_CURVE_SECP256K1 0x8 +#define PHY_CURVE_BP256R1 0x10 +#define PHY_CURVE_BP384R1 0x20 +#define PHY_CURVE_BP512R1 0x40 +#define PHY_CURVE_ED25519 0x80 +#define PHY_CURVE_ED448 0x100 +#define PHY_CURVE_CURVE25519 0x200 +#define PHY_CURVE_CURVE448 0x400 + #include #include @@ -44,19 +56,27 @@ typedef struct phy_data { }; uint8_t vidpid[4]; }; + + uint32_t enabled_curves; + + char usb_product[32]; + + uint16_t opts; + uint8_t led_gpio; uint8_t led_brightness; - uint16_t opts; uint8_t up_btn; - char usb_product[32]; + bool vidpid_present; bool led_gpio_present; bool led_brightness_present; bool up_btn_present; bool usb_product_present; + bool enabled_curves_present; + } phy_data_t; -#define PHY_MAX_SIZE 47 +#define PHY_MAX_SIZE sizeof(phy_data_t) #ifndef ENABLE_EMULATION extern int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len);