common.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis
  2. *
  3. * LibTomCrypt is a library that provides various cryptographic
  4. * algorithms in a highly modular and flexible manner.
  5. *
  6. * The library is free for all purposes without any express
  7. * guarantee it works.
  8. */
  9. #include "common.h"
  10. /**
  11. @file common.c
  12. Steffen Jaeckel
  13. */
  14. void run_cmd(int res, int line, const char *file, const char *cmd, const char *algorithm)
  15. {
  16. if (res != CRYPT_OK) {
  17. fprintf(stderr, "%s (%d)%s%s\n%s:%d:%s\n",
  18. error_to_string(res), res,
  19. (algorithm ? " - " : ""), (algorithm ? algorithm : ""),
  20. file, line, cmd);
  21. if (res != CRYPT_NOP) {
  22. exit(EXIT_FAILURE);
  23. }
  24. }
  25. }
  26. void print_hex(const char* what, const void* v, const unsigned long l)
  27. {
  28. const unsigned char* p = v;
  29. unsigned long x, y = 0, z;
  30. fprintf(stderr, "%s contents: \n", what);
  31. for (x = 0; x < l; ) {
  32. fprintf(stderr, "%02X ", p[x]);
  33. if (!(++x % 16) || x == l) {
  34. if((x % 16) != 0) {
  35. z = 16 - (x % 16);
  36. if(z >= 8)
  37. fprintf(stderr, " ");
  38. for (; z != 0; --z) {
  39. fprintf(stderr, " ");
  40. }
  41. }
  42. fprintf(stderr, " | ");
  43. for(; y < x; y++) {
  44. if((y % 8) == 0)
  45. fprintf(stderr, " ");
  46. if(isgraph(p[y]))
  47. fprintf(stderr, "%c", p[y]);
  48. else
  49. fprintf(stderr, ".");
  50. }
  51. fprintf(stderr, "\n");
  52. }
  53. else if((x % 8) == 0) {
  54. fprintf(stderr, " ");
  55. }
  56. }
  57. }
  58. prng_state yarrow_prng;
  59. /* ref: $Format:%D$ */
  60. /* git commit: $Format:%H$ */
  61. /* commit time: $Format:%ai$ */