bool ProfileSignatureValidate(PK_Signer &priv, PK_Verifier &pub, const byte *input, const size_t inputLength, string description, bool thorough = false) { bool pass = true, fail; fail = !pub.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2) || !priv.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2); assert(pass && !fail); SecByteBlock signature(priv.MaxSignatureLength()); std::chrono::steady_clock::time_point signStartTime = std::chrono::steady_clock::now(); size_t signatureLength = priv.SignMessage(GlobalRNG(), input, inputLength, signature); std::chrono::steady_clock::time_point signEndTime = std::chrono::steady_clock::now(); size_t signNanoSeconds = std::chrono::duration_cast<std::chrono::nanoseconds>(signEndTime - signStartTime).count(); cout << generateCSVString(description, "sign", signNanoSeconds) << endl; std::chrono::steady_clock::time_point verifyStartTime = std::chrono::steady_clock::now(); fail = !pub.VerifyMessage(input, inputLength, signature, signatureLength); std::chrono::steady_clock::time_point verifyEndTime = std::chrono::steady_clock::now(); size_t verifyNanoSeconds = std::chrono::duration_cast<std::chrono::nanoseconds>(verifyEndTime - verifyStartTime).count(); cout << generateCSVString(description, "verify", verifyNanoSeconds) << endl; assert(pass && !fail); return pass; }
bool SimpleKeyAgreementValidate(SimpleKeyAgreementDomain &d) { if (d.GetCryptoParameters().Validate(GlobalRNG(), 3)) cout << "passed simple key agreement domain parameters validation" << endl; else { cout << "FAILED simple key agreement domain parameters invalid" << endl; return false; } SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength()); SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength()); SecByteBlock val1(d.AgreedValueLength()), val2(d.AgreedValueLength()); d.GenerateKeyPair(GlobalRNG(), priv1, pub1); d.GenerateKeyPair(GlobalRNG(), priv2, pub2); memset(val1.begin(), 0x10, val1.size()); memset(val2.begin(), 0x11, val2.size()); if (!(d.Agree(val1, priv1, pub2) && d.Agree(val2, priv2, pub1))) { cout << "FAILED simple key agreement failed" << endl; return false; } if (!VerifyBufsEqual(val1.begin(), val2.begin(), d.AgreedValueLength())) { cout << "FAILED simple agreed values not equal" << endl; return false; } cout << "passed simple key agreement" << endl; return true; }
void BenchMarkVerification(const char *name, const PK_Signer &priv, PK_Verifier &pub, double timeTotal, bool pc=false) { unsigned int len = 16; AlignedSecByteBlock message(len), signature(pub.SignatureLength()); GlobalRNG().GenerateBlock(message, len); priv.SignMessage(GlobalRNG(), message, len, signature); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) { // The return value is ignored because we are interested in throughput bool unused = pub.VerifyMessage(message, len, signature, signature.size()); CRYPTOPP_UNUSED(unused); } OutputResultOperations(name, "Verification", pc, i, timeTaken); if (!pc && pub.GetMaterial().SupportsPrecomputation()) { pub.AccessMaterial().Precompute(16); BenchMarkVerification(name, priv, pub, timeTotal, true); } }
bool TestModeIV(SymmetricCipher &e, SymmetricCipher &d) { SecByteBlock lastIV, iv(e.IVSize()); StreamTransformationFilter filter(e, new StreamTransformationFilter(d)); byte plaintext[20480]; for (unsigned int i=1; i<sizeof(plaintext); i*=2) { e.GetNextIV(GlobalRNG(), iv); if (iv == lastIV) return false; else lastIV = iv; e.Resynchronize(iv); d.Resynchronize(iv); unsigned int length = STDMAX(GlobalRNG().GenerateWord32(0, i), (word32)e.MinLastBlockSize()); GlobalRNG().GenerateBlock(plaintext, length); if (!TestFilter(filter, plaintext, length, plaintext, length)) return false; } return true; }
bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough = false) { bool pass = true, fail; fail = !pub.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2) || !priv.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "cryptosystem key validation\n"; static const byte message[] = "test message"; const int messageLen = COUNTOF(message); SecByteBlock ciphertext(priv.CiphertextLength(messageLen)); SecByteBlock plaintext(priv.MaxPlaintextLength(ciphertext.size())); pub.Encrypt(GlobalRNG(), message, messageLen, ciphertext); fail = priv.Decrypt(GlobalRNG(), ciphertext, priv.CiphertextLength(messageLen), plaintext) != DecodingResult(messageLen); fail = fail || !VerifyBufsEqual(message, plaintext, messageLen); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "encryption and decryption\n"; return pass; }
void RandomizedTransfer(BufferedTransformation &source, BufferedTransformation &target, bool finish, const std::string &channel=DEFAULT_CHANNEL) { while (source.MaxRetrievable() > (finish ? 0 : 4096)) { byte buf[4096+64]; size_t start = GlobalRNG().GenerateWord32(0, 63); size_t len = GlobalRNG().GenerateWord32(1, UnsignedMin(4096U, 3*source.MaxRetrievable()/2)); len = source.Get(buf+start, len); target.ChannelPut(channel, buf+start, len); } }
bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false) { bool pass = true, fail; fail = !pub.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2) || !priv.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "signature key validation\n"; static const byte message[] = "test message"; const unsigned int messageLen = COUNTOF(message); SecByteBlock signature(priv.MaxSignatureLength()); size_t signatureLength = priv.SignMessage(GlobalRNG(), message, messageLen, signature); fail = !pub.VerifyMessage(message, messageLen, signature, signatureLength); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "signature and verification\n"; ++signature[0]; fail = pub.VerifyMessage(message, messageLen, signature, signatureLength); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "checking invalid signature" << endl; if (priv.MaxRecoverableLength() > 0) { signatureLength = priv.SignMessageWithRecovery(GlobalRNG(), message, messageLen, NULL, 0, signature); SecByteBlock recovered(priv.MaxRecoverableLengthFromSignatureLength(signatureLength)); DecodingResult result = pub.RecoverMessage(recovered, NULL, 0, signature, signatureLength); fail = !(result.isValidCoding && result.messageLength == messageLen && VerifyBufsEqual(recovered, message, messageLen)); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "signature and verification with recovery" << endl; ++signature[0]; result = pub.RecoverMessage(recovered, NULL, 0, signature, signatureLength); fail = result.isValidCoding; pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "recovery with invalid signature" << endl; } return pass; }
void TestKeyPairValidAndConsistent(CryptoMaterial &pub, const CryptoMaterial &priv) { if (!pub.Validate(GlobalRNG(), 3)) SignalTestFailure(); if (!priv.Validate(GlobalRNG(), 3)) SignalTestFailure(); /* EqualityComparisonFilter comparison; pub.Save(ChannelSwitch(comparison, "0")); pub.AssignFrom(priv); pub.Save(ChannelSwitch(comparison, "1")); comparison.ChannelMessageSeriesEnd("0"); comparison.ChannelMessageSeriesEnd("1"); */ }
void TestKeyPairValidAndConsistent(CryptoMaterial &pub, const CryptoMaterial &priv) { // "!!" converts between bool <-> integral. if (!pub.Validate(GlobalRNG(), 2U+!!s_thorough)) SignalTestFailure(); if (!priv.Validate(GlobalRNG(), 2U+!!s_thorough)) SignalTestFailure(); ByteQueue bq1, bq2; pub.Save(bq1); pub.AssignFrom(priv); pub.Save(bq2); if (bq1 != bq2) SignalTestFailure(); }
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 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; }
void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename) { FileSource privFile(privFilename, true); RSASSA_PKCS1v15_SHA_Signer priv(privFile); // RSASSA_PKCS1v15_SHA_Signer ignores the rng. Use a real RNG for other signature schemes! FileSource f(messageFilename, true, new SignerFilter(GlobalRNG(), priv, new FileSink(signatureFilename))); }
void BenchMarkDecryption(const char *name, PK_Decryptor &priv, PK_Encryptor &pub, double timeTotal) { unsigned int len = 16; SecByteBlock ciphertext(pub.CiphertextLength(len)); SecByteBlock plaintext(pub.MaxPlaintextLength(ciphertext.size())); GlobalRNG().GenerateBlock(plaintext, len); pub.Encrypt(GlobalRNG(), plaintext, len, ciphertext); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) priv.Decrypt(GlobalRNG(), ciphertext, ciphertext.size(), plaintext); OutputResultOperations(name, "Decryption", false, i, timeTaken); }
string RSADecryptString(const char *privFilename, const char *ciphertext) { FileSource privFile(privFilename, true, new HexDecoder); RSAES_OAEP_SHA_Decryptor priv(privFile); string result; StringSource(ciphertext, true, new HexDecoder(new PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result)))); return result; }
void BenchMarkAgreement(const char *name, SimpleKeyAgreementDomain &d, double timeTotal, bool pc=false) { SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength()); SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength()); d.GenerateKeyPair(GlobalRNG(), priv1, pub1); d.GenerateKeyPair(GlobalRNG(), priv2, pub2); SecByteBlock val(d.AgreedValueLength()); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i+=2) { d.Agree(val, priv1, pub2); d.Agree(val, priv2, pub1); } OutputResultOperations(name, "Key Agreement", pc, i, timeTaken); }
void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal, bool pc=false) { unsigned int len = 16; SecByteBlock plaintext(len), ciphertext(key.CiphertextLength(len)); GlobalRNG().GenerateBlock(plaintext, len); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) key.Encrypt(GlobalRNG(), plaintext, len, ciphertext); OutputResultOperations(name, "Encryption", pc, i, timeTaken); if (!pc && key.GetMaterial().SupportsPrecomputation()) { key.AccessMaterial().Precompute(16); BenchMarkEncryption(name, key, timeTotal, true); } }
void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool pc=false) { unsigned int len = 16; AlignedSecByteBlock message(len), signature(key.SignatureLength()); GlobalRNG().GenerateBlock(message, len); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) key.SignMessage(GlobalRNG(), message, len, signature); OutputResultOperations(name, "Signature", pc, i, timeTaken); if (!pc && key.GetMaterial().SupportsPrecomputation()) { key.AccessMaterial().Precompute(16); BenchMarkSigning(name, key, timeTotal, true); } }
bool ValidateRW(const byte *input, const size_t inputLength, const int secLevelIndex) { string description = generateDetailedDescription("RW", securityLevels[secLevelIndex], factorizationGroupSizes[secLevelIndex], inputLength); RWSS<PSSR, SHA>::Signer priv(GlobalRNG(), factorizationGroupSizes[secLevelIndex]); RWSS<PSSR, SHA>::Verifier pub(priv); bool pass = ProfileSignatureValidate(priv, pub, input, inputLength, description); assert(pass); return pass; }
bool ValidateLUC_DL(const byte *input, const size_t inputLength, const int secLevelIndex) { string description = generateDetailedDescription("LUC-DL", securityLevels[secLevelIndex], finiteFieldSizes[secLevelIndex], inputLength); LUC_HMP<SHA>::Signer privS(GlobalRNG(), finiteFieldSizes[secLevelIndex]); LUC_HMP<SHA>::Verifier pubS(privS); bool pass = ProfileSignatureValidate(privS, pubS, input, inputLength, description); assert(pass); return pass; }
bool ValidateLUC(const byte *input, const size_t inputLength, const int secLevelIndex) { string description = generateDetailedDescription("LUC", securityLevels[secLevelIndex], factorizationGroupSizes[secLevelIndex], inputLength); LUCSSA_PKCS1v15_SHA_Signer priv(GlobalRNG(), factorizationGroupSizes[secLevelIndex]); LUCSSA_PKCS1v15_SHA_Verifier pub(priv); bool pass = ProfileSignatureValidate(priv, pub, input, inputLength, description); assert(pass); return pass; }
bool ValidateDLIES() { cout << "\nDLIES validation suite running...\n\n"; bool pass = true; { FileSource fc("TestData/dlie1024.dat", true, new HexDecoder); DLIES<>::Decryptor privC(fc); DLIES<>::Encryptor pubC(privC); pass = CryptoSystemValidate(privC, pubC) && pass; } { cout << "Generating new encryption key..." << endl; DLIES<>::GroupParameters gp; gp.GenerateRandomWithKeySize(GlobalRNG(), 128); DLIES<>::Decryptor decryptor; decryptor.AccessKey().GenerateRandom(GlobalRNG(), gp); DLIES<>::Encryptor encryptor(decryptor); pass = CryptoSystemValidate(decryptor, encryptor) && pass; } return pass; }
bool AuthenticatedKeyAgreementValidate(AuthenticatedKeyAgreementDomain &d) { if (d.GetCryptoParameters().Validate(GlobalRNG(), 3)) cout << "passed authenticated key agreement domain parameters validation" << endl; else { cout << "FAILED authenticated key agreement domain parameters invalid" << endl; return false; } SecByteBlock spriv1(d.StaticPrivateKeyLength()), spriv2(d.StaticPrivateKeyLength()); SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength()); SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength()); SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength()); SecByteBlock val1(d.AgreedValueLength()), val2(d.AgreedValueLength()); d.GenerateStaticKeyPair(GlobalRNG(), spriv1, spub1); d.GenerateStaticKeyPair(GlobalRNG(), spriv2, spub2); d.GenerateEphemeralKeyPair(GlobalRNG(), epriv1, epub1); d.GenerateEphemeralKeyPair(GlobalRNG(), epriv2, epub2); memset(val1.begin(), 0x10, val1.size()); memset(val2.begin(), 0x11, val2.size()); if (!(d.Agree(val1, spriv1, epriv1, spub2, epub2) && d.Agree(val2, spriv2, epriv2, spub1, epub1))) { cout << "FAILED authenticated key agreement failed" << endl; return false; } if (!VerifyBufsEqual(val1.begin(), val2.begin(), d.AgreedValueLength())) { cout << "FAILED authenticated agreed values not equal" << endl; return false; } cout << "passed authenticated key agreement" << endl; return true; }
bool ValidateNR(const byte *input, const size_t inputLength, const int secLevelIndex) { string description = generateDetailedDescription("NR", securityLevels[secLevelIndex], factorizationGroupSizes[secLevelIndex], inputLength); NR<SHA>::Signer privS(GlobalRNG(), finiteFieldSubgroupSizes[secLevelIndex]); privS.AccessKey().Precompute(); NR<SHA>::Verifier pubS(privS); bool pass = ProfileSignatureValidate(privS, pubS, input, inputLength, description); assert(pass); return pass; }
bool TestFilter(BufferedTransformation &bt, const byte *in, size_t inLen, const byte *out, size_t outLen) { FilterTester *ft; bt.Attach(ft = new FilterTester(out, outLen)); while (inLen) { size_t randomLen = GlobalRNG().GenerateWord32(0, (word32)inLen); bt.Put(in, randomLen); in += randomLen; inLen -= randomLen; } bt.MessageEnd(); return ft->GetResult(); }
void BenchMarkKeyGen(const char *name, AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false) { SecByteBlock priv(d.EphemeralPrivateKeyLength()), pub(d.EphemeralPublicKeyLength()); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) d.GenerateEphemeralKeyPair(GlobalRNG(), priv, pub); OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken); if (!pc && d.GetMaterial().SupportsPrecomputation()) { d.AccessMaterial().Precompute(16); BenchMarkKeyGen(name, d, timeTotal, true); } }
bool ValidateRSA(const byte *input, const size_t inputLength, const int secLevelIndex) { string description = generateDetailedDescription("RSA", securityLevels[secLevelIndex], factorizationGroupSizes[secLevelIndex], inputLength); // FileSource keys("TestData/rsa512a.dat", true, new HexDecoder); // FileSource keys("mykey.pem", true, new HexDecoder); // Weak::RSASSA_PKCS1v15_MD2_Signer rsaPriv(keys); Weak::RSASSA_PKCS1v15_MD2_Signer rsaPriv(GlobalRNG(), factorizationGroupSizes[secLevelIndex]); Weak::RSASSA_PKCS1v15_MD2_Verifier rsaPub(rsaPriv); bool pass = ProfileSignatureValidate(rsaPriv, rsaPub, input, inputLength, description); assert(pass); 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() { 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; }
void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal) { const int BUF_SIZE=RoundUpToMultipleOf(2048U, cipher.OptimalBlockSize()); AlignedSecByteBlock buf(BUF_SIZE); GlobalRNG().GenerateBlock(buf, BUF_SIZE); clock_t start = clock(); unsigned long i=0, blocks=1; double timeTaken; do { blocks *= 2; for (; i<blocks; i++) cipher.ProcessString(buf, BUF_SIZE); timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND; } while (timeTaken < 2.0/3*timeTotal); OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken); }
void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal) { const int BUF_SIZE=2048U; AlignedSecByteBlock buf(BUF_SIZE); GlobalRNG().GenerateBlock(buf, BUF_SIZE); clock_t start = clock(); unsigned long i=0, blocks=1; double timeTaken; do { blocks *= 2; for (; i<blocks; i++) bt.Put(buf, BUF_SIZE); timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND; } while (timeTaken < 2.0/3*timeTotal); OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken); }