]> git.ipfire.org Git - thirdparty/strongswan.git/blame - scripts/hash_burn.c
tnc-pdp: Initialize TNC-PDP in plugin callback with proper dependencies
[thirdparty/strongswan.git] / scripts / hash_burn.c
CommitLineData
8217c099
MW
1/*
2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16#include <stdio.h>
17#include <library.h>
18
19
20
21int main(int argc, char *argv[])
22{
23 hash_algorithm_t alg;
24 hasher_t *hasher;
25 char buffer[1024];
26 int limit = 0, i = 0;
27
28 library_init(NULL);
29 lib->plugins->load(lib->plugins, NULL, PLUGINS);
30 atexit(library_deinit);
31
32 printf("loaded: %s\n", PLUGINS);
33
34 memset(buffer, 0x12, sizeof(buffer));
35
36 if (argc < 2)
37 {
38 fprintf(stderr, "usage: %s <algorithm>!\n", argv[0]);
39 return 1;
40 }
41 if (argc > 2)
42 {
43 limit = atoi(argv[2]);
44 }
45
46 alg = enum_from_name(hash_algorithm_short_names, argv[1]);
47 if (alg == -1)
48 {
49 fprintf(stderr, "unknown hash algorthm: %s\n", argv[1]);
50 return 1;
51 }
52 hasher = lib->crypto->create_hasher(lib->crypto, alg);
53 if (!hasher)
54 {
55 fprintf(stderr, "hash algorthm not supported: %N\n",
56 hash_algorithm_names, alg);
57 return 1;
58 }
59
60 while (TRUE)
61 {
62 if (!hasher->get_hash(hasher, chunk_from_thing(buffer), buffer))
63 {
64 fprintf(stderr, "hashing failed!\n");
65 return 1;
66 }
67 if (limit && ++i == limit)
68 {
69 break;
70 }
71 }
72 hasher->destroy(hasher);
73 return 0;
74}