hash_burn.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include <stdio.h>
  16. #include <library.h>
  17. int main(int argc, char *argv[])
  18. {
  19. hash_algorithm_t alg;
  20. hasher_t *hasher;
  21. char buffer[1024];
  22. int limit = 0, i = 0;
  23. library_init(NULL, "hash_burn");
  24. lib->plugins->load(lib->plugins, PLUGINS);
  25. atexit(library_deinit);
  26. printf("loaded: %s\n", PLUGINS);
  27. memset(buffer, 0x12, sizeof(buffer));
  28. if (argc < 2)
  29. {
  30. fprintf(stderr, "usage: %s <algorithm>!\n", argv[0]);
  31. return 1;
  32. }
  33. if (argc > 2)
  34. {
  35. limit = atoi(argv[2]);
  36. }
  37. if (!enum_from_name(hash_algorithm_short_names, argv[1], &alg))
  38. {
  39. fprintf(stderr, "unknown hash algorithm: %s\n", argv[1]);
  40. return 1;
  41. }
  42. hasher = lib->crypto->create_hasher(lib->crypto, alg);
  43. if (!hasher)
  44. {
  45. fprintf(stderr, "hash algorithm not supported: %N\n",
  46. hash_algorithm_names, alg);
  47. return 1;
  48. }
  49. while (TRUE)
  50. {
  51. if (!hasher->get_hash(hasher, chunk_from_thing(buffer), buffer))
  52. {
  53. fprintf(stderr, "hashing failed!\n");
  54. return 1;
  55. }
  56. if (limit && ++i == limit)
  57. {
  58. break;
  59. }
  60. }
  61. hasher->destroy(hasher);
  62. return 0;
  63. }