示例#1
0
    void runTest() {
        SparseVector<Pairing<G1, G1>> A_query;
        SparseVector<Pairing<G2, G1>> B_query;
        SparseVector<Pairing<G1, G1>> C_query;
        std::vector<G1> H_query;
        std::vector<G1> K_query;

        randomSparseVector(A_query, m_numberElems, m_startIndex);
        randomSparseVector(B_query, m_numberElems, m_startIndex);
        randomSparseVector(C_query, m_numberElems, m_startIndex);
        randomVector(H_query, m_numberElems);
        randomVector(K_query, m_numberElems);

        const PPZK_ProvingKey<PAIRING> A(A_query,
                                         B_query,
                                         C_query,
                                         H_query,
                                         K_query);

        std::stringstream oss;
        A.marshal_out_raw(oss);

        PPZK_ProvingKey<PAIRING> B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in_raw(iss));

        checkPass(A == B);
    }
示例#2
0
    void runTest() {
        const auto a = m_lhsA - m_rhsA;
        const auto b = m_lhsB - m_rhsB;
        checkPass(equal_libsnark(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(
            equal_libsnark(
#ifdef USE_OLD_LIBSNARK
                a1.fast_add_special(a2),
#else
                a1.mixed_add(a2),
#endif
                fastAddSpecial(b1, b2)));
    }
示例#3
0
    void runTest() {
        const auto
            a = Fr::random(),
            b = Fr::random();

        checkPass((a + b) * T::one() == a * T::one() + b * T::one());

        const auto
            c = a - Fr::one(),
            d = a + Fr::one();

        checkPass((c + Fr::one()) * T::one() == (d - Fr::one()) * T::one());
        checkPass(c * T::one() == a * T::one() - T::one());
        checkPass(d * T::one() == a * T::one() + T::one());

        auto
            specA = a * T::one(),
            specB = b * T::one(),
            specAB = (a + b) * T::one();

        specA.toSpecial();
        specB.toSpecial();
        specAB.toSpecial();

        checkPass(specAB == fastAddSpecial(specA, specB));
    }
示例#4
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
    }
示例#5
0
    void runTest() {
        std::stringstream oss;
        m_A.marshal_out_rawspecial(oss);

        Pairing<GA, GB> B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in_rawspecial(iss));

        checkPass(m_A == B);
    }
示例#6
0
    void runTest() {
        std::stringstream oss;
        m_A.marshal_out(oss);

        SparseVector<Pairing<GA, GB>> B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in(iss));

        checkPass(m_A == B);
    }
示例#7
0
    void runTest() {
        std::stringstream oss;
        marshal_out_raw(oss, m_A);

        std::vector<T> B;

        std::stringstream iss(oss.str());
        checkPass(marshal_in_raw(iss, B));

        checkPass(m_A == B);
    }
示例#8
0
    void runTest() {
        std::stringstream oss;
        m_A.marshal_out(oss);

        PPZK_Proof<PAIRING> B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in(iss));

        checkPass(m_A == B);
    }
示例#9
0
    void runTest() {
        std::stringstream oss;
        m_A.marshal_out_raw(oss);

        T B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in_raw(iss));

        checkPass(m_A == B);
    }
示例#10
0
    void runTest() {
        std::stringstream oss;
        m_A.marshal_out(oss);

        R1Witness<FIELD> B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in(iss));

        checkPass(m_A == B);
    }
示例#11
0
    void runTest() {
        const auto
            a = m_B + T::zero(),
            b = T::zero() + m_B,
            c = m_B - T::zero();

        const auto
            d = fastAddSpecial(a, T::zero()),
            e = fastAddSpecial(T::zero(), b);

        checkPass(a == b && a == m_B && b == m_B && c == m_B && m_B == c);
        checkPass(d == e && d == a && e == b);
    }
示例#12
0
void process()
{
	if( checkPass() )
		doGreatWork();
	else
		die();
}
示例#13
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));
    }
示例#14
0
    void runTest() {
        const auto keypair
            = libsnark::r1cs_ppzksnark_generator<PPT>(
                m_cs);

        const auto pvk
            = libsnark::r1cs_ppzksnark_verifier_process_vk<PPT>(
                keypair.vk);

#ifdef USE_OLD_LIBSNARK
        const auto proof
            = libsnark::r1cs_ppzksnark_prover<PPT>(
                keypair.pk,
                m_witness);
#else
        const auto proof
            = libsnark::r1cs_ppzksnark_prover<PPT>(
                keypair.pk,
                m_input,
                m_witness);
#endif

        const auto ans_online
            = libsnark::r1cs_ppzksnark_online_verifier_strong_IC<PPT>(
                pvk,
                m_input,
                proof);

        checkPass(ans_online);
    }
示例#15
0
    // check input and input with appended metadata
    void checkMeta (std::string const& input, bool shouldPass)
    {
        checkPass (input, shouldPass);

        checkPass (input + "+a", shouldPass);
        checkPass (input + "+1", shouldPass);
        checkPass (input + "+a.b", shouldPass);
        checkPass (input + "+ab.cd", shouldPass);

        checkFail (input + "!");
        checkFail (input + "+");
        checkFail (input + "++");
        checkFail (input + "+!");
        checkFail (input + "+.");
        checkFail (input + "+a.!");
    }
示例#16
0
    void runTest() {
        std::vector<G1> encoded_terms;
        randomVector(encoded_terms, m_numberElems);

        const PPZK_QueryIC<PAIRING> A(G1::random(),
                                      encoded_terms);

        std::stringstream oss;
        A.marshal_out_raw(oss);

        PPZK_QueryIC<PAIRING> B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in_raw(iss));

        checkPass(A == B);
    }
示例#17
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
    }
示例#18
0
int forceCrack(char* hash, int maxPassLength, int myRank)
{
	char* alphanum;  							// Character set to check passwords of
    sprintf(alphanum, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
	int alphanumLength = strlen(alphanum); 		// 62
	int spot[maxPassLength]; 					// Gives you the index into alphanum you should have for each character place
	char str[maxPassLength];					// Test string
	int i, j, k;
    bool search = true;
	for (i = 0; i < maxPassLength; i++) {		// Set initial values for arrays
		spot[i] = -1;
		str[i] = 0;
	}
	spot[0] = 0;


	if (myRank == 0)  {
		//printf("alphanumLength: %d\n", alphanumLength);
		//printf("maxPassLength: %d\n", maxPassLength);
	}
	while (search) {
		// #pragma omp parallel for private(j)
		#pragma omp parallel for
		for(j = 0; j < maxPassLength; j++) 				// For each character in the string
		{
			if(spot[j] == alphanumLength)				// If we're at the last character
			{
				spot[j] = 0;						// Reset back to the first
				for(k = 1; k < maxPassLength; k++)		// And "carry" to the right (Multiple times if multiple carries)
				{
                    if (j+k == maxPassLength)
                    {
                        search = false;
                        break;
                    }
					if(spot[j+k] < alphanumLength)
					{
						spot[j+k] += 1;
						break;						// Successful carry. Stop.
					}
				}
			}
			if(spot[j] >= 0)
			{ 
				 str[j] = alphanum[spot[j]];
			}
		}
		checkPass(hash, str);				// Checks the string
		spot[0]++; 							// Increment least significant character
	}
    if (myRank == 0)
    {
        printf("Could not find matching hash for words of length %d or less\n", maxPassLength);
    }
	return 0;
}
示例#19
0
    void runTest() {
        SparseVector<Pairing<G1, G1>> A_query;
        SparseVector<Pairing<G2, G1>> B_query;
        SparseVector<Pairing<G1, G1>> C_query;
        std::vector<G1> H_query;
        std::vector<G1> K_query;

        randomSparseVector(A_query, m_numberElems, m_startIndex);
        randomSparseVector(B_query, m_numberElems, m_startIndex);
        randomSparseVector(C_query, m_numberElems, m_startIndex);
        randomVector(H_query, m_numberElems);
        randomVector(K_query, m_numberElems);

        std::vector<G1> encoded_terms;
        randomVector(encoded_terms, m_numberElems);

        const PPZK_Keypair<PAIRING>
            A(PPZK_ProvingKey<PAIRING>(
                  A_query,
                  B_query,
                  C_query,
                  H_query,
                  K_query),
              PPZK_VerificationKey<PAIRING>(
                  G2::random(),
                  G1::random(),
                  G2::random(),
                  G2::random(),
                  G1::random(),
                  G2::random(),
                  G2::random(),
                  PPZK_QueryIC<PAIRING>(G1::random(), encoded_terms)));

        std::stringstream oss;
        A.marshal_out(oss);

        PPZK_Keypair<PAIRING> B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in(iss));

        checkPass(A == B);
    }
示例#20
0
static int sendChallengePacket()
{
	int nameLen = strlen(userName);
	if (startMode%3 == 2)	/* 赛尔 */
	{
		if (sendCount == 0)
		{
			printf(_(">> 发送密码...\n"));
			*(u_int16_t *)(sendPacket+0x0E) = htons(0x0100);
			*(u_int16_t *)(sendPacket+0x10) = *(u_int16_t *)(sendPacket+0x14) = htons(nameLen+22);
			sendPacket[0x12] = 0x02;
			sendPacket[0x13] = capBuf[0x13];
			sendPacket[0x16] = 0x04;
			sendPacket[0x17] = 16;
			memcpy(sendPacket+0x18, checkPass(capBuf[0x13], capBuf+0x18, capBuf[0x17]), 16);
			memcpy(sendPacket+0x28, userName, nameLen);
			setTimer(timeout);
		}
		return pcap_sendpacket(hPcap, sendPacket, nameLen+40);
	}
	if (sendCount == 0)
	{
		printf(_(">> 发送密码...\n"));
		//fillMd5Packet(capBuf+0x18);
		fillEtherAddr(0x888E0100);
		*(u_int16_t *)(sendPacket+0x14) = *(u_int16_t *)(sendPacket+0x10) = htons(nameLen+22);
		sendPacket[0x12] = 0x02;
		sendPacket[0x13] = capBuf[0x13];
		sendPacket[0x16] = 0x04;
		sendPacket[0x17] = 16;
		memcpy(sendPacket+0x18, checkPass(capBuf[0x13], capBuf+0x18, capBuf[0x17]), 16);
		memcpy(sendPacket+0x28, userName, nameLen);

                memcpy(sendPacket+0x28+nameLen, pkt3, sizeof(pkt3));
                memcpy(sendPacket + 0x90 + nameLen, computePwd(capBuf+0x18), 0x10);
                //memcpy(sendPacket + 0xa0 +nameLen, fillBuf + 0x68, fillSize-0x68);
                memcpy(sendPacket + 0x109 + nameLen, computeV4(capBuf+0x18, capBuf[0x17]), 0x80);
                //sendPacket[0x77] = 0xc7;
		setTimer(timeout);
	}
	return pcap_sendpacket(hPcap, sendPacket, 578);
}
示例#21
0
    void runTest() {
        auto a = m_A;
        auto b = m_B;

        for (std::size_t i = 0; i < 1000; ++i) {
            checkPass(a.is_well_formed() == b.wellFormed());
            checkPass(a.is_special() == b.isSpecial());

            auto c = a;
            auto d = b;
            c.to_special();
            d.toSpecial();

            checkPass(c.is_well_formed() == d.wellFormed());
            checkPass(c.is_special() == d.isSpecial());

            a = a + U::one();
            b = b + T::one();
        }
    }
示例#22
0
    void runTest() {
        std::stringstream oss;
        m_A.marshal_out(
            oss,
            [] (std::ostream& o, const Pairing<GA, GB>& a) {
                a.marshal_out_raw(o);
            });

        SparseVector<Pairing<GA, GB>> B;

        std::stringstream iss(oss.str());
        checkPass(
            B.marshal_in(
                iss,
                [] (std::istream& i, Pairing<GA, GB>& a) {
                    return a.marshal_in_raw(i);
                }));

        checkPass(m_A == B);
    }
int main(int argc, char *argv[])
{
	char dummy[1000];
	
	if(checkPass()){
		printf("\n認証成功!\n");
		printf("あなたのクレジットカード番号は、1234-5678-01245-6789 です。\n");
	}else{
		printf("\n認証失敗。パスワードを確認して下さい。\n");
	}
	
    return 0;
}
示例#24
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));
    }
示例#25
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));
    }
示例#26
0
int main(int argc, char *argv[]) {
    char pass[15]; 

    printf("Enter password: "******"%s", pass);
    printf("Got [%s]\n", pass); 

 
    if ((checkPassLength(pass) == 15) && (checkPass(pass) == 0)) {
        puts("Congratz! \n");
    } else {
        puts("You Need to learn more!!\n"); 
    }
    return 0;
}
示例#27
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));
    }
示例#28
0
    void runTest() {
        const PPZK_Keypair<PAIRING> keypair(m_constraintSystem.systemB(),
                                            m_constraintSystem.numCircuitInputs(),
                                            PPZK_LagrangePoint<Fr>(0),
                                            PPZK_BlindGreeks<Fr, Fr>(0));

        const PPZK_Proof<PAIRING> proofB(m_constraintSystem.systemB(),
                                         m_constraintSystem.numCircuitInputs(),
                                         keypair.pk(),
                                         m_constraintSystem.witnessB(),
                                         PPZK_ProofRandomness<typename PAIRING::Fr>(0));

        const auto ans = strongVerify(keypair.vk(),
                                      m_constraintSystem.inputB(),
                                      proofB);

        checkPass(m_failureIsSuccess ? !ans : ans);
    }
示例#29
0
文件: Auth.cpp 项目: luogangyi/Dislab
void Auth::Do()
{
	log.write("begin Auth::Do.", Log::INFO);	
	
	//参数检查
	log.write("begin process parameter.", Log::INFO);
	if( getPara() == false)
	{
		ackCode =  "ACK:LOGIN:RETN=4,DESC=parameter error";
		return;
	}
	log.write("end process parameter.", Log::INFO);
	

	//检查用户名密码是否正确

	log.write("begin check user name and password.", Log::INFO);
	if( checkPass() == false)
	{
		ackCode =  "ACK:LOGIN:RETN=1001,DESC=user name or pass is error";
		return;
	}
	log.write("end check user name and password.", Log::INFO);

	if( userType == 0 )
	{
		ackCode =  "ACK:LOGIN:RETN=0,DESC=success,RESULT=-1|-1";
		return;
	}
	//////////////////////获取权限数据
	log.write("begin get permission data.", Log::INFO);
	if( getPermissionData() == false)
	{
		ackCode =  "ACK:LOGIN:RETN=8,DESC=system internal error,cannot get permissionData from database.";
		return;
	}
	log.write("end get permission data.", Log::INFO);



	ackCode =  "ACK:LOGIN:RETN=0,DESC=success,RESULT=" + permissionData;

	log.write("end Auth::Do.", Log::INFO);	
}
示例#30
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));
    }