コード例 #1
0
ファイル: bn254_fp2.c プロジェクト: akirakanaoka/teplatest
void bn254_fp2_sqr(Element z, const Element x)
{
    Element* t = field(z)->base->tmp;

    if (strcmp(x->field->field_name, "bn254_fp2a") == 0)
    {
        bn254_fp_addn(t[0], rep1(x), rep1(x)); //
        bn254_fp_muln(t[0], t[0], rep0(x));    // t0 = 2*x1*x0
        bn254_fp_addp(t[1], rep0(x));
        bn254_fp_subn(t[1], t[1], rep1(x));    // t1 = x0-x1
        bn254_fp_addn(t[2], rep1(x), rep1(x)); //
        bn254_fp_addn(t[2], t[2], t[2]);       //
        bn254_fp_addn(t[2], t[2], rep1(x));    //
        bn254_fp_addn(t[2], t[2], rep0(x));    // t2 = 5*x1 + x0
        bn254_fp_muln(t[1], t[1], t[2]);       // t1 = t1 * t2
        bn254_fp_mod(rep1(z), t[0]);           // c1 = t0
        bn254_fp_addn(t[0], t[0], t[0]);       //
        bn254_fp_subn(t[1], t[1], t[0]);       // t1 = 2*t0*t1
        bn254_fp_mod(rep0(z), t[1]);           // c0 = t1
    }

    if (strcmp(x->field->field_name, "bn254_fp2b") == 0)
    {
        bn254_fp_addn(t[0], rep1(x), rep1(x)); // t0 = 2*x1
        bn254_fp_muln(t[0], t[0], rep0(x));    // t0 = 2*x1*x0
        bn254_fp_addn(t[1], rep0(x), rep1(x)); // t1 = x0+x1
        bn254_fp_subn(t[2], rep0(x), rep1(x)); // t2 = x0-x1
        bn254_fp_muln(t[1], t[1], t[2]);       // t1 = t1*t2
        bn254_fp_mod(rep1(z), t[0]);           // c1 = t0
        bn254_fp_mod(rep0(z), t[1]);		   // c0 = t1
    }
}
コード例 #2
0
ファイル: bn254_fp2.c プロジェクト: ysk-knbr/tepla-1
void bn254_fp2_sqr(Element z, const Element x)
{
    Element* t = field(z)->base->tmp;

    bn254_fp_addn(t[0], rep1(x), rep1(x)); //
    bn254_fp_muln(t[0], t[0], rep0(x));    // t0 = 2*x1*x0
    bn254_fp_addp(t[1], rep0(x));
    bn254_fp_subn(t[1], t[1], rep1(x));    // t1 = x0-x1
    bn254_fp_addn(t[2], rep1(x), rep1(x)); //
    bn254_fp_addn(t[2], t[2], t[2]);       //
    bn254_fp_addn(t[2], t[2], rep1(x));    //
    bn254_fp_addn(t[2], t[2], rep0(x));    // t2 = 5*x1 + x0
    bn254_fp_muln(t[1], t[1], t[2]);       // t1 = t1 * t2
    bn254_fp_mod(rep1(z), t[0]);           // c1 = t0
    bn254_fp_addn(t[0], t[0], t[0]);       //
    bn254_fp_subn(t[1], t[1], t[0]);       // t1 = 2*t0*t1
    bn254_fp_mod(rep0(z), t[1]);           // c0 = t1
}