Annotation of embedaddon/strongswan/scripts/hash_burn.c, revision 1.1
1.1 ! misho 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:
! 21: int 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, "hash_burn");
! 29: lib->plugins->load(lib->plugins, 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: if (!enum_from_name(hash_algorithm_short_names, argv[1], &alg))
! 47: {
! 48: fprintf(stderr, "unknown hash algorithm: %s\n", argv[1]);
! 49: return 1;
! 50: }
! 51: hasher = lib->crypto->create_hasher(lib->crypto, alg);
! 52: if (!hasher)
! 53: {
! 54: fprintf(stderr, "hash algorithm not supported: %N\n",
! 55: hash_algorithm_names, alg);
! 56: return 1;
! 57: }
! 58:
! 59: while (TRUE)
! 60: {
! 61: if (!hasher->get_hash(hasher, chunk_from_thing(buffer), buffer))
! 62: {
! 63: fprintf(stderr, "hashing failed!\n");
! 64: return 1;
! 65: }
! 66: if (limit && ++i == limit)
! 67: {
! 68: break;
! 69: }
! 70: }
! 71: hasher->destroy(hasher);
! 72: return 0;
! 73: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>