Skip to content

Commit abe02a8

Browse files
authored
Issue #179 Fix src/library/digest/argonish tests (#246)
1 parent 131bf52 commit abe02a8

File tree

6 files changed

+101
-101
lines changed

6 files changed

+101
-101
lines changed

src/library/digest/argonish/ut/ya.make

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/library/digest/argonish/ut_fat/ya.make

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/library/digest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
add_subdirectory(argonish)
12
add_subdirectory(lower_case)
23
add_subdirectory(md5)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_ydb_test(NAME library-digest-argonish-ut
2+
SOURCES
3+
ut.cpp
4+
LINK_LIBRARIES
5+
cpp-digest-argonish
6+
cpp-testing-unittest_main
7+
)
8+
9+
add_ydb_test(NAME library-digest-argonish-fat_ut
10+
SOURCES
11+
fat_ut.cpp
12+
LINK_LIBRARIES
13+
cpp-digest-argonish
14+
cpp-testing-unittest_main
15+
)

src/library/digest/argonish/ut_fat/ut.cpp renamed to tests/library/digest/argonish/fat_ut.cpp

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
#include <src/library/digest/argonish/blake2b.h>
33
#include <src/library/testing/unittest/registar.h>
44

5+
#include <type_traits>
6+
57
Y_UNIT_TEST_SUITE(ArgonishTest) {
8+
constexpr auto ToUnderlying(NArgonish::EInstructionSet e) noexcept {
9+
return static_cast<std::underlying_type_t<NArgonish::EInstructionSet>>(e);
10+
}
11+
612
const ui8 GenKatPassword[32] = {
713
0x01,
814
0x01,
@@ -83,13 +89,13 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
8389
0x04,
8490
};
8591

86-
constexpr NArgonish::EInstructionSet MaxArch =
92+
constexpr auto MaxArch = ToUnderlying(
8793
#if !defined(_arm64_)
8894
NArgonish::EInstructionSet::AVX2
8995
#else
9096
NArgonish::EInstructionSet::REF
9197
#endif
92-
;
98+
);
9399

94100
Y_UNIT_TEST(Argon2_Factory_SelfTest) {
95101
try {
@@ -107,10 +113,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
107113
0xd8, 0xc6, 0x8f, 0x53, 0xea, 0xb2, 0x1a, 0x32};
108114

109115
NArgonish::TArgon2Factory factory;
110-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
116+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
111117
ui8 result[32];
112118
auto argon2d = factory.Create(
113-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
119+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2d,
114120
1, 32, 1, GenKatSecret, sizeof(GenKatSecret));
115121

116122
argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -133,10 +139,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
133139
0x0d, 0x5d, 0x24, 0x19, 0x8a, 0xac, 0xd2, 0xbb};
134140

135141
NArgonish::TArgon2Factory factory;
136-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
142+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
137143
ui8 result[32];
138144
auto argon2i = factory.Create(
139-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2i,
145+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2i,
140146
1, 32, 1, GenKatSecret, sizeof(GenKatSecret));
141147

142148
argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -159,10 +165,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
159165
0xcb, 0xb4, 0x69, 0xaa, 0xa8, 0x72, 0x18, 0xba};
160166

161167
NArgonish::TArgon2Factory factory;
162-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
168+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
163169
ui8 result[32];
164170
auto argon2id = factory.Create(
165-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2id,
171+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2id,
166172
1, 32, 1, GenKatSecret, sizeof(GenKatSecret));
167173

168174
argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -185,10 +191,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
185191
0xb9, 0x64, 0xa2, 0x59, 0x3f, 0xe9, 0xd9, 0xc5};
186192

187193
NArgonish::TArgon2Factory factory;
188-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
194+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
189195
ui8 result[32];
190196
auto argon2d = factory.Create(
191-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
197+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2d,
192198
2, 32, 1, GenKatSecret, sizeof(GenKatSecret));
193199

194200
argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -211,10 +217,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
211217
0x26, 0xd0, 0x6e, 0xad, 0x75, 0x46, 0xe0, 0x44};
212218

213219
NArgonish::TArgon2Factory factory;
214-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
220+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
215221
ui8 result[32];
216222
auto argon2i = factory.Create(
217-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2i,
223+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2i,
218224
2, 32, 1, GenKatSecret, sizeof(GenKatSecret));
219225

220226
argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -237,10 +243,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
237243
0xd8, 0x08, 0x42, 0x11, 0xd3, 0x23, 0x6b, 0x7a};
238244

239245
NArgonish::TArgon2Factory factory;
240-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
246+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
241247
ui8 result[32];
242248
auto argon2id = factory.Create(
243-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2id,
249+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2id,
244250
2, 32, 1, GenKatSecret, sizeof(GenKatSecret));
245251

246252
argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -263,10 +269,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
263269
0xbf, 0x35, 0x73, 0x9a, 0xdb, 0x31, 0x0c, 0x60};
264270

265271
NArgonish::TArgon2Factory factory;
266-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
272+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
267273
ui8 result[32];
268274
auto argon2d = factory.Create(
269-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
275+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2d,
270276
2, 32, 2, GenKatSecret, sizeof(GenKatSecret));
271277

272278
argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -289,10 +295,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
289295
0xca, 0x92, 0xaa, 0xae, 0xba, 0x05, 0x29, 0xd8};
290296

291297
NArgonish::TArgon2Factory factory;
292-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
298+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
293299
ui8 result[32];
294300
auto argon2id = factory.Create(
295-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2id,
301+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2id,
296302
2, 64, 4, GenKatSecret, sizeof(GenKatSecret));
297303

298304
argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -315,10 +321,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
315321
0xca, 0xaf, 0xe4, 0xdc, 0x61, 0x4c, 0xae, 0xb2};
316322

317323
NArgonish::TArgon2Factory factory;
318-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
324+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
319325
ui8 result[32];
320326
auto argon2d = factory.Create(
321-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
327+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2d,
322328
2, 64, 4, GenKatSecret, sizeof(GenKatSecret));
323329

324330
argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -341,10 +347,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
341347
0xb4, 0x9c, 0x6c, 0x64, 0xaf, 0xf0, 0x79, 0x0b};
342348

343349
NArgonish::TArgon2Factory factory;
344-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
350+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
345351
ui8 result[32];
346352
auto argon2i = factory.Create(
347-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2i,
353+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2i,
348354
2, 64, 4, GenKatSecret, sizeof(GenKatSecret));
349355

350356
argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -379,10 +385,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
379385
0x9e, 0x62, 0x65, 0x89, 0xbb, 0xce, 0x7d, 0x65};
380386

381387
NArgonish::TArgon2Factory factory;
382-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
388+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
383389
ui8 result[128];
384390
auto argon2d = factory.Create(
385-
(NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d,
391+
static_cast<NArgonish::EInstructionSet>(i), NArgonish::EArgon2Type::Argon2d,
386392
1, 32, 1, GenKatSecret, sizeof(GenKatSecret));
387393

388394
argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt),
@@ -404,8 +410,8 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
404410
const ui8 data[] = {'a', 'b', 'c'};
405411

406412
NArgonish::TBlake2BFactory factory;
407-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) {
408-
auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult));
413+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
414+
auto blake2b = factory.Create(static_cast<NArgonish::EInstructionSet>(i), sizeof(TResult));
409415
ui8 hashResult[16] = {0};
410416

411417
blake2b->Update(data, sizeof(data));
@@ -428,8 +434,8 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
428434
const ui8 data[] = {'a', 'b', 'c'};
429435

430436
NArgonish::TBlake2BFactory factory;
431-
for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)(int)MaxArch; ++i) {
432-
auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult));
437+
for (auto i = ToUnderlying(NArgonish::EInstructionSet::REF); i <= MaxArch; ++i) {
438+
auto blake2b = factory.Create(static_cast<NArgonish::EInstructionSet>(i), sizeof(TResult));
433439
ui8 hashResult[64] = {0};
434440

435441
blake2b->Update(data, sizeof(data));

0 commit comments

Comments
 (0)