diff options
author | Martin Willi <martin@revosec.ch> | 2012-07-17 17:11:01 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-07-17 17:32:08 +0200 |
commit | 8217c099cedae0617cb56eda728ab485dcb16838 (patch) | |
tree | 99ec6ab8a73e34b218d1e08791b2aa6542f3bf24 /scripts | |
parent | c63fb853e88ff0dd6dca07ecf61009e736a28eff (diff) | |
download | strongswan-8217c099cedae0617cb56eda728ab485dcb16838.tar.bz2 strongswan-8217c099cedae0617cb56eda728ab485dcb16838.tar.xz |
Add a tool to burn hashers
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/.gitignore | 1 | ||||
-rw-r--r-- | scripts/Makefile.am | 4 | ||||
-rw-r--r-- | scripts/hash_burn.c | 74 |
3 files changed, 78 insertions, 1 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore index 4a715e590..2c8b8008d 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -8,5 +8,6 @@ thread_analysis dh_speed pubkey_speed crypt_burn +hash_burn tls_test fetch diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 5f303be17..ea399e84c 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -3,7 +3,7 @@ AM_CFLAGS = \ -DPLUGINS="\"${scripts_plugins}\"" noinst_PROGRAMS = bin2array bin2sql id2sql key2keyid keyid2sql oid2der \ - thread_analysis dh_speed pubkey_speed crypt_burn fetch + thread_analysis dh_speed pubkey_speed crypt_burn hash_burn fetch if USE_TLS noinst_PROGRAMS += tls_test @@ -22,6 +22,7 @@ thread_analysis_SOURCES = thread_analysis.c dh_speed_SOURCES = dh_speed.c pubkey_speed_SOURCES = pubkey_speed.c crypt_burn_SOURCES = crypt_burn.c +hash_burn_SOURCES = hash_burn.c fetch_SOURCES = fetch.c id2sql_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la key2keyid_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la @@ -30,6 +31,7 @@ oid2der_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la dh_speed_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la -lrt pubkey_speed_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la -lrt crypt_burn_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la +hash_burn_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la fetch_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la key2keyid.o : $(top_builddir)/config.status diff --git a/scripts/hash_burn.c b/scripts/hash_burn.c new file mode 100644 index 000000000..e616d6d5a --- /dev/null +++ b/scripts/hash_burn.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2012 Martin Willi + * Copyright (C) 2012 revosec AG + * + * This program 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. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +#include <stdio.h> +#include <library.h> + + + +int main(int argc, char *argv[]) +{ + hash_algorithm_t alg; + hasher_t *hasher; + char buffer[1024]; + int limit = 0, i = 0; + + library_init(NULL); + lib->plugins->load(lib->plugins, NULL, PLUGINS); + atexit(library_deinit); + + printf("loaded: %s\n", PLUGINS); + + memset(buffer, 0x12, sizeof(buffer)); + + if (argc < 2) + { + fprintf(stderr, "usage: %s <algorithm>!\n", argv[0]); + return 1; + } + if (argc > 2) + { + limit = atoi(argv[2]); + } + + alg = enum_from_name(hash_algorithm_short_names, argv[1]); + if (alg == -1) + { + fprintf(stderr, "unknown hash algorthm: %s\n", argv[1]); + return 1; + } + hasher = lib->crypto->create_hasher(lib->crypto, alg); + if (!hasher) + { + fprintf(stderr, "hash algorthm not supported: %N\n", + hash_algorithm_names, alg); + return 1; + } + + while (TRUE) + { + if (!hasher->get_hash(hasher, chunk_from_thing(buffer), buffer)) + { + fprintf(stderr, "hashing failed!\n"); + return 1; + } + if (limit && ++i == limit) + { + break; + } + } + hasher->destroy(hasher); + return 0; +} |