For finite field math I store the corresponding addition and multiplication tables as statically typed integer arrays, e.g., for GF(4/8), I have
static const uint8_t GF4ADD[4][4] = {...};
static const uint8_t GF8ADD[8][8] = {...};
Now, at runtime, the program reads from a config file which field size is desired and should assign to a struct pointer the corresponding table:
struct obj data {
...
uint8_t** table_add;
uint8_t** table_mult;
...
};
switch(order) {
case 4:
data.table_add = GF4ADD;
data.table_mult = GF4MULT;
break;
case 8:
data.table_add = GF8ADD;
data.table_mult = GF8MULT;
break;
}
Of course, the above doesn't work, but it should give you the idea of what I am trying to accomplish. The main problem is that I don't know of which type I should declare the struct members, as the size of the tables is only known at runtime. Besides, I do not want to resort to a one-dimensional indexing of the tables only.
Thanks, Tom.