Topic: Key generation for curve ECC_SECP521R1


I am trying to test different curves on my IoT devices with RIOT OS. Now I am using wc_ecc_make_key_ex() to generate ECC keys for three different curves: ECC_SECP256R1, ECC_SECP384R1, ECC_SECP521R1.
1. ECC_SECP256R1 works well by default.
2. ECC_SECP384R1. I noticed that I need to define WOLFSSL_SP_384 in user_settings.h to enable key generation for this curve (let me know if I am wrong with this). Now it also works.
3. ECC_SECP521R1. My code always returns -234 to indicate key size error for this curve. So is there any other way to enable key generation for ECC_SECP521R1 or did I miss something here?

Here is my code below (wolfCrypt version 4.5.0):

static int _encrypt_handler_keyGen(int argc, char **argv) {
    if (argc < 2) {
        printf("usage: %s [key_size]\n", argv[0]);
        return 1;

    int ret = 0;
    ecc_key key;
    WC_RNG rng;


    // int curveId = ECC_SECP256R1;
    // int curveId = ECC_SECP384R1;
    int curveId = ECC_SECP521R1;

    int keySize = wc_ecc_get_curve_size_from_id(curveId);
    ret = wc_ecc_make_key_ex(&rng, keySize, &key, curveId);

    if (ret != MP_OKAY) {
        printf("Failed to generate ECC keys. Error code: %d. Key Size: %d.\n", ret, keySize);
        return -1;

    return 0;


Re: Key generation for curve ECC_SECP521R1

Hi Hu,

Please try adding a define for `WOLFSSL_SP_4096` to enable the larger bit sizes.

Eric @ wolfSSL Support