bash_bench.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. *******************************************************************************
  3. \file bash_bench.c
  4. \brief Benchmarks for STB 34.101.77 (bash)
  5. \project bee2/test
  6. \author (C) Sergey Agievich [agievich@{bsu.by|gmail.com}]
  7. \created 2014.07.15
  8. \version 2020.06.23
  9. \license This program is released under the GNU General Public License
  10. version 3. See Copyright Notices in bee2/info.h.
  11. *******************************************************************************
  12. */
  13. #include <stdio.h>
  14. #include <bee2/core/prng.h>
  15. #include <bee2/core/tm.h>
  16. #include <bee2/core/util.h>
  17. #include <bee2/crypto/bash.h>
  18. #include <bee2/crypto/belt.h>
  19. #include <bee2/math/pp.h>
  20. #include <bee2/math/ww.h>
  21. /*
  22. *******************************************************************************
  23. Замер производительности
  24. *******************************************************************************
  25. */
  26. extern const char bash_platform[];
  27. bool_t bashBench()
  28. {
  29. octet belt_state[256];
  30. octet bash_state[1024];
  31. octet combo_state[256];
  32. octet buf[1024];
  33. octet hash[64];
  34. size_t l, d;
  35. // заполнить buf псевдослучайными числами
  36. ASSERT(prngCOMBO_keep() <= sizeof(combo_state));
  37. prngCOMBOStart(combo_state, utilNonce32());
  38. prngCOMBOStepR(buf, sizeof(buf), combo_state);
  39. // платформа
  40. printf("bashBench::platform = %s\n", bash_platform);
  41. // оценить скорость хэширования
  42. {
  43. const size_t reps = 2000;
  44. size_t i;
  45. tm_ticks_t ticks;
  46. // эксперимент c belt
  47. ASSERT(beltHash_keep() <= sizeof(belt_state));
  48. beltHashStart(belt_state);
  49. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  50. beltHashStepH(buf, sizeof(buf), belt_state);
  51. beltHashStepG(hash, belt_state);
  52. ticks = tmTicks() - ticks;
  53. printf("bashBench::belt-hash: %3u cpb [%5u kBytes/sec]\n",
  54. (unsigned)(ticks / 1024 / reps),
  55. (unsigned)tmSpeed(reps, ticks));
  56. // эксперимент c bashHashLLL
  57. ASSERT(bashHash_keep() <= sizeof(bash_state));
  58. for (l = 128; l <= 256; l += 64)
  59. {
  60. bashHashStart(bash_state, l);
  61. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  62. bashHashStepH(buf, sizeof(buf), bash_state);
  63. bashHashStepG(hash, l / 4, bash_state);
  64. ticks = tmTicks() - ticks;
  65. printf("bashBench::bash%u: %3u cpb [%5u kBytes/sec]\n",
  66. (unsigned)(2 * l),
  67. (unsigned)(ticks / sizeof(buf) / reps),
  68. (unsigned)tmSpeed(reps, ticks));
  69. }
  70. // эксперимент с bash-prg-hashLLLD
  71. ASSERT(bashPrg_keep() <= sizeof(bash_state));
  72. for (l = 128; l <= 256; l += 64)
  73. for (d = 1; d <= 2; ++d)
  74. {
  75. bashPrgStart(bash_state, l, d, hash, l / 8, 0, 0);
  76. bashPrgAbsorbStart(bash_state);
  77. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  78. bashPrgAbsorbStep(buf, 1024, bash_state);
  79. bashPrgSqueeze(hash, l / 4, bash_state);
  80. ticks = tmTicks() - ticks;
  81. printf("bashBench::bash-prg-hash%u%u: %3u cpb [%5u kBytes/sec]\n",
  82. (unsigned)(2 * l), (unsigned)d,
  83. (unsigned)(ticks / sizeof(buf) / reps),
  84. (unsigned)tmSpeed(reps, ticks));
  85. }
  86. // эксперимент с bash-prg-aeLLLD
  87. ASSERT(bashPrg_keep() <= sizeof(bash_state));
  88. for (l = 128; l <= 256; l += 64)
  89. for (d = 1; d <= 2; ++d)
  90. {
  91. bashPrgStart(bash_state, l, d, 0, 0, hash, l / 8);
  92. bashPrgEncrStart(bash_state);
  93. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  94. bashPrgEncrStep(buf, 1024, bash_state);
  95. bashPrgDecrStart(bash_state);
  96. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  97. bashPrgDecrStep(buf, 1024, bash_state);
  98. ticks = tmTicks() - ticks;
  99. printf("bashBench::bash-prg-ae%u%u: %3u cpb [%5u kBytes/sec]\n",
  100. (unsigned)l, (unsigned)d,
  101. (unsigned)(ticks / (2 * sizeof(buf)) / reps),
  102. (unsigned)tmSpeed(2 * reps, ticks));
  103. }
  104. }
  105. // все нормально
  106. return TRUE;
  107. }