/* Copyright (C) 2003, 2010 - Wolfire Games This file is part of Lugaru. Lugaru is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // DRIVER.CC - test driver for the C++/object oriented translation and // modification of MD5. // Translation and modification (c) 1995 by Mordechai T. Abzug // This translation/ modification is provided "as is," without express or // implied warranty of any kind. // The translator/ modifier does not claim (1) that MD5 will do what you think // it does; (2) that this translation/ modification is accurate; or (3) that // this software is "merchantible." (Language for this disclaimer partially // copied from the disclaimer below). /* based on: MDDRIVER.C - test driver for MD2, MD4 and MD5 Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights reserved. RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind. These notices must be retained in any copies of any part of this documentation and/or software. */ #include #include #include #include #include "md5.h" // Length of test block, number of test blocks. #define TEST_BLOCK_LEN 1000 #define TEST_BLOCK_COUNT 1000 static void MD5_timeTrial (void); static void MD5_testSuite (void); static void MD5_file (char *); static void MD5_filter (void); static void MD5_string (unsigned char *string); static char *MD5_usage (void); // Main driver. /* int main (int argc, char *argv[]){ int i; MD5_testSuite(); if (argc > 1) for (i = 1; i < argc; i++) if (argv[i][0] == '-' && argv[i][1] == 's') MD5_string ( (unsigned char *) argv[i] + 2); else if (strcmp (argv[i], "-t") == 0) MD5_timeTrial (); else if (strcmp (argv[i], "-x") == 0) MD5_testSuite (); else if (strcmp (argv[i], "-h") == 0) cout << MD5_usage()<< flush; else if (strcmp (argv[i], "-help")==0) cout << MD5_usage()<< flush; else if (argv[i][0] == '-'){ cerr << argv[i] << " is an unknown option.\n" << MD5_usage()<< flush; exit (1); } else MD5_file (argv[i]); else MD5_filter (); return (0); } */ // Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks. static void MD5_timeTrial () { MD5 context; time_t endTime, startTime; unsigned char block[TEST_BLOCK_LEN]; unsigned int i; cout << "MD5 time trial. Digesting "<< TEST_BLOCK_LEN << " "; cout << TEST_BLOCK_COUNT << "-byte blocks ..."; // Initialize block for (i = 0; i < TEST_BLOCK_LEN; i++) block[i] = (unsigned char)(i & 0xff); // Start timer time (&startTime); // Digest blocks for (i = 0; i < TEST_BLOCK_COUNT; i++) context.update (block, TEST_BLOCK_LEN); context.finalize(); // Stop timer time (&endTime); cout << " done" << endl; cout << "Digest = " << context << endl; cout << "Time = "<< (long)(endTime-startTime) << " seconds" << endl; cout << "Speed = "; cout << (long)TEST_BLOCK_LEN * (long)TEST_BLOCK_COUNT/(endTime-startTime); cout << "bytes/second" <