Could you please add the following C function (or a derivative)? I would like to populate an NtruEncParams structure for a given key pair.
void ntru_enc_params_from_kp(NtruEncKeyPair keypair, NtruEncParams parameters)
{
if(!keypair || !parameters)
return;
size_t i = 0;
struct NtruEncParams all[] = ALL_PARAM_SETS;
for(i = 0; i < sizeof(all) / sizeof(struct NtruEncParams); i++)
if(keypair->pub.h.N == all[i].N)
{
parameters->N = all[i].N;
parameters->q = all[i].q;
parameters->prod_flag = all[i].prod_flag;
parameters->df1 = all[i].df1;
parameters->df2 = all[i].df2;
parameters->df3 = all[i].df3;
parameters->dm0 = all[i].dm0;
parameters->maxm1 = all[i].maxm1;
parameters->db = all[i].db;
parameters->c = all[i].c;
parameters->min_calls_r = all[i].min_calls_r;
parameters->min_calls_mask = all[i].min_calls_mask;
parameters->hash_seed = all[i].hash_seed;
memcpy(parameters->oid, all[i].oid, 3 * sizeof(uint8_t));
parameters->sparse = all[i].sparse;
parameters->hash = all[i].hash;
parameters->hlen = all[i].hlen;
parameters->pklen = all[i].pklen;
break;
}
}
The problem with that is that there are parameter sets that have the same N value: EES1087EP1 and EES1087EP2. I don't think there is enough information in a public key to uniquely identify the parameter set.
If you are using libntru in an application, can't you store the name of the parameter set along with the key? You'd also need something like a get_param_set_by_name(char *) function which I wouldn't mind adding to libntru.
Ah, yes. I was hoping that you'd identify a better set of attributes. :) For the keys that I am using, N is unique. Your proposed function would be very helpful. Thanks.
Silly me realized you said key pair, not public key. Yes, this can be done. In fact, a private key is enough.
I added two functions named ntru_params_from_key_pair and ntru_params_from_priv_key. The latest sources are at https://github.com/tbuktu/libntru .
Thanks! If you don't mind, please remove the extra "the" from "for a given the key pair" in the original description.
Diff: