0

When I try to compile this project I receive an error like this:

dereferencing pointer to incomplete type ‘const struct uECC_Curve_t’ uECC_generate_random_int(r, curves[0]->n, BITS_TO_WORDS(curves[0]->num_n_bits));

I searched several times on Stackoverflow a method to solve this error without success. May I ask you what is wrong in this operation? Why cannot I recover the EC curve parameter n in this manner curves[0]->n?


#include "uECC.h"

#include <stdio.h>
#include <string.h>

void vli_print(char *str, uint8_t *vli, unsigned int size)
{
    printf("%s ", str);
    for (unsigned i = 0; i < size; ++i)
    {
        printf("%02X ", (unsigned)vli[i]);
    }
    printf("\n");
}

int main()
{
    uint8_t private[32]  = {0};
    uint8_t public[64]  = {0};
    unsigned int r[21];

    const struct uECC_Curve_t *curves[1];

    int num_curves = 0;
#if uECC_SUPPORTS_secp160r1
    curves[num_curves++] = uECC_secp160r1();
#endif

    uECC_generate_random_int(r, curves[0]->n, BITS_TO_WORDS(curves[0]->num_n_bits));

    memset(public, 0, sizeof(public));

    if (!uECC_make_key(public, private, curves[0]))
    {
        printf("uECC_make_key() failed\n");
    }

    vli_print("Provided public key = ", public, sizeof(public));
    vli_print("Private key = ", private, sizeof(private));

    return 0;
}

uECC.h

struct uECC_Curve_t;
typedef const struct uECC_Curve_t * uECC_Curve;

uECC.c (I call it during the compilation with gcc, e.g. gcc -o test test.c uECC.c)

struct uECC_Curve_t {
    wordcount_t num_words;
    wordcount_t num_bytes;
    bitcount_t num_n_bits;
    uECC_word_t p[uECC_MAX_WORDS];
    uECC_word_t n[uECC_MAX_WORDS];
    uECC_word_t G[uECC_MAX_WORDS * 2];
    uECC_word_t b[uECC_MAX_WORDS];
    void (*double_jacobian)(uECC_word_t * X1,
                            uECC_word_t * Y1,
                            uECC_word_t * Z1,
                            uECC_Curve curve);
#if uECC_SUPPORT_COMPRESSED_POINT
    void (*mod_sqrt)(uECC_word_t *a, uECC_Curve curve);
#endif
    void (*x_side)(uECC_word_t *result, const uECC_word_t *x, uECC_Curve curve);
#if (uECC_OPTIMIZATION_LEVEL > 0)
    void (*mmod_fast)(uECC_word_t *result, uECC_word_t *product);
#endif
};
CipherX
  • 371
  • 5
  • 18
  • Please show the part of "uECC.h" that defines the `struct uECC_Curve_t`. If it's not in that file, your should locate the header file with the definition of that struct and add a `#include`. – harper May 19 '20 at 11:29
  • The type `uECC_curve_t` is declared as an *opaque structure*, which generally means that the implementers of the library don't want you to know about its details. You can use a pointer to the type, but can never dereference such pointers (and you should never need to). See here: [What is an opaque pointer in C?](https://stackoverflow.com/q/7553750/10871073) – Adrian Mole May 19 '20 at 13:09
  • @AdrianMole so, what is in practice your suggestion? – CipherX May 19 '20 at 13:12
  • 1
    It depends on how willing (or able) you are to modify the `uECC.h` and `uECC.c` files. If you are free to do so, then you would need to move the *full definition* of the structure from the `.c` file into the `.h` file. If you're not willing/able to do that, then your code shouldn't be trying to access the 'innards' of the structure. – Adrian Mole May 19 '20 at 13:15
  • @AdrianMole do you think that could be suitable include the ```uECC.c``` in my script? – CipherX May 19 '20 at 14:04

0 Answers0