bool ValidateRW() { cout << "\nRW validation suite running...\n\n"; FileSource f(CRYPTOPP_DATA_DIR "TestData/rw1024.dat", true, new HexDecoder); RWSS<PSSR, SHA>::Signer priv(f); RWSS<PSSR, SHA>::Verifier pub(priv); return SignatureValidate(priv, pub); }
bool RWValidate() { cout << "\nRW validation suite running...\n\n"; FileSource f("rw512.dat", true, new HexDecoder); RWSigner<SHA> priv(f); RWVerifier<SHA> pub(priv); return SignatureValidate(priv, pub); }
bool DSAValidate() { cout << "\nDSA validation suite running...\n\n"; bool pass = true, fail; { FileSource fs("dsa512.dat", true, new HexDecoder()); DSAPrivateKey priv(fs); priv.Precompute(16); DSAPublicKey pub(priv); byte seed[]={0xd5, 0x01, 0x4e, 0x4b, 0x60, 0xef, 0x2b, 0xa8, 0xb6, 0x21, 0x1b, 0x40, 0x62, 0xba, 0x32, 0x24, 0xe0, 0x42, 0x7d, 0xd3}; Integer k("358dad57 1462710f 50e254cf 1a376b2b deaadfbfh"); Integer h("a9993e36 4706816a ba3e2571 7850c26c 9cd0d89dh"); byte sig[]={0x8b, 0xac, 0x1a, 0xb6, 0x64, 0x10, 0x43, 0x5c, 0xb7, 0x18, 0x1f, 0x95, 0xb1, 0x6a, 0xb9, 0x7c, 0x92, 0xb3, 0x41, 0xc0, 0x41, 0xe2, 0x34, 0x5f, 0x1f, 0x56, 0xdf, 0x24, 0x58, 0xf4, 0x26, 0xd1, 0x55, 0xb4, 0xba, 0x2d, 0xb6, 0xdc, 0xd8, 0xc8}; Integer r(sig, 20); Integer s(sig+20, 20); Integer pGen, qGen, rOut, sOut; int c; fail = !GenerateDSAPrimes(seed, 160, c, pGen, 512, qGen); fail = fail || (pGen != pub.GetModulus()) || (qGen != pub.GetSubgroupSize()); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "prime generation test\n"; priv.RawSign(k, h, rOut, sOut); fail = (rOut != r) || (sOut != s); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "signature check against test vector\n"; fail = !pub.VerifyMessage((byte *)"abc", 3, sig); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "verification check against test vector\n"; fail = pub.VerifyMessage((byte *)"xyz", 3, sig); pass = pass && !fail; } FileSource fs1("dsa1024.dat", true, new HexDecoder()); DSAPrivateKey priv(fs1); FileSource fs2("dsa1024b.dat", true, new HexDecoder()); DSAPublicKey pub(fs2); pass = SignatureValidate(priv, pub) && pass; return pass; }
bool ValidateRW() { cout << "\nRW validation suite running...\n\n"; bool pass=true; FileSource f("TestData/rw1024.dat", true, new HexDecoder); RWSS<PSSR, SHA>::Signer priv(f); RWSS<PSSR, SHA>::Verifier pub(priv); pass = pass && SignatureValidate(priv, pub); return pass; }
bool ValidateNR() { cout << "\nNR validation suite running...\n\n"; bool pass = true; { FileSource f("TestData/nr2048.dat", true, new HexDecoder); NR<SHA>::Signer privS(f); privS.AccessKey().Precompute(); NR<SHA>::Verifier pubS(privS); pass = SignatureValidate(privS, pubS) && pass; } { cout << "Generating new signature key..." << endl; NR<SHA>::Signer privS(GlobalRNG(), 256); NR<SHA>::Verifier pubS(privS); pass = SignatureValidate(privS, pubS) && pass; } return pass; }
bool NRValidate() { cout << "\nNR validation suite running...\n\n"; bool pass = true; { FileSource f("nr2048.dat", true, new HexDecoder); NRSigner<SHA> privS(f); privS.Precompute(); NRVerifier<SHA> pubS(privS); pass = SignatureValidate(privS, pubS) && pass; } { LC_RNG rng(4781); cout << "Generating new signature key..." << endl; NRSigner<SHA> privS(rng, 256); NRVerifier<SHA> pubS(privS); pass = SignatureValidate(privS, pubS) && pass; } return pass; }
bool EC2NValidate() { cout << "\nEC2N validation suite running...\n\n"; LC_RNG rng(5667); ECDecryptor<EC2N> cpriv(rng, ASN1::sect193r1()); ECEncryptor<EC2N> cpub(cpriv); ByteQueue bq; cpriv.DEREncode(bq); cpub.SetEncodeAsOID(true); cpub.DEREncode(bq); ECSigner<EC2N, SHA> spriv(bq); ECVerifier<EC2N, SHA> spub(bq); ECDHC<EC2N> ecdhc(ASN1::sect193r1()); ECMQVC<EC2N> ecmqvc(ASN1::sect193r1()); spriv.Precompute(); ByteQueue queue; spriv.SavePrecomputation(queue); spub.LoadPrecomputation(queue); bool pass = SignatureValidate(spriv, spub); pass = CryptoSystemValidate(cpriv, cpub) && pass; pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; cout << "Turning on point compression..." << endl; cpriv.SetPointCompression(true); cpub.SetPointCompression(true); ecdhc.SetPointCompression(true); ecmqvc.SetPointCompression(true); pass = CryptoSystemValidate(cpriv, cpub) && pass; pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; #if 0 // TODO: turn this back on when I make EC2N faster for pentanomial basis cout << "Testing SEC 2 recommended curves..." << endl; OID oid; while (!(oid = ECParameters<EC2N>::GetNextRecommendedParametersOID(oid)).m_values.empty()) { ECParameters<EC2N> params(oid); bool fail = !params.ValidateParameters(rng); cout << (fail ? "FAILED" : "passed") << " " << params.GetCurve().GetField().MaxElementBitLength() << " bits" << endl; pass = pass && !fail; } #endif return pass; }
bool ValidateECDSA() { cout << "\nECDSA validation suite running...\n\n"; // from Sample Test Vectors for P1363 GF2NT gf2n(191, 9, 0); byte a[]="\x28\x66\x53\x7B\x67\x67\x52\x63\x6A\x68\xF5\x65\x54\xE1\x26\x40\x27\x6B\x64\x9E\xF7\x52\x62\x67"; byte b[]="\x2E\x45\xEF\x57\x1F\x00\x78\x6F\x67\xB0\x08\x1B\x94\x95\xA3\xD9\x54\x62\xF5\xDE\x0A\xA1\x85\xEC"; EC2N ec(gf2n, PolynomialMod2(a,24), PolynomialMod2(b,24)); EC2N::Point P; ec.DecodePoint(P, (byte *)"\x04\x36\xB3\xDA\xF8\xA2\x32\x06\xF9\xC4\xF2\x99\xD7\xB2\x1A\x9C\x36\x91\x37\xF2\xC8\x4A\xE1\xAA\x0D" "\x76\x5B\xE7\x34\x33\xB3\xF9\x5E\x33\x29\x32\xE7\x0E\xA2\x45\xCA\x24\x18\xEA\x0E\xF9\x80\x18\xFB", ec.EncodedPointSize()); Integer n("40000000000000000000000004a20e90c39067c893bbb9a5H"); Integer d("340562e1dda332f9d2aec168249b5696ee39d0ed4d03760fH"); EC2N::Point Q(ec.Multiply(d, P)); ECDSA<EC2N, SHA>::Signer priv(ec, P, n, d); ECDSA<EC2N, SHA>::Verifier pub(priv); Integer h("A9993E364706816ABA3E25717850C26C9CD0D89DH"); Integer k("3eeace72b4919d991738d521879f787cb590aff8189d2b69H"); byte sig[]="\x03\x8e\x5a\x11\xfb\x55\xe4\xc6\x54\x71\xdc\xd4\x99\x84\x52\xb1\xe0\x2d\x8a\xf7\x09\x9b\xb9\x30" "\x0c\x9a\x08\xc3\x44\x68\xc2\x44\xb4\xe5\xd6\xb2\x1b\x3c\x68\x36\x28\x07\x41\x60\x20\x32\x8b\x6e"; Integer r(sig, 24); Integer s(sig+24, 24); Integer rOut, sOut; bool fail, pass=true; priv.RawSign(k, h, rOut, sOut); fail = (rOut != r) || (sOut != s); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "signature check against test vector\n"; fail = !pub.VerifyMessage((byte *)"abc", 3, sig, sizeof(sig)); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "verification check against test vector\n"; fail = pub.VerifyMessage((byte *)"xyz", 3, sig, sizeof(sig)); pass = pass && !fail; pass = SignatureValidate(priv, pub) && pass; return pass; }
bool ValidateESIGN() { cout << "\nESIGN validation suite running...\n\n"; bool pass = true, fail; static const char plain[] = "test"; static const byte signature[] = "\xA3\xE3\x20\x65\xDE\xDA\xE7\xEC\x05\xC1\xBF\xCD\x25\x79\x7D\x99\xCD\xD5\x73\x9D\x9D\xF3\xA4\xAA\x9A\xA4\x5A\xC8\x23\x3D\x0D\x37\xFE\xBC\x76\x3F\xF1\x84\xF6\x59" "\x14\x91\x4F\x0C\x34\x1B\xAE\x9A\x5C\x2E\x2E\x38\x08\x78\x77\xCB\xDC\x3C\x7E\xA0\x34\x44\x5B\x0F\x67\xD9\x35\x2A\x79\x47\x1A\x52\x37\x71\xDB\x12\x67\xC1\xB6\xC6" "\x66\x73\xB3\x40\x2E\xD6\xF2\x1A\x84\x0A\xB6\x7B\x0F\xEB\x8B\x88\xAB\x33\xDD\xE4\x83\x21\x90\x63\x2D\x51\x2A\xB1\x6F\xAB\xA7\x5C\xFD\x77\x99\xF2\xE1\xEF\x67\x1A" "\x74\x02\x37\x0E\xED\x0A\x06\xAD\xF4\x15\x65\xB8\xE1\xD1\x45\xAE\x39\x19\xB4\xFF\x5D\xF1\x45\x7B\xE0\xFE\x72\xED\x11\x92\x8F\x61\x41\x4F\x02\x00\xF2\x76\x6F\x7C" "\x79\xA2\xE5\x52\x20\x5D\x97\x5E\xFE\x39\xAE\x21\x10\xFB\x35\xF4\x80\x81\x41\x13\xDD\xE8\x5F\xCA\x1E\x4F\xF8\x9B\xB2\x68\xFB\x28"; FileSource keys("TestData/esig1536.dat", true, new HexDecoder); ESIGN<SHA>::Signer signer(keys); ESIGN<SHA>::Verifier verifier(signer); fail = !SignatureValidate(signer, verifier); pass = pass && !fail; fail = !verifier.VerifyMessage((byte *)plain, strlen(plain), signature, verifier.SignatureLength()); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "verification check against test vector\n"; cout << "Generating signature key from seed..." << endl; signer.AccessKey().GenerateRandom(GlobalRNG(), MakeParameters("Seed", ConstByteArrayParameter((const byte *)"test", 4))("KeySize", 3*512)); verifier = signer; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; return pass; }
bool ValidateDSA(bool thorough) { cout << "\nDSA validation suite running...\n\n"; bool pass = true; FileSource fs1("TestData/dsa1024.dat", true, new HexDecoder()); DSA::Signer priv(fs1); DSA::Verifier pub(priv); FileSource fs2("TestData/dsa1024b.dat", true, new HexDecoder()); DSA::Verifier pub1(fs2); CRYPTOPP_ASSERT(pub.GetKey() == pub1.GetKey()); pass = SignatureValidate(priv, pub, thorough) && pass; pass = RunTestDataFile("TestVectors/dsa.txt", g_nullNameValuePairs, thorough) && pass; return pass; }
bool ValidateEC2N() { cout << "\nEC2N validation suite running...\n\n"; ECIES<EC2N>::Decryptor cpriv(GlobalRNG(), ASN1::sect193r1()); ECIES<EC2N>::Encryptor cpub(cpriv); ByteQueue bq; cpriv.DEREncode(bq); cpub.AccessKey().AccessGroupParameters().SetEncodeAsOID(true); cpub.DEREncode(bq); ECDSA<EC2N, SHA>::Signer spriv(bq); ECDSA<EC2N, SHA>::Verifier spub(bq); ECDH<EC2N>::Domain ecdhc(ASN1::sect193r1()); ECMQV<EC2N>::Domain ecmqvc(ASN1::sect193r1()); spriv.AccessKey().Precompute(); ByteQueue queue; spriv.AccessKey().SavePrecomputation(queue); spriv.AccessKey().LoadPrecomputation(queue); bool pass = SignatureValidate(spriv, spub); pass = CryptoSystemValidate(cpriv, cpub) && pass; pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; cout << "Turning on point compression..." << endl; cpriv.AccessKey().AccessGroupParameters().SetPointCompression(true); cpub.AccessKey().AccessGroupParameters().SetPointCompression(true); ecdhc.AccessGroupParameters().SetPointCompression(true); ecmqvc.AccessGroupParameters().SetPointCompression(true); pass = CryptoSystemValidate(cpriv, cpub) && pass; pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; #if 0 // TODO: turn this back on when I make EC2N faster for pentanomial basis cout << "Testing SEC 2 recommended curves..." << endl; OID oid; while (!(oid = DL_GroupParameters_EC<EC2N>::GetNextRecommendedParametersOID(oid)).m_values.empty()) { DL_GroupParameters_EC<EC2N> params(oid); bool fail = !params.Validate(GlobalRNG(), 2); cout << (fail ? "FAILED" : "passed") << " " << params.GetCurve().GetField().MaxElementBitLength() << " bits" << endl; pass = pass && !fail; } #endif return pass; }
bool ValidateECP() { std::cout << "\nECP validation suite running...\n\n"; ECIES<ECP>::Decryptor cpriv(GlobalRNG(), ASN1::secp192r1()); ECIES<ECP>::Encryptor cpub(cpriv); ByteQueue bq; cpriv.GetKey().DEREncode(bq); cpub.AccessKey().AccessGroupParameters().SetEncodeAsOID(true); cpub.GetKey().DEREncode(bq); ECDSA<ECP, SHA>::Signer spriv(bq); ECDSA<ECP, SHA>::Verifier spub(bq); ECDH<ECP>::Domain ecdhc(ASN1::secp192r1()); ECMQV<ECP>::Domain ecmqvc(ASN1::secp192r1()); spriv.AccessKey().Precompute(); ByteQueue queue; spriv.AccessKey().SavePrecomputation(queue); spriv.AccessKey().LoadPrecomputation(queue); bool pass = SignatureValidate(spriv, spub); cpub.AccessKey().Precompute(); cpriv.AccessKey().Precompute(); pass = CryptoSystemValidate(cpriv, cpub) && pass; pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; std::cout << "Turning on point compression..." << std::endl; cpriv.AccessKey().AccessGroupParameters().SetPointCompression(true); cpub.AccessKey().AccessGroupParameters().SetPointCompression(true); ecdhc.AccessGroupParameters().SetPointCompression(true); ecmqvc.AccessGroupParameters().SetPointCompression(true); pass = CryptoSystemValidate(cpriv, cpub) && pass; pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; std::cout << "Testing SEC 2, NIST, and Brainpool recommended curves..." << std::endl; OID oid; while (!(oid = DL_GroupParameters_EC<ECP>::GetNextRecommendedParametersOID(oid)).m_values.empty()) { DL_GroupParameters_EC<ECP> params(oid); bool fail = !params.Validate(GlobalRNG(), 2); std::cout << (fail ? "FAILED" : "passed") << " " << std::dec << params.GetCurve().GetField().MaxElementBitLength() << " bits" << std::endl; pass = pass && !fail; } return pass; }
bool ValidateRabin() { cout << "\nRabin validation suite running...\n\n"; bool pass=true; { FileSource f("TestData/rabi1024.dat", true, new HexDecoder); RabinSS<PSSR, SHA>::Signer priv(f); RabinSS<PSSR, SHA>::Verifier pub(priv); pass = SignatureValidate(priv, pub) && pass; } { RabinES<OAEP<SHA> >::Decryptor priv(GlobalRNG(), 512); RabinES<OAEP<SHA> >::Encryptor pub(priv); pass = CryptoSystemValidate(priv, pub) && pass; } return pass; }
bool ValidateLUC_DL() { cout << "\nLUC-HMP validation suite running...\n\n"; FileSource f("TestData/lucs512.dat", true, new HexDecoder); LUC_HMP<SHA>::Signer privS(f); LUC_HMP<SHA>::Verifier pubS(privS); bool pass = SignatureValidate(privS, pubS); cout << "\nLUC-IES validation suite running...\n\n"; FileSource fc("TestData/lucc512.dat", true, new HexDecoder); LUC_IES<>::Decryptor privC(fc); LUC_IES<>::Encryptor pubC(privC); pass = CryptoSystemValidate(privC, pubC) && pass; return pass; }
bool ValidateLUC() { cout << "\nLUC validation suite running...\n\n"; bool pass=true; { FileSource f("TestData/luc1024.dat", true, new HexDecoder); LUCSSA_PKCS1v15_SHA_Signer priv(f); LUCSSA_PKCS1v15_SHA_Verifier pub(priv); pass = SignatureValidate(priv, pub) && pass; } { LUCES_OAEP_SHA_Decryptor priv(GlobalRNG(), 512); LUCES_OAEP_SHA_Encryptor pub(priv); pass = CryptoSystemValidate(priv, pub) && pass; } return pass; }
bool LUCELGValidate() { cout << "\nLUCELG validation suite running...\n\n"; FileSource f("lucs512.dat", true, new HexDecoder); LUCELG_Signer<SHA> privS(f); LUCELG_Verifier<SHA> pubS(privS); bool pass = SignatureValidate(privS, pubS); FileSource fc("lucc512.dat", true, new HexDecoder); LUCELG_Decryptor privC(fc); LUCELG_Encryptor pubC(privC); pass = CryptoSystemValidate(privC, pubC) && pass; return pass; }
bool LUCValidate() { cout << "\nLUC validation suite running...\n\n"; bool pass=true; { FileSource f("luc512.dat", true, new HexDecoder); LUCSSA_PKCS1v15_SHA_Signer priv(f); LUCSSA_PKCS1v15_SHA_Verifier pub(priv); pass = SignatureValidate(priv, pub) && pass; } { FileSource f("luc512.dat", true, new HexDecoder); LUCES_OAEP_SHA_Decryptor priv(f); LUCES_OAEP_SHA_Encryptor pub(priv); pass = CryptoSystemValidate(priv, pub) && pass; } return pass; }
bool RabinValidate() { cout << "\nRabin validation suite running...\n\n"; bool pass=true; { FileSource f("rabi512.dat", true, new HexDecoder); RabinSignerWith(SHA) priv(f); RabinVerifierWith(SHA) pub(priv); pass = SignatureValidate(priv, pub) && pass; } { FileSource f("rabi512.dat", true, new HexDecoder); RabinDecryptor priv(f); RabinEncryptor pub(priv); pass = CryptoSystemValidate(priv, pub) && pass; } return pass; }