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"
23 #define ENC_LEN 0x00100000 /* enc data len (at least) */
24 #define ENC_ROUND 512 /* enc rounds (at least) */
25 #define ENC_MIN_TIME 15.0 /* seconds to run the test (at least) */
27 SilcTimerStruct timer;
28 SilcCipher cipher, acc_cipher;
30 int main(int argc, char **argv)
40 silc_crypto_init(NULL);
45 silc_log_debug_hexdump(TRUE);
46 silc_log_set_debug_string("*acc*,*thread*");
49 if (!silc_acc_init(SILC_SOFTACC, (void *)0x01, "min_threads", 2,
50 "max_threads", 8, NULL))
53 data = malloc(ENC_LEN * sizeof(*data));
57 for (i = 0; i < ENC_LEN; i++)
60 silc_timer_synchronize(&timer);
62 for (i = 0; silc_default_ciphers[i].name; i++) {
63 if (!silc_cipher_alloc(silc_default_ciphers[i].name, &cipher)) {
64 fprintf(stderr, "Error allocating %s\n", silc_default_ciphers[i].name);
68 acc_cipher = silc_acc_cipher(SILC_SOFTACC, cipher);
72 silc_cipher_set_iv(acc_cipher, data);
73 silc_cipher_set_key(acc_cipher, data, silc_cipher_get_key_len(cipher),
80 silc_timer_start(&timer);
81 for (k = 0; k < rounds; k++)
82 silc_cipher_encrypt(acc_cipher, data, data, ENC_LEN, NULL);
83 silc_timer_stop(&timer);
85 silc_timer_value(&timer, &sec, &usec);
87 totsec += ((double)usec / (double)((double)1000 * (double)1000));
88 if (totsec < ENC_MIN_TIME) {
93 silc_cipher_free(acc_cipher);
94 silc_cipher_free(cipher);
97 printf("%s:\t%.2f KB (%.2f MB, %.2f Mbit) / sec (total %.3f secs)\n",
98 silc_default_ciphers[i].name,
99 (((double)((double)ENC_LEN * (double)rounds) / 1024.0) / totsec),
100 (((double)((double)ENC_LEN * (double)rounds) / (1024.0 *
102 ((((double)((double)ENC_LEN * (double)rounds) / 1024.0)
107 silc_acc_uninit(SILC_SOFTACC);
109 silc_crypto_uninit();
110 silc_runtime_uninit();