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
};