belt_bench.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. *******************************************************************************
  3. \file belt_bench.c
  4. \brief Benchmarks for STB 34.101.31 (belt)
  5. \project bee2/test
  6. \created 2014.11.18
  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/belt.h>
  17. #include <bee2/math/pp.h>
  18. #include <bee2/math/ww.h>
  19. /*
  20. *******************************************************************************
  21. Замер производительности
  22. *******************************************************************************
  23. */
  24. bool_t beltBench()
  25. {
  26. const size_t reps = 5000;
  27. octet belt_state[512];
  28. octet combo_state[256];
  29. octet buf[1024];
  30. octet key[32];
  31. octet iv[16];
  32. octet hash[32];
  33. size_t i;
  34. tm_ticks_t ticks;
  35. // подготовить стек
  36. if (sizeof(combo_state) < prngCOMBO_keep() ||
  37. sizeof(belt_state) < utilMax(10,
  38. beltECB_keep(),
  39. beltCBC_keep(),
  40. beltCFB_keep(),
  41. beltCTR_keep(),
  42. beltMAC_keep(),
  43. beltDWP_keep(),
  44. beltCHE_keep(),
  45. beltHash_keep(),
  46. beltBDE_keep(),
  47. beltSDE_keep()))
  48. return FALSE;
  49. // псевдослучайная генерация объектов
  50. prngCOMBOStart(combo_state, utilNonce32());
  51. prngCOMBOStepR(buf, sizeof(buf), combo_state);
  52. prngCOMBOStepR(key, sizeof(key), combo_state);
  53. prngCOMBOStepR(iv, sizeof(iv), combo_state);
  54. // cкорость belt-ecb
  55. beltECBStart(belt_state, key, 32);
  56. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  57. beltECBStepE(buf, 1024, belt_state),
  58. beltECBStepD(buf, 1024, belt_state);
  59. ticks = tmTicks() - ticks;
  60. printf("beltBench::belt-ecb: %3u cpb [%5u kBytes/sec]\n",
  61. (unsigned)(ticks / 2048 / reps),
  62. (unsigned)tmSpeed(2 * reps, ticks));
  63. // cкорость belt-cbc
  64. beltCBCStart(belt_state, key, 32, iv);
  65. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  66. beltCBCStepE(buf, 1024, belt_state),
  67. beltCBCStepD(buf, 1024, belt_state);
  68. ticks = tmTicks() - ticks;
  69. printf("beltBench::belt-cbc: %3u cpb [%5u kBytes/sec]\n",
  70. (unsigned)(ticks / 2048 / reps),
  71. (unsigned)tmSpeed(2 * reps, ticks));
  72. // cкорость belt-cfb
  73. beltCFBStart(belt_state, key, 32, iv);
  74. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  75. beltCFBStepE(buf, 1024, belt_state),
  76. beltCFBStepD(buf, 1024, belt_state);
  77. ticks = tmTicks() - ticks;
  78. printf("beltBench::belt-cfb: %3u cpb [%5u kBytes/sec]\n",
  79. (unsigned)(ticks / 2048 / reps),
  80. (unsigned)tmSpeed(2 * reps, ticks));
  81. // cкорость belt-ctr
  82. beltCTRStart(belt_state, key, 32, iv);
  83. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  84. beltCTRStepE(buf, 1024, belt_state),
  85. beltCTRStepD(buf, 1024, belt_state);
  86. ticks = tmTicks() - ticks;
  87. printf("beltBench::belt-ctr: %3u cpb [%5u kBytes/sec]\n",
  88. (unsigned)(ticks / 2048 / reps),
  89. (unsigned)tmSpeed(2 * reps, ticks));
  90. // cкорость belt-mac
  91. beltMACStart(belt_state, key, 32);
  92. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  93. beltMACStepA(buf, 1024, belt_state);
  94. beltMACStepG(hash, belt_state);
  95. ticks = tmTicks() - ticks;
  96. printf("beltBench::belt-mac: %3u cpb [%5u kBytes/sec]\n",
  97. (unsigned)(ticks / 1024 / reps),
  98. (unsigned)tmSpeed(reps, ticks));
  99. // cкорость belt-dwp
  100. beltDWPStart(belt_state, key, 32, iv);
  101. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  102. beltDWPStepE(buf, 1024, belt_state),
  103. beltDWPStepA(buf, 1024, belt_state);
  104. beltDWPStepG(hash, belt_state);
  105. ticks = tmTicks() - ticks;
  106. printf("beltBench::belt-dwp: %3u cpb [%5u kBytes/sec]\n",
  107. (unsigned)(ticks / 1024 / reps),
  108. (unsigned)tmSpeed(reps, ticks));
  109. // cкорость belt-che
  110. beltCHEStart(belt_state, key, 32, iv);
  111. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  112. beltCHEStepE(buf, 1024, belt_state),
  113. beltCHEStepA(buf, 1024, belt_state);
  114. beltCHEStepG(hash, belt_state);
  115. ticks = tmTicks() - ticks;
  116. printf("beltBench::belt-che: %3u cpb [%5u kBytes/sec]\n",
  117. (unsigned)(ticks / 1024 / reps),
  118. (unsigned)tmSpeed(reps, ticks));
  119. // cкорость belt-hash
  120. beltHashStart(belt_state);
  121. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  122. beltHashStepH(buf, 1024, belt_state);
  123. beltHashStepG(hash, belt_state);
  124. ticks = tmTicks() - ticks;
  125. printf("beltBench::belt-hash: %3u cpb [%5u kBytes/sec]\n",
  126. (unsigned)(ticks / 1024 / reps),
  127. (unsigned)tmSpeed(reps, ticks));
  128. // cкорость belt-bde
  129. beltBDEStart(belt_state, key, 32, iv);
  130. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  131. beltBDEStepE(buf, 1024, belt_state),
  132. beltBDEStepD(buf, 1024, belt_state);
  133. ticks = tmTicks() - ticks;
  134. printf("beltBench::belt-bde: %3u cpb [%5u kBytes/sec]\n",
  135. (unsigned)(ticks / 2048 / reps),
  136. (unsigned)tmSpeed(2 * reps, ticks));
  137. // cкорость belt-sde
  138. beltSDEStart(belt_state, key, 32);
  139. for (i = 0, ticks = tmTicks(); i < reps; ++i)
  140. beltSDEStepE(buf, 1024, iv, belt_state),
  141. beltSDEStepD(buf, 1024, iv, belt_state);
  142. ticks = tmTicks() - ticks;
  143. printf("beltBench::belt-sde: %3u cpb [%5u kBytes/sec]\n",
  144. (unsigned)(ticks / 2048 / reps),
  145. (unsigned)tmSpeed(2 * reps, ticks));
  146. // все нормально
  147. return TRUE;
  148. }