diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2009-11-29 00:11:12 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2009-11-29 01:08:05 +0200 |
commit | 0477fd0883cbd9cd9809c3b8029ce146187b5431 (patch) | |
tree | 197ec8f844aee340bc79b842a3a400eed3aecaa5 /src | |
parent | 02ee5842f8f5f37ee93e258d5edfc2560b00ac2c (diff) | |
download | gnutls-0477fd0883cbd9cd9809c3b8029ce146187b5431.tar.gz |
Added cryptodev support (/dev/crypto). Tested with http://www.logix.cz/michal/devel/cryptodev/.
Added benchmark utility for AES. Exported API to access encryption algorithms.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/benchmark.c | 79 |
2 files changed, 83 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 80b4f76fcd..9b6eb7ef9e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,6 +28,7 @@ AM_CPPFLAGS = \ -I$(srcdir)/../libextra/includes \ -I$(srcdir)/cfg +noinst_PROGRAMS = benchmark bin_PROGRAMS = gnutls-serv gnutls-cli psktool gnutls-cli-debug if ENABLE_PKI bin_PROGRAMS += certtool @@ -60,6 +61,9 @@ noinst_LTLIBRARIES += libcmd-psk.la libcmd_psk_la_CFLAGS = libcmd_psk_la_SOURCES = psk.gaa psk-gaa.h psk-gaa.c +benchmark_SOURCES = benchmark.c +benchmark_LDADD = ../lib/libgnutls.la ../gl/libgnu.la -lrt + gnutls_cli_SOURCES = cli.c common.h common.c gnutls_cli_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la gnutls_cli_LDADD += libcmd-cli.la ../gl/libgnu.la diff --git a/src/benchmark.c b/src/benchmark.c new file mode 100644 index 0000000000..83d57f44c9 --- /dev/null +++ b/src/benchmark.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2009 Free Software Foundation + * + * This file is part of GNUTLS. + * + * GNUTLS 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 3 of the License, or + * (at your option) any later version. + * + * GNUTLS 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, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <gnutls/gnutls.h> +#include <gnutls/crypto.h> +#include <time.h> + +static unsigned char data[64*1024]; + +void cipher_bench(int size) +{ +int ret, i; +gnutls_cipher_hd_t ctx; +gnutls_datum_t key = { "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01", 16 }; +gnutls_datum_t iv = { "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 16 }; +struct timespec start, stop; +double secs; +long data_size = 0; +double dd; + + gnutls_global_init(); + + printf("Checking AES (%dkb payload)... ", size); + fflush(stdout); + clock_gettime(CLOCK_MONOTONIC, &start); + + ret = gnutls_cipher_init( &ctx, GNUTLS_CIPHER_AES_128_CBC, &key, &iv); + if (ret < 0) { + fprintf(stderr, "error: %s\n", gnutls_strerror(ret)); + return; + } + + for (i=0;i<7*1024;i++) { + gnutls_cipher_encrypt(ctx, data, size*1024); + data_size+= size*1024; + } + + gnutls_cipher_deinit(ctx); + + clock_gettime(CLOCK_MONOTONIC, &stop); + + secs = (stop.tv_sec*1000+stop.tv_nsec/(1000*1000)-(start.tv_sec*1000+start.tv_nsec/(1000*1000))); + secs /= 1000; + dd = (((double)data_size/(double)secs))/1000; + printf("Transferred %u kb in %.2f secs: ", data_size/1000, secs); + printf("%.2f kbyte/sec\n", dd); + +} + + +int main() +{ + cipher_bench(8); + cipher_bench(16); + cipher_bench(32); + + return 0; +} |