void MD5_verify(const char *input, const char *digest, bool isFile) { bool result; KMD5 context; if (!isFile) { context.update(QByteArray(input)); result = context.verify(digest); cout << "Input string: " << input << endl; } else { QFile f(input); if (!f.open(QIODevice::ReadOnly)) { f.close(); kFatal() << "Cannot open file for reading!"; } result = context.verify(digest); f.close(); cout << "Input filename: " << input << endl; } cout << "Calculated Digest = " << context.hexDigest().data() << endl; cout << "Supplied Digest = " << digest << endl; cout << "Matches: " << (result ? "TRUE" : "FALSE") << endl; }
int POP3Protocol::loginAPOP( char *challenge, KIO::AuthInfo &ai ) { char buf[512]; QString apop_string = QString::fromLatin1("APOP "); if (m_sUser.isEmpty() || m_sPass.isEmpty()) { // Prompt for usernames if (!openPasswordDialog(ai)) { error(ERR_ABORTED, i18n("No authentication details supplied.")); closeConnection(); return -1; } else { m_sUser = ai.username; m_sPass = ai.password; } } m_sOldUser = m_sUser; m_sOldPass = m_sPass; apop_string.append(m_sUser); memset(buf, 0, sizeof(buf)); KMD5 ctx; kDebug(7105) << "APOP challenge: " << challenge; // Generate digest ctx.update(challenge, strlen(challenge)); ctx.update(m_sPass.toLatin1() ); // Genenerate APOP command apop_string.append(" "); apop_string.append(ctx.hexDigest()); if (command(apop_string.toLocal8Bit(), buf, sizeof(buf)) == Ok) { return 0; } kDebug(7105) << "Could not login via APOP. Falling back to USER/PASS"; closeConnection(); if (metaData("auth") == "APOP") { error(ERR_COULD_NOT_LOGIN, i18n ("Login via APOP failed. The server %1 may not support APOP, although it claims to support it, or the password may be wrong.\n\n%2", m_sServer, m_sError)); return -1; } return 1; }
void MD5_string(const char *input, const char *expected, bool rawOutput) { KMD5 context; context.update(QByteArray(input)); cout << "Checking MD5 for: " << input << endl; if (rawOutput) { cout << "Result: " << context.rawDigest() << endl; } else { cout << "Result: " << context.hexDigest().data() << endl; } if (expected) { cout << "Expected: " << expected << endl; cout << "Status: " << context.verify(expected) << endl; } }
void MD5_timeTrial() { KMD5 context; QDateTime endTime; QDateTime startTime; quint8 block[TEST_BLOCK_LEN]; quint32 i; cout << "Timing test. Digesting " << TEST_BLOCK_COUNT << " blocks of " << TEST_BLOCK_LEN << "-byte..." << endl; // Initialize block for (i = 0; i < TEST_BLOCK_LEN; ++i) { block[i] = (quint8)(i & 0xff); } // Start timer startTime = QDateTime::currentDateTime(); // Digest blocks for (i = 0; i < TEST_BLOCK_COUNT; ++i) { context.update(block, TEST_BLOCK_LEN); } // Stop timer endTime = QDateTime::currentDateTime(); long duration = startTime.secsTo(endTime); long speed; if (duration) { speed = (TEST_BLOCK_LEN * (TEST_BLOCK_COUNT / duration)); } else { speed = TEST_BLOCK_COUNT; } cout << "Result: " << endl; cout << " Time = " << duration << " seconds" << endl; cout << " Speed = " << speed << " bytes/second" << endl; cout << " Digest = " << context.hexDigest().data() << endl; }
void MD5_file(const char *filename, bool rawOutput) { QFile f(QFile::encodeName(filename)); if (!f.open(QIODevice::ReadOnly)) { f.close(); kError() << "(" << filename << ") cannot be opened!" << endl; return; } KMD5 context; context.update(f); if (rawOutput) { cout << "MD5 (" << filename << ") = " << context.rawDigest() << endl; } else { cout << "MD5 (" << filename << ") = " << context.hexDigest().data() << endl; } f.close(); }
void MD5_timeTrial () { KMD5 context; time_t endTime; time_t startTime; Q_UINT8 block[TEST_BLOCK_LEN]; Q_UINT32 i; cout << "Timing test. Digesting " << TEST_BLOCK_COUNT << " blocks of " << TEST_BLOCK_LEN << "-byte..." << endl; // Initialize block for (i = 0; i < TEST_BLOCK_LEN; i++) block[i] = (Q_UINT8)(i & 0xff); // Start timer time (&startTime); // Digest blocks for (i = 0; i < TEST_BLOCK_COUNT; i++) context.update (block, TEST_BLOCK_LEN); // Stop timer time (&endTime); long duration = endTime - startTime; long speed; if (duration) speed = (TEST_BLOCK_LEN * (TEST_BLOCK_COUNT/duration)); else speed = TEST_BLOCK_COUNT; cout << "Result: " << endl; cout << " Time = " << duration << " seconds" << endl; cout << " Speed = " << speed << " bytes/second" << endl; cout << " Digest = " << context.hexDigest() << endl; }