KeyParams keyParams = KeyParams.getKeyParams(oid);
IGF2 igf = new IGF2(keyParams.N, keyParams.c, prng);
// Generate trinomial g that is invertible
FullPolynomial g = null;
boolean gIsInvertible = false;
while (!gIsInvertible)
{
g = BPGM3.genTrinomial(
keyParams.N, keyParams.dg+1, keyParams.dg, igf);
FullPolynomial gInv = keyParams.polyInverter.invert(g);
gIsInvertible = (gInv != null);
}
// Create F, f=1+p*F, and f^-1 mod q
FullPolynomial F = null, f = null, fInv = null;
boolean fIsInvertible = false;
while (!fIsInvertible)
{
// Generate random F
F = BPGM3.genTrinomial(
keyParams.N, keyParams.df, keyParams.df, igf);
// Calculate f = 1+p*f
f = new FullPolynomial(keyParams.N);
for (int i=0; i<keyParams.N; i++)
f.p[i] = (short) (keyParams.p*F.p[i]);
f.p[0]++;
// Compute f^-1 mod q. Check whether the operation succeeded.
fInv = keyParams.polyInverter.invert(f);
fIsInvertible = (fInv != null);
}
// Calculate h = f^-1 * g * p mod q
FullPolynomial h = FullPolynomial.convolution(fInv, g);
for (int i=0; i<h.p.length; i++)
{
h.p[i] = (short) ((h.p[i] * keyParams.p) % keyParams.q);
if (h.p[i] < 0)
h.p[i] += keyParams.q;