]> git.ipfire.org Git - thirdparty/strongswan.git/blob - scripts/hash_burn.c
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / scripts / hash_burn.c
1 /*
2 * Copyright (C) 2012 Martin Willi
3 *
4 * Copyright (C) secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include <stdio.h>
18 #include <library.h>
19
20
21
22 int main(int argc, char *argv[])
23 {
24 hash_algorithm_t alg;
25 hasher_t *hasher;
26 char buffer[1024];
27 int limit = 0, i = 0;
28
29 library_init(NULL, "hash_burn");
30 lib->plugins->load(lib->plugins, PLUGINS);
31 atexit(library_deinit);
32
33 printf("loaded: %s\n", PLUGINS);
34
35 memset(buffer, 0x12, sizeof(buffer));
36
37 if (argc < 2)
38 {
39 fprintf(stderr, "usage: %s <algorithm>!\n", argv[0]);
40 return 1;
41 }
42 if (argc > 2)
43 {
44 limit = atoi(argv[2]);
45 }
46
47 if (!enum_from_name(hash_algorithm_short_names, argv[1], &alg))
48 {
49 fprintf(stderr, "unknown hash algorithm: %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 algorithm 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 }