bash_bench.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. *******************************************************************************
  3. \file bash_bench.c
  4. \brief Benchmarks for STB 34.101.77 (bash)
  5. \project bee2/test
  6. \created 2014.07.15
  7. \version 2023.03.30
  8. \copyright The Bee2 authors
  9. \license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
  10. *******************************************************************************
  11. */
  12. #include <stdio.h>
  13. #include <bee2/core/prng.h>
  14. #include <bee2/core/tm.h>
  15. #include <bee2/core/util.h>
  16. #include <bee2/crypto/bash.h>
  17. #include <bee2/crypto/belt.h>
  18. #include <bee2/math/pp.h>
  19. #include <bee2/math/ww.h>
  20. /*
  21. *******************************************************************************
  22. Замер производительности
  23. *******************************************************************************
  24. */
  25. extern const char bash_platform[];
  26. bool_t bashBench()
  27. {
  28. octet belt_state[256];
  29. octet bash_state[1024];
  30. octet combo_state[256];
  31. octet buf[1024];
  32. octet hash[64];
  33. size_t l, d;
  34. // подготовить память
  35. if (sizeof(belt_state) < beltHash_keep() ||
  36. sizeof(bash_state) < bashPrg_keep() ||
  37. sizeof(bash_state) < bashHash_keep() ||
  38. sizeof(combo_state) < prngCOMBO_keep())
  39. return FALSE;
  40. // заполнить buf псевдослучайными числами
  41. prngCOMBOStart(combo_state, utilNonce32());
  42. prngCOMBOStepR(buf, sizeof(buf), combo_state);
  43. // платформа
  44. printf("bashBench::platform = %s\n", bash_platform);
  45. // оценить скорость хэширования
  46. {
  47. const size_t reps = 2000;
  48. size_t i;
  49. tm_ticks_t ticks;
  50. // эксперимент c belt
  51. beltHashStart(belt_state);
  52. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  53. beltHashStepH(buf, sizeof(buf), belt_state);
  54. beltHashStepG(hash, belt_state);
  55. ticks = tmTicks() - ticks;
  56. printf("bashBench::belt-hash: %3u cpb [%5u kBytes/sec]\n",
  57. (unsigned)(ticks / 1024 / reps),
  58. (unsigned)tmSpeed(reps, ticks));
  59. // эксперимент c bashHashLLL
  60. for (l = 128; l <= 256; l += 64)
  61. {
  62. bashHashStart(bash_state, l);
  63. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  64. bashHashStepH(buf, sizeof(buf), bash_state);
  65. bashHashStepG(hash, l / 4, bash_state);
  66. ticks = tmTicks() - ticks;
  67. printf("bashBench::bash%u: %3u cpb [%5u kBytes/sec]\n",
  68. (unsigned)(2 * l),
  69. (unsigned)(ticks / sizeof(buf) / reps),
  70. (unsigned)tmSpeed(reps, ticks));
  71. }
  72. // эксперимент с bash-prg-hashLLLD
  73. for (l = 128; l <= 256; l += 64)
  74. for (d = 1; d <= 2; ++d)
  75. {
  76. bashPrgStart(bash_state, l, d, hash, l / 8, 0, 0);
  77. bashPrgAbsorbStart(bash_state);
  78. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  79. bashPrgAbsorbStep(buf, 1024, bash_state);
  80. bashPrgSqueeze(hash, l / 4, bash_state);
  81. ticks = tmTicks() - ticks;
  82. printf("bashBench::bash-prg-hash%u%u: %3u cpb [%5u kBytes/sec]\n",
  83. (unsigned)(2 * l), (unsigned)d,
  84. (unsigned)(ticks / sizeof(buf) / reps),
  85. (unsigned)tmSpeed(reps, ticks));
  86. }
  87. // эксперимент с bash-prg-aeLLLD
  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. }