Exemple #1
0
void bn254_fp2_inv(Element z, const Element x)
{
    Element* t = field(z)->base->tmp;

    if (strcmp(x->field->field_name, "bn254_fp2a") == 0)
    {
        bn254_fp_muln(t[1], rep1(x), rep1(x)); // t1 = a1^2
        bn254_fp_addn(t[0], t[1], t[1]);
        bn254_fp_addn(t[0], t[0], t[0]);
        bn254_fp_addn(t[1], t[1], t[0]);      // t1 = 5*a1^2
        bn254_fp_muln(t[0], rep0(x), rep0(x));// t0 = a0^2
        bn254_fp_addn(t[0], t[0], t[1]);      // t0 = t0 - t1
        bn254_fp_inv(t[1], t[0]);             // t1 = t0^-1
        bn254_fp_mul(rep0(z), rep0(x), t[1]); // c0 = a0*t1
        bn254_fp_mul(rep1(z), rep1(x), t[1]); // c1 = a1*t1
        bn254_fp_neg(rep1(z), rep1(z));       // c1 = -1*a1*t1
    }

    if (strcmp(x->field->field_name, "bn254_fp2b") == 0)
    {
        bn254_fp_muln(t[1], rep1(x), rep1(x));// t1 = a1^2
        bn254_fp_muln(t[0], rep0(x), rep0(x));// t0 = a0^2
        bn254_fp_addn(t[0], t[0], t[1]);      // t0 = t0 + t1 ( beta = -1 )
        bn254_fp_inv(t[1], t[0]);             // t1 = t0^-1
        bn254_fp_mul(rep0(z), rep0(x), t[1]); // c0 = a0*t1
        bn254_fp_mul(rep1(z), rep1(x), t[1]); // c1 = a1*t1
        bn254_fp_neg(rep1(z), rep1(z));       // c1 = -1*a1*t1
    }
}
Exemple #2
0
void bn254_fp2_xi_mul(Element z, const Element x)
{
    Element* t = field(z)->base->tmp;

    bn254_fp_add(t[0], rep1(x), rep1(x));
    bn254_fp_add(t[0], t[0], t[0]);
    bn254_fp_add(t[0], t[0], rep1(x));
    bn254_fp_set(rep1(z), rep0(x));
    bn254_fp_neg(rep0(z), t[0]);
}
Exemple #3
0
void bn254_fp2_inv(Element z, const Element x)
{
    Element* t = field(z)->base->tmp;

    bn254_fp_muln(t[1], rep1(x), rep1(x)); // t1 = a1^2
    bn254_fp_addn(t[0], t[1], t[1]);
    bn254_fp_addn(t[0], t[0], t[0]);
    bn254_fp_addn(t[1], t[1], t[0]);      // t1 = 5*a1^2
    bn254_fp_muln(t[0], rep0(x), rep0(x));// t0 = a0^2
    bn254_fp_addn(t[0], t[0], t[1]);      // t0 = t0 - t1
    bn254_fp_inv(t[1], t[0]);             // t1 = t0^-1
    bn254_fp_mul(rep0(z), rep0(x), t[1]); // c0 = a0*t1
    bn254_fp_mul(rep1(z), rep1(x), t[1]); // c1 = a1*t1
    bn254_fp_neg(rep1(z), rep1(z));       // c1 = -1*a1*t1
}
Exemple #4
0
void bn254_fp2_xi_mul(Element z, const Element x)
{
    Element* t = field(z)->base->tmp;

    if (strcmp(x->field->field_name, "bn254_fp2a") == 0)
    {
        bn254_fp_add(t[0], rep1(x), rep1(x));
        bn254_fp_add(t[0], t[0], t[0]);
        bn254_fp_add(t[0], t[0], rep1(x));
        bn254_fp_set(rep1(z), rep0(x));
        bn254_fp_neg(rep0(z), t[0]);
    }

    if (strcmp(x->field->field_name, "bn254_fp2b") == 0)
    {
        bn254_fp_sub(t[0], rep0(x), rep1(x));
        bn254_fp_add(t[1], rep0(x), rep1(x));
        bn254_fp_set(rep0(z), t[0]);
        bn254_fp_set(rep1(z), t[1]);
    }
}
Exemple #5
0
void bn254_fp2_conj(Element z, const Element x)
{
    bn254_fp_set(rep0(z), rep0(x));
    bn254_fp_neg(rep1(z), rep1(x));
}