ut.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. #include <library/cpp/digest/argonish/argon2.h>
  2. #include <library/cpp/digest/argonish/blake2b.h>
  3. #include <library/cpp/testing/unittest/registar.h>
  4. Y_UNIT_TEST_SUITE(ArgonishTest) {
  5. const ui8 GenKatPassword[32] = {
  6. 0x01,
  7. 0x01,
  8. 0x01,
  9. 0x01,
  10. 0x01,
  11. 0x01,
  12. 0x01,
  13. 0x01,
  14. 0x01,
  15. 0x01,
  16. 0x01,
  17. 0x01,
  18. 0x01,
  19. 0x01,
  20. 0x01,
  21. 0x01,
  22. 0x01,
  23. 0x01,
  24. 0x01,
  25. 0x01,
  26. 0x01,
  27. 0x01,
  28. 0x01,
  29. 0x01,
  30. 0x01,
  31. 0x01,
  32. 0x01,
  33. 0x01,
  34. 0x01,
  35. 0x01,
  36. 0x01,
  37. 0x01,
  38. };
  39. const ui8 GenKatSalt[16] = {
  40. 0x02,
  41. 0x02,
  42. 0x02,
  43. 0x02,
  44. 0x02,
  45. 0x02,
  46. 0x02,
  47. 0x02,
  48. 0x02,
  49. 0x02,
  50. 0x02,
  51. 0x02,
  52. 0x02,
  53. 0x02,
  54. 0x02,
  55. 0x02,
  56. };
  57. const ui8 GenKatSecret[8] = {
  58. 0x03,
  59. 0x03,
  60. 0x03,
  61. 0x03,
  62. 0x03,
  63. 0x03,
  64. 0x03,
  65. 0x03,
  66. };
  67. const ui8 FrPassword[13] = {
  68. 'm',
  69. 'e',
  70. 'g',
  71. 'a',
  72. '_',
  73. 'p',
  74. 'a',
  75. 's',
  76. 's',
  77. 'w',
  78. 'o',
  79. 'r',
  80. 'd',
  81. };
  82. const ui8 FrSecret[16] = {
  83. 'm',
  84. 'e',
  85. 'g',
  86. 'a',
  87. '_',
  88. 's',
  89. 'e',
  90. 'c',
  91. 'r',
  92. 'e',
  93. 't',
  94. '_',
  95. 'k',
  96. 'e',
  97. 'y',
  98. '2',
  99. };
  100. const ui8 FrSalt[9] = {
  101. 'm',
  102. 'e',
  103. 'g',
  104. 'a',
  105. '_',
  106. 's',
  107. 'a',
  108. 'l',
  109. 't',
  110. };
  111. const ui8 GenKatAAD[12] = {
  112. 0x04,
  113. 0x04,
  114. 0x04,
  115. 0x04,
  116. 0x04,
  117. 0x04,
  118. 0x04,
  119. 0x04,
  120. 0x04,
  121. 0x04,
  122. 0x04,
  123. 0x04,
  124. };
  125. Y_UNIT_TEST(Argon2_Fr_Test) {
  126. const ui32 mcost = 16;
  127. const ui32 tcost = 1;
  128. TArrayHolder<ui8> memory(new ui8[mcost * 1024]);
  129. const ui8 TResult[165] = {
  130. 0xe6, 0xff, 0x7b, 0xa1, 0xfa, 0x93, 0x0a, 0x51,
  131. 0x24, 0xf3, 0xbc, 0xc4, 0x98, 0xe2, 0x32, 0x08,
  132. 0x22, 0x7d, 0x4d, 0xf9, 0xe7, 0x2c, 0xd2, 0xd8,
  133. 0x21, 0x6b, 0x3f, 0xf3, 0xfc, 0x3d, 0xa2, 0x79,
  134. 0xb8, 0xdb, 0xfe, 0xfc, 0x18, 0xfa, 0x33, 0x08,
  135. 0x45, 0x03, 0x5f, 0x21, 0x0d, 0xaa, 0x05, 0x5f,
  136. 0x57, 0x6f, 0xc5, 0x4c, 0xba, 0xe7, 0xcd, 0xcf,
  137. 0x8e, 0xc3, 0xc1, 0xab, 0x40, 0xea, 0x18, 0xca,
  138. 0xe4, 0xa1, 0x08, 0x23, 0x54, 0x8d, 0xc0, 0x39,
  139. 0x2c, 0xdd, 0x7e, 0x1f, 0x06, 0x6a, 0x2c, 0x25,
  140. 0xe3, 0x7b, 0xbd, 0x45, 0xa3, 0xd8, 0xeb, 0x4c,
  141. 0x44, 0xc3, 0x00, 0x52, 0x84, 0x35, 0x6c, 0x48,
  142. 0xb2, 0xbc, 0x43, 0xd6, 0x58, 0xa9, 0x85, 0x78,
  143. 0xe0, 0x2a, 0x6c, 0x0b, 0x42, 0x9a, 0x60, 0x62,
  144. 0xc8, 0xe8, 0x62, 0x5d, 0xab, 0x3c, 0xfc, 0xba,
  145. 0xe2, 0x84, 0x11, 0xda, 0x68, 0x79, 0x36, 0x13,
  146. 0x84, 0x78, 0x6f, 0x47, 0x6a, 0x01, 0xd9, 0x94,
  147. 0x8c, 0x6a, 0x81, 0xdc, 0x59, 0x82, 0xcd, 0x99,
  148. 0x9b, 0x0a, 0x11, 0x8f, 0x1c, 0x09, 0x25, 0x2f,
  149. 0x07, 0xf4, 0x50, 0xf9, 0x3f, 0xd7, 0xe7, 0x7b,
  150. 0x0c, 0xc9, 0xe4, 0xc8, 0xe9};
  151. try {
  152. NArgonish::TArgon2Factory factory;
  153. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  154. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  155. auto argon2d = factory.Create((NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d, tcost, mcost, 1,
  156. FrSecret, sizeof(FrSecret));
  157. ui8 hashResult[sizeof(TResult)];
  158. argon2d->HashWithCustomMemory(memory.Get(), mcost * 1024, FrPassword, sizeof(FrPassword),
  159. FrSalt, sizeof(FrSalt), hashResult, sizeof(hashResult));
  160. UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(hashResult)) == 0);
  161. UNIT_ASSERT(argon2d->VerifyWithCustomMemory(memory.Get(), mcost * 1024, FrPassword, sizeof(FrPassword),
  162. FrSalt, sizeof(FrSalt), TResult, sizeof(TResult)));
  163. }
  164. } catch (...) {
  165. UNIT_FAIL("Argon2 fraction len test fail");
  166. }
  167. }
  168. Y_UNIT_TEST(Argon2_Factory_SelfTest) {
  169. try {
  170. NArgonish::TArgon2Factory factory;
  171. factory.GetInstructionSet();
  172. } catch (...) {
  173. UNIT_FAIL("Argon2 factory self-test fail");
  174. }
  175. }
  176. Y_UNIT_TEST(Blake2B_Factory_SelfTest) {
  177. try {
  178. NArgonish::TBlake2BFactory factory;
  179. factory.GetInstructionSet();
  180. } catch (...) {
  181. UNIT_FAIL("Blake2B factory self-test fail");
  182. }
  183. }
  184. Y_UNIT_TEST(Argon2d) {
  185. const ui8 TResult[32] = {
  186. 0x7b, 0xa5, 0xa1, 0x7a, 0x72, 0xf7, 0xe5, 0x99,
  187. 0x77, 0xf7, 0xf2, 0x3d, 0x10, 0xe6, 0x21, 0x89,
  188. 0x8c, 0x63, 0xce, 0xbe, 0xed, 0xda, 0xbd, 0x15,
  189. 0xd8, 0xc6, 0x8f, 0x53, 0xea, 0xb2, 0x1a, 0x32};
  190. NArgonish::TArgon2Factory factory;
  191. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  192. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  193. ui8 result[32];
  194. auto argon2d = factory.Create(
  195. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
  196. 1, 32, 1, GenKatSecret, sizeof(GenKatSecret));
  197. argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  198. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  199. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  200. UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword),
  201. GenKatSalt, sizeof(GenKatSalt),
  202. TResult, sizeof(TResult),
  203. GenKatAAD, sizeof(GenKatAAD)));
  204. }
  205. }
  206. Y_UNIT_TEST(Argon2i) {
  207. const ui8 TResult[32] = {
  208. 0x87, 0x4d, 0x23, 0xfb, 0x9f, 0x55, 0xe2, 0xff,
  209. 0x66, 0xbc, 0x19, 0x03, 0x46, 0xe7, 0x01, 0x19,
  210. 0x7c, 0x9f, 0x25, 0xd1, 0x1d, 0xa4, 0x5a, 0xad,
  211. 0x0d, 0x5d, 0x24, 0x19, 0x8a, 0xac, 0xd2, 0xbb};
  212. NArgonish::TArgon2Factory factory;
  213. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  214. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  215. ui8 result[32];
  216. auto argon2i = factory.Create(
  217. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2i,
  218. 1, 32, 1, GenKatSecret, sizeof(GenKatSecret));
  219. argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  220. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  221. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  222. UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword),
  223. GenKatSalt, sizeof(GenKatSalt),
  224. TResult, sizeof(TResult),
  225. GenKatAAD, sizeof(GenKatAAD)));
  226. }
  227. }
  228. Y_UNIT_TEST(Argon2id) {
  229. const ui8 TResult[32] = {
  230. 0x99, 0xdf, 0xcf, 0xc2, 0x89, 0x76, 0x93, 0x9d,
  231. 0xa2, 0x97, 0x09, 0x44, 0x34, 0xd8, 0x6f, 0xd0,
  232. 0x0c, 0x94, 0x9a, 0x0f, 0x31, 0x8c, 0x22, 0xf0,
  233. 0xcb, 0xb4, 0x69, 0xaa, 0xa8, 0x72, 0x18, 0xba};
  234. NArgonish::TArgon2Factory factory;
  235. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  236. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  237. ui8 result[32];
  238. auto argon2id = factory.Create(
  239. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2id,
  240. 1, 32, 1, GenKatSecret, sizeof(GenKatSecret));
  241. argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  242. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  243. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  244. UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword),
  245. GenKatSalt, sizeof(GenKatSalt),
  246. TResult, sizeof(TResult),
  247. GenKatAAD, sizeof(GenKatAAD)));
  248. }
  249. }
  250. Y_UNIT_TEST(Argon2d_2p) {
  251. const ui8 TResult[32] = {
  252. 0x59, 0xb0, 0x94, 0x62, 0xcf, 0xdc, 0xd2, 0xb4,
  253. 0x0a, 0xbd, 0x17, 0x81, 0x0a, 0x47, 0x4a, 0x8e,
  254. 0xc1, 0xab, 0xb7, 0xc1, 0x8d, 0x07, 0x53, 0x7c,
  255. 0xb9, 0x64, 0xa2, 0x59, 0x3f, 0xe9, 0xd9, 0xc5};
  256. NArgonish::TArgon2Factory factory;
  257. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  258. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  259. ui8 result[32];
  260. auto argon2d = factory.Create(
  261. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
  262. 2, 32, 1, GenKatSecret, sizeof(GenKatSecret));
  263. argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  264. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  265. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  266. UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword),
  267. GenKatSalt, sizeof(GenKatSalt),
  268. TResult, sizeof(TResult),
  269. GenKatAAD, sizeof(GenKatAAD)));
  270. }
  271. }
  272. Y_UNIT_TEST(Argon2i_2p) {
  273. const ui8 TResult[32] = {
  274. 0xc1, 0x0f, 0x00, 0x5e, 0xf8, 0x78, 0xc8, 0x07,
  275. 0x0e, 0x2c, 0xc5, 0x2f, 0x57, 0x75, 0x25, 0xc9,
  276. 0x71, 0xc7, 0x30, 0xeb, 0x00, 0x64, 0x4a, 0x4e,
  277. 0x26, 0xd0, 0x6e, 0xad, 0x75, 0x46, 0xe0, 0x44};
  278. NArgonish::TArgon2Factory factory;
  279. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  280. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  281. ui8 result[32];
  282. auto argon2i = factory.Create(
  283. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2i,
  284. 2, 32, 1, GenKatSecret, sizeof(GenKatSecret));
  285. argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  286. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  287. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  288. UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword),
  289. GenKatSalt, sizeof(GenKatSalt),
  290. TResult, sizeof(TResult),
  291. GenKatAAD, sizeof(GenKatAAD)));
  292. }
  293. }
  294. Y_UNIT_TEST(Argon2id_2p) {
  295. const ui8 TResult[32] = {
  296. 0x6c, 0x00, 0xb7, 0xa9, 0x00, 0xe5, 0x00, 0x4c,
  297. 0x24, 0x46, 0x9e, 0xc1, 0xe7, 0xc0, 0x1a, 0x99,
  298. 0xb2, 0xb8, 0xf7, 0x73, 0x75, 0xd4, 0xec, 0xa7,
  299. 0xd8, 0x08, 0x42, 0x11, 0xd3, 0x23, 0x6b, 0x7a};
  300. NArgonish::TArgon2Factory factory;
  301. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  302. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  303. ui8 result[32];
  304. auto argon2id = factory.Create(
  305. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2id,
  306. 2, 32, 1, GenKatSecret, sizeof(GenKatSecret));
  307. argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  308. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  309. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  310. UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword),
  311. GenKatSalt, sizeof(GenKatSalt),
  312. TResult, sizeof(TResult),
  313. GenKatAAD, sizeof(GenKatAAD)));
  314. }
  315. }
  316. Y_UNIT_TEST(Argon2d_2p_2th) {
  317. const ui8 TResult[32] = {
  318. 0x2b, 0x47, 0x35, 0x39, 0x4a, 0x40, 0x3c, 0xc9,
  319. 0x05, 0xfb, 0x51, 0x25, 0x96, 0x68, 0x64, 0x43,
  320. 0x02, 0x16, 0x38, 0xa6, 0xc1, 0x58, 0xfc, 0x8d,
  321. 0xbf, 0x35, 0x73, 0x9a, 0xdb, 0x31, 0x0c, 0x60};
  322. NArgonish::TArgon2Factory factory;
  323. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  324. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  325. ui8 result[32];
  326. auto argon2d = factory.Create(
  327. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
  328. 2, 32, 2, GenKatSecret, sizeof(GenKatSecret));
  329. argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  330. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  331. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  332. UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword),
  333. GenKatSalt, sizeof(GenKatSalt),
  334. TResult, sizeof(TResult),
  335. GenKatAAD, sizeof(GenKatAAD)));
  336. }
  337. }
  338. Y_UNIT_TEST(Argon2id_2p_4th) {
  339. const ui8 TResult[32] = {
  340. 0x4f, 0x93, 0xb5, 0xad, 0x78, 0xa4, 0xa9, 0x49,
  341. 0xfb, 0xe3, 0x55, 0x96, 0xd5, 0xa0, 0xc2, 0xab,
  342. 0x6f, 0x52, 0x2d, 0x2d, 0x29, 0xbc, 0x98, 0x49,
  343. 0xca, 0x92, 0xaa, 0xae, 0xba, 0x05, 0x29, 0xd8};
  344. NArgonish::TArgon2Factory factory;
  345. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  346. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  347. ui8 result[32];
  348. auto argon2id = factory.Create(
  349. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2id,
  350. 2, 64, 4, GenKatSecret, sizeof(GenKatSecret));
  351. argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  352. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  353. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  354. UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword),
  355. GenKatSalt, sizeof(GenKatSalt),
  356. TResult, sizeof(TResult),
  357. GenKatAAD, sizeof(GenKatAAD)));
  358. }
  359. }
  360. Y_UNIT_TEST(Argon2d_2p_4th) {
  361. const ui8 TResult[32] = {
  362. 0x8f, 0xa2, 0x7c, 0xed, 0x28, 0x38, 0x79, 0x0f,
  363. 0xba, 0x5c, 0x11, 0x85, 0x1c, 0xdf, 0x90, 0x88,
  364. 0xb2, 0x18, 0x44, 0xd7, 0xf0, 0x4c, 0x97, 0xb2,
  365. 0xca, 0xaf, 0xe4, 0xdc, 0x61, 0x4c, 0xae, 0xb2};
  366. NArgonish::TArgon2Factory factory;
  367. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  368. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  369. ui8 result[32];
  370. auto argon2d = factory.Create(
  371. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
  372. 2, 64, 4, GenKatSecret, sizeof(GenKatSecret));
  373. argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  374. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  375. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  376. UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword),
  377. GenKatSalt, sizeof(GenKatSalt),
  378. TResult, sizeof(TResult),
  379. GenKatAAD, sizeof(GenKatAAD)));
  380. }
  381. }
  382. Y_UNIT_TEST(Argon2i_2p_4th) {
  383. const ui8 TResult[32] = {
  384. 0x61, 0x1c, 0x99, 0x3c, 0xb0, 0xb7, 0x23, 0x16,
  385. 0xbd, 0xa2, 0x6c, 0x4c, 0x2f, 0xe8, 0x2d, 0x39,
  386. 0x9c, 0x8f, 0x1c, 0xfd, 0x45, 0xd9, 0x58, 0xa9,
  387. 0xb4, 0x9c, 0x6c, 0x64, 0xaf, 0xf0, 0x79, 0x0b};
  388. NArgonish::TArgon2Factory factory;
  389. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  390. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  391. ui8 result[32];
  392. auto argon2i = factory.Create(
  393. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2i,
  394. 2, 64, 4, GenKatSecret, sizeof(GenKatSecret));
  395. argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  396. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  397. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  398. UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword),
  399. GenKatSalt, sizeof(GenKatSalt),
  400. TResult, sizeof(TResult),
  401. GenKatAAD, sizeof(GenKatAAD)));
  402. }
  403. }
  404. Y_UNIT_TEST(Argon2d_128) {
  405. const ui8 TResult[128] = {
  406. 0x4e, 0xc4, 0x6c, 0x4e, 0x8c, 0x32, 0x89, 0x65,
  407. 0xf9, 0x82, 0x2b, 0x00, 0x95, 0x00, 0x50, 0x0a,
  408. 0x72, 0x0d, 0xc5, 0x12, 0x8d, 0x6b, 0xbd, 0x84,
  409. 0x7a, 0xf0, 0x78, 0x5d, 0xa6, 0x14, 0xe3, 0xf1,
  410. 0xac, 0x07, 0x1c, 0xca, 0x12, 0x4d, 0x32, 0xa4,
  411. 0x24, 0x08, 0x5e, 0x07, 0x7c, 0x26, 0xb9, 0x1b,
  412. 0x5c, 0xc0, 0xff, 0xb8, 0x7a, 0x20, 0x00, 0xcb,
  413. 0x07, 0x2b, 0xb4, 0x4d, 0x7b, 0x5b, 0x79, 0x9e,
  414. 0xb4, 0x21, 0xcb, 0x63, 0xeb, 0x46, 0xd7, 0x79,
  415. 0x44, 0x9c, 0x9f, 0xee, 0xa4, 0x17, 0xb5, 0x01,
  416. 0x0f, 0x61, 0x7e, 0xd8, 0xec, 0x1b, 0xe3, 0x8b,
  417. 0x9a, 0x74, 0x17, 0x19, 0x9d, 0x80, 0xe9, 0x20,
  418. 0xd4, 0x84, 0xdd, 0x07, 0x40, 0xb2, 0x26, 0xdb,
  419. 0xf7, 0xbe, 0x79, 0x7f, 0x81, 0x59, 0x86, 0xf3,
  420. 0xe9, 0x34, 0xe4, 0x52, 0xcd, 0x33, 0xb9, 0xf8,
  421. 0x9e, 0x62, 0x65, 0x89, 0xbb, 0xce, 0x7d, 0x65};
  422. NArgonish::TArgon2Factory factory;
  423. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  424. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  425. ui8 result[128];
  426. auto argon2d = factory.Create(
  427. (NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
  428. 1, 32, 1, GenKatSecret, sizeof(GenKatSecret));
  429. argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
  430. result, sizeof(result), GenKatAAD, sizeof(GenKatAAD));
  431. UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0);
  432. UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword),
  433. GenKatSalt, sizeof(GenKatSalt),
  434. TResult, sizeof(TResult),
  435. GenKatAAD, sizeof(GenKatAAD)));
  436. }
  437. }
  438. Y_UNIT_TEST(Blake2B_16_ABC) {
  439. const ui8 TResult[16] = {
  440. 0xcf, 0x4a, 0xb7, 0x91, 0xc6, 0x2b, 0x8d, 0x2b,
  441. 0x21, 0x09, 0xc9, 0x02, 0x75, 0x28, 0x78, 0x16};
  442. const ui8 data[] = {'a', 'b', 'c'};
  443. NArgonish::TBlake2BFactory factory;
  444. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  445. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  446. auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult));
  447. ui8 hashResult[16] = {0};
  448. blake2b->Update(data, sizeof(data));
  449. blake2b->Final(hashResult, sizeof(hashResult));
  450. UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0);
  451. }
  452. }
  453. Y_UNIT_TEST(Blake2B_64_ABC) {
  454. const ui8 TResult[64] = {
  455. 0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d,
  456. 0x6a, 0x27, 0x97, 0xb6, 0x9f, 0x12, 0xf6, 0xe9,
  457. 0x4c, 0x21, 0x2f, 0x14, 0x68, 0x5a, 0xc4, 0xb7,
  458. 0x4b, 0x12, 0xbb, 0x6f, 0xdb, 0xff, 0xa2, 0xd1,
  459. 0x7d, 0x87, 0xc5, 0x39, 0x2a, 0xab, 0x79, 0x2d,
  460. 0xc2, 0x52, 0xd5, 0xde, 0x45, 0x33, 0xcc, 0x95,
  461. 0x18, 0xd3, 0x8a, 0xa8, 0xdb, 0xf1, 0x92, 0x5a,
  462. 0xb9, 0x23, 0x86, 0xed, 0xd4, 0x00, 0x99, 0x23};
  463. const ui8 data[] = {'a', 'b', 'c'};
  464. NArgonish::TBlake2BFactory factory;
  465. NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet();
  466. for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) {
  467. auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult));
  468. ui8 hashResult[64] = {0};
  469. blake2b->Update(data, sizeof(data));
  470. blake2b->Final(hashResult, sizeof(hashResult));
  471. UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0);
  472. }
  473. }
  474. }