5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2008 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.
20 #include "silccrypto.h"
22 #define ENC_LEN 0x00100000 /* enc data len (at least) */
23 #define ENC_ROUND 512 /* enc rounds (at least) */
24 #define ENC_MIN_TIME 8.0 /* seconds to run the test (at least) */
26 SilcTimerStruct timer;
29 int main(int argc, char **argv)
38 data = malloc(ENC_LEN * sizeof(*data));
42 for (i = 0; i < ENC_LEN; i++)
45 silc_timer_synchronize(&timer);
47 for (i = 0; silc_default_ciphers[i].name; i++) {
48 if (!silc_cipher_alloc(silc_default_ciphers[i].name, &cipher)) {
49 fprintf(stderr, "Error allocating %s\n", silc_default_ciphers[i].name);
53 silc_cipher_set_key(cipher, data, silc_cipher_get_key_len(cipher), TRUE);
54 silc_cipher_set_iv(cipher, data);
59 silc_timer_start(&timer);
60 for (k = 0; k < rounds; k++)
61 silc_cipher_encrypt(cipher, data, data, ENC_LEN, NULL);
62 silc_timer_stop(&timer);
64 silc_timer_value(&timer, &sec, &usec);
66 totsec += ((double)usec / (double)(1000 * 1000));
67 if (totsec < ENC_MIN_TIME) {
72 printf("%s:\t%.2f KB (%.2f MB) / sec (total test time %.2f secs)\n",
73 silc_default_ciphers[i].name,
74 (((double)(ENC_LEN * rounds) / 1024.0) / totsec),
75 (((double)(ENC_LEN * rounds) / (1024.0 * 1024.0)) / totsec),
78 silc_cipher_free(cipher);