5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2007 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
22 #define HASH_LEN 0x0002ffff /* hash data len (at least) */
23 #define HASH_ROUND 256 /* hash rounds (at least) */
24 #define HASH_MIN_TIME 2.0 /* seconds to run the test (at least) */
26 SilcTimerStruct timer;
29 int main(int argc, char **argv)
36 unsigned char digest[SILC_HASH_MAXLEN];
39 data = malloc(HASH_LEN * sizeof(*data));
43 for (i = 0; i < HASH_LEN; i++)
46 silc_timer_synchronize(&timer);
48 for (i = 0; silc_default_hash[i].name; i++) {
49 if (!silc_hash_alloc(silc_default_hash[i].name, &hash))
56 silc_timer_start(&timer);
57 for (k = 0; k < rounds; k++)
58 silc_hash_update(hash, data, HASH_LEN);
59 silc_timer_stop(&timer);
60 silc_hash_final(hash, digest);
62 silc_timer_value(&timer, &sec, &usec);
64 totsec += ((double)usec / (double)(1000 * 1000));
65 if (totsec < HASH_MIN_TIME) {
70 printf("%s:\t%.2f KB (%.2f MB) / sec (total test time %.2f secs)\n",
71 silc_default_hash[i].name,
72 (((double)(HASH_LEN * rounds) / 1024.0) / totsec),
73 (((double)(HASH_LEN * rounds) / (1024.0 * 1024.0)) / totsec),