Ejemplo n.º 1
0
    void runTest() {
        const auto a = m_lhsA - m_rhsA;
        const auto b = m_lhsB - m_rhsB;
        checkPass(sameData(a, b));

        auto
            a1 = m_lhsA,
            a2 = -m_rhsA;
        a1.to_special();
        a2.to_special();

        auto
            b1 = m_lhsB,
            b2 = -m_rhsB;
        b1.toSpecial();
        b2.toSpecial();

        checkPass(
            sameData(
#ifdef USE_OLD_LIBSNARK
                a1.fast_add_special(a2),
#else
                a1.mixed_add(a2),
#endif
                fastAddSpecial(b1, b2)));
    }
Ejemplo n.º 2
0
    void runTest() {
        const G2_precomp b(m_B);

#ifdef CURVE_EDWARDS
        const auto a = edwards_ate_precompute_G2(m_A);

        if (checkPass(a.size() == b.coeffs.size())) {
            for (std::size_t i = 0; i < a.size(); ++i) {
                checkPass(sameData(a[i].c_ZZ, b.coeffs[i].c_ZZ));
                checkPass(sameData(a[i].c_XY, b.coeffs[i].c_XY));
                checkPass(sameData(a[i].c_XZ, b.coeffs[i].c_XZ));
            }
        }
#endif

#ifdef CURVE_ALT_BN128
        const auto a = alt_bn128_ate_precompute_G2(m_A);

        checkPass(sameData(a.QX, b.QX));
        checkPass(sameData(a.QY, b.QY));

        if (checkPass(a.coeffs.size() == b.coeffs.size())) {
            for (std::size_t i = 0; i < a.coeffs.size(); ++i) {
                checkPass(sameData(a.coeffs[i].ell_0, b.coeffs[i].ell_0));
                checkPass(sameData(a.coeffs[i].ell_VW, b.coeffs[i].ell_VW));
                checkPass(sameData(a.coeffs[i].ell_VV, b.coeffs[i].ell_VV));
            }
        }
#endif
    }
Ejemplo n.º 3
0
    void runTest() {
#ifdef CURVE_EDWARDS
        const auto
            a0 = edwards_ate_precompute_G1(m_g1_0A),
            a2 = edwards_ate_precompute_G1(m_g1_2A);

        const auto
            a1 = edwards_ate_precompute_G2(m_g2_1A),
            a3 = edwards_ate_precompute_G2(m_g2_3A);

        const auto a = edwards_ate_double_miller_loop(a0, a1, a2, a3);
#endif

#ifdef CURVE_ALT_BN128
        const auto
            a0 = alt_bn128_ate_precompute_G1(m_g1_0A),
            a2 = alt_bn128_ate_precompute_G1(m_g1_2A);

        const auto
            a1 = alt_bn128_ate_precompute_G2(m_g2_1A),
            a3 = alt_bn128_ate_precompute_G2(m_g2_3A);

        const auto a = alt_bn128_ate_double_miller_loop(a0, a1, a2, a3);
#endif

        const G1_precomp b0(m_g1_0B), b2(m_g1_2B);
        const G2_precomp b1(m_g2_1B), b3(m_g2_3B);

        const auto b = PAIRING::ate_double_miller_loop(b0, b1, b2, b3);

        checkPass(sameData(a, b));
    }
Ejemplo n.º 4
0
    void runTest() {
        const G1_precomp b(m_B);

#ifdef CURVE_EDWARDS
        const auto a = edwards_ate_precompute_G1(m_A);

        checkPass(sameData(a.P_XY, b.P_XY));
        checkPass(sameData(a.P_XZ, b.P_XZ));
        checkPass(sameData(a.P_ZZplusYZ, b.P_ZZplusYZ));
#endif

#ifdef CURVE_ALT_BN128
        const auto a = alt_bn128_ate_precompute_G1(m_A);

        checkPass(sameData(a.PX, b.PX));
        checkPass(sameData(a.PY, b.PY));
#endif
    }
Ejemplo n.º 5
0
  void doAssertSameData(const char *file, unsigned line, const char *xExpr,
                        const void *x, const char *yExpr, const void *y,
                        const char *sizeExpr, unsigned size, const char *message) {
    if (!sameData(x, y, size)) {
      if (message)
        tracker().failedTest(file, line, message);

      tracker().failedAssertSameData(file, line, xExpr, yExpr, sizeExpr, x, y, size);
      TS_ABORT();
    }
  }
Ejemplo n.º 6
0
    void runTest() {
        const auto a = opt_window_wnaf_exp(
#ifdef USE_OLD_LIBSNARK
                                           U::zero(),
#endif
                                           m_baseA,
                                           m_scalarA,
                                           m_scalarA.num_bits());

        const auto b = wnafExp(m_scalarB, m_baseB);

        checkPass(sameData(a, b));
    }
Ejemplo n.º 7
0
    void runTest() {
#ifdef CURVE_EDWARDS
        const auto a = edwards_final_exponentiation(m_A);
#endif

#ifdef CURVE_ALT_BN128
        const auto a = alt_bn128_final_exponentiation(m_A);
#endif

        const auto b = PAIRING::final_exponentiation(m_B);

        checkPass(sameData(a, b));
    }
Ejemplo n.º 8
0
    void runTest() {
        const auto a = libsnark::multi_exp<U, G>(
#ifdef USE_OLD_LIBSNARK
                                                 U::zero(),
#endif
                                                 m_baseA.begin(),
                                                 m_baseA.end(),
                                                 m_scalarA.begin(),
                                                 m_scalarA.end(),
                                                 1,
                                                 true);

        const auto b = multiExp(m_baseB, m_scalarB);

        checkPass(sameData(a, b));
    }
Ejemplo n.º 9
0
    void runTest() {
#ifdef CURVE_EDWARDS
        const auto a1 = edwards_ate_precompute_G1(m_g1A);
        const auto a2 = edwards_ate_precompute_G2(m_g2A);
        const auto a = edwards_ate_miller_loop(a1, a2);
#endif

#ifdef CURVE_ALT_BN128
        const auto a1 = alt_bn128_ate_precompute_G1(m_g1A);
        const auto a2 = alt_bn128_ate_precompute_G2(m_g2A);
        const auto a = alt_bn128_ate_miller_loop(a1, a2);
#endif

        const G1_precomp b1(m_g1B);
        const G2_precomp b2(m_g2B);
        const auto b = PAIRING::ate_miller_loop(b1, b2);

        checkPass(sameData(a, b));
    }
Ejemplo n.º 10
0
    void runTest() {
        auto a = m_A;
        a.to_affine_coordinates();

        auto b = m_B;
        b.affineCoordinates();

#ifdef CURVE_EDWARDS
        libsnark::edwards_Fq3_conic_coefficients aC;
        libsnark::extended_edwards_G2_projective aR;
        aR.X = a.X;
        aR.Y = a.Y;
        aR.Z = a.Z;
        aR.T = a.X * a.Y;
        libsnark::doubling_step_for_flipped_miller_loop(aR, aC);

        typename PAIRING::G2_projective bR(b.x(), b.y(), b.z(), b.x() * b.y());
        const auto bC = PAIRING::doubling_step_for_flipped_miller_loop(bR);

        checkPass(sameData(aC.c_ZZ, bC.c_ZZ));
        checkPass(sameData(aC.c_XY, bC.c_XY));
        checkPass(sameData(aC.c_XZ, bC.c_XZ));
#endif

#ifdef CURVE_ALT_BN128
        libsnark::alt_bn128_ate_ell_coeffs aC;
        libsnark::alt_bn128_G2 aR;
        aR.X = a.X;
        aR.Y = a.Y;
        aR.Z = libsnark::alt_bn128_Fq2::one();
        const libsnark::alt_bn128_Fq two_inv = libsnark::alt_bn128_Fq("2").inverse();
        libsnark::doubling_step_for_flipped_miller_loop(two_inv, aR, aC);

        typename PAIRING::G2 bR(b.x(), b.y(), PAIRING::Fq2::one());
        const auto bC = PAIRING::doubling_step_for_flipped_miller_loop(bR);

        checkPass(sameData(aC.ell_0, bC.ell_0));
        checkPass(sameData(aC.ell_VW, bC.ell_VW));
        checkPass(sameData(aC.ell_VV, bC.ell_VV));
#endif
    }
Ejemplo n.º 11
0
extern int
main(int argc, const char *argv[]) {
    static char line[2000], firstLine[2000], lastLine[2000];
    char *end;
    long first, last, c;
    int finished;

    first=last=-1;
    finished=0;

    for(;;) {
        if(gets(line)!=NULL) {
            /* parse the initial code point, if any */
            c=strtol(line, &end, 16);
            if(end!=line && *skipWhitespace(end)==';') {
                /* single code point followed by semicolon and data, keep c */
            } else {
                c=-1;
            }
        } else {
            line[0]=0;
            c=-1;
            finished=1;
        }

        if(last>=0 && (c!=(last+1) || !sameData(firstLine, line))) {
            /* output the current range */
            if(first==last) {
                /* there was no range, just output the one line we found */
                puts(firstLine);
            } else {
                /* there was a real range, merge their lines */
                end=strchr(lastLine, '#');
                if(end==NULL) {
                    /* no comment in second line */
                    printf("%04lX..%04lX%s\n",
                            first, last,            /* code point range */
                            strchr(firstLine, ';'));/* first line starting from the first ; */
                } else if(strchr(firstLine, '#')==NULL) {
                    /* no comment in first line */
                    printf("%04lX..%04lX%s%s\n",
                            first, last,            /* code point range */
                            strchr(firstLine, ';'), /* first line starting from the first ; */
                            end);                   /* comment from second line */
                } else {
                    /* merge comments from both lines */
                    printf("%04lX..%04lX%s..%s\n",
                            first, last,            /* code point range */
                            strchr(firstLine, ';'), /* first line starting from the first ; */
                            skipWhitespace(end+1)); /* comment from second line, after # and spaces */
                }
            }
            first=last=-1;
        }

        if(c<0) {
            if(finished) {
                break;
            }

            /* no data on this line, output as is */
            puts(line);
        } else {
            /* data on this line, store for possible range compaction */
            if(last<0) {
                /* set as the first line in a possible range */
                first=last=c;
                strcpy(firstLine, line);
                lastLine[0]=0;
            } else /* must be c==(last+1) && sameData() because of previous conditions */ {
                /* continue with the current range */
                last=c;
                strcpy(lastLine, line);
            }
        }
    }

    return 0;
}
Ejemplo n.º 12
0
    void runTest() {
        const auto a = m_A.dbl();
        const auto b = m_B.dbl();

        checkPass(sameData(a, b));
    }
Ejemplo n.º 13
0
    void runTest() {
        const auto a = m_powerA * m_baseA;
        const auto b = m_powerB * m_baseB;

        checkPass(sameData(a, b));
    }