Skip to content

Enabling ECC smaller curves - SECP160R1 #25

@fusetim

Description

@fusetim

I'm new to this project and wolfssl in general, and I would like to use the curve known as SECP160R1.
According to the documentation, it should be quite straightforward:

ECC_USER_CURVES

Allow user to choose ECC curve sizes that are enabled. Only the 256-bit curve is enabled by default. To enable others use HAVE_ECC192, HAVE_ECC224, etc...
~ https://www.wolfssl.com/documentation/manuals/wolfssl/chapter02.html#ecc_user_curves

Unfortunately, I am probably missing something, as the following additional flags does not seem to enable it.
So now, I am wondering if anyone could kindly point me in the correct direction.

How to reproduce

#define HAVE_ECC
#define ECC_USER_CURVES
#define HAVE_ECC160

Those lines are added to the default user_settings.h file, and it seems to be correctly applied, as switching between Math library works perfectly.

#include "Arduino.h"
#include "user_settings.h"
#include <wolfssl.h>
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/ecc.h>
#include <wolfssl/wolfcrypt/integer.h> 

int8_t computeECC() {
    ecc_key key;
    if (wc_ecc_init(&key) != 0) {
        return -1; // wc_ecc_init failed
    }
    if (int err = wc_ecc_set_curve(&key, 20, ECC_SECP160R1); err != 0) {
        Serial.println("Failed to set ECC curve, error code: " + String(err));
        return -2; // wc_ecc_set_curve failed
    }
    wc_ecc_free(&key);
    return 0;
}

void setup() {
  Serial.begin(115200);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB
    }
    Serial.println("Hello, Arduino!");

    //Setup a LED blink
    pinMode(LED_BUILTIN, OUTPUT);

    //Setup WOLFSSL
    Serial.print(F("wolfSSL library version: "));
    Serial.println(LIBWOLFSSL_VERSION_STRING);
    Serial.print(F("wolfSSL user settings version: "));
    Serial.println(WOLFSSL_USER_SETTINGS_ID);

    // Test ECC
    computeECC();
}

void loop() {
  // put your main code here, to run repeatedly:
}

The error code is the following:

Hello, Arduino!
wolfSSL library version: 5.8.2
wolfSSL user settings version: Arduino user_settings.h v5.7.6
Failed to set ECC curve, error code: -172

And ERROR Code -172 stands for ECC_CURVE_OID_E : -172 : Unsupported ECC OID curve type
When I try using SECP256R1 it works perfectly (since it is bundled by default).

Additional infos

arduino-cli  Version: 1.3.1 Commit: 08ff7e2b76b7cd6394c4d09420b10cf0592b4405 Date: 
wolfssl version: 5.8.2
FQBN target: esp32:esp32:esp32c6 (platform: esp32:esp32 (3.3.3))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions