2
2
#include < src/library/digest/argonish/blake2b.h>
3
3
#include < src/library/testing/unittest/registar.h>
4
4
5
+ #include < type_traits>
6
+
5
7
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
+
6
12
const ui8 GenKatPassword[32 ] = {
7
13
0x01 ,
8
14
0x01 ,
@@ -83,13 +89,13 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
83
89
0x04 ,
84
90
};
85
91
86
- constexpr NArgonish::EInstructionSet MaxArch =
92
+ constexpr auto MaxArch = ToUnderlying (
87
93
#if !defined(_arm64_)
88
94
NArgonish::EInstructionSet::AVX2
89
95
#else
90
96
NArgonish::EInstructionSet::REF
91
97
#endif
92
- ;
98
+ ) ;
93
99
94
100
Y_UNIT_TEST (Argon2_Factory_SelfTest) {
95
101
try {
@@ -107,10 +113,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
107
113
0xd8 , 0xc6 , 0x8f , 0x53 , 0xea , 0xb2 , 0x1a , 0x32 };
108
114
109
115
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) {
111
117
ui8 result[32 ];
112
118
auto argon2d = factory.Create (
113
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2d,
119
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2d,
114
120
1 , 32 , 1 , GenKatSecret, sizeof (GenKatSecret));
115
121
116
122
argon2d->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -133,10 +139,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
133
139
0x0d , 0x5d , 0x24 , 0x19 , 0x8a , 0xac , 0xd2 , 0xbb };
134
140
135
141
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) {
137
143
ui8 result[32 ];
138
144
auto argon2i = factory.Create (
139
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2i,
145
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2i,
140
146
1 , 32 , 1 , GenKatSecret, sizeof (GenKatSecret));
141
147
142
148
argon2i->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -159,10 +165,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
159
165
0xcb , 0xb4 , 0x69 , 0xaa , 0xa8 , 0x72 , 0x18 , 0xba };
160
166
161
167
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) {
163
169
ui8 result[32 ];
164
170
auto argon2id = factory.Create (
165
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2id,
171
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2id,
166
172
1 , 32 , 1 , GenKatSecret, sizeof (GenKatSecret));
167
173
168
174
argon2id->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -185,10 +191,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
185
191
0xb9 , 0x64 , 0xa2 , 0x59 , 0x3f , 0xe9 , 0xd9 , 0xc5 };
186
192
187
193
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) {
189
195
ui8 result[32 ];
190
196
auto argon2d = factory.Create (
191
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2d,
197
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2d,
192
198
2 , 32 , 1 , GenKatSecret, sizeof (GenKatSecret));
193
199
194
200
argon2d->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -211,10 +217,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
211
217
0x26 , 0xd0 , 0x6e , 0xad , 0x75 , 0x46 , 0xe0 , 0x44 };
212
218
213
219
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) {
215
221
ui8 result[32 ];
216
222
auto argon2i = factory.Create (
217
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2i,
223
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2i,
218
224
2 , 32 , 1 , GenKatSecret, sizeof (GenKatSecret));
219
225
220
226
argon2i->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -237,10 +243,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
237
243
0xd8 , 0x08 , 0x42 , 0x11 , 0xd3 , 0x23 , 0x6b , 0x7a };
238
244
239
245
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) {
241
247
ui8 result[32 ];
242
248
auto argon2id = factory.Create (
243
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2id,
249
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2id,
244
250
2 , 32 , 1 , GenKatSecret, sizeof (GenKatSecret));
245
251
246
252
argon2id->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -263,10 +269,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
263
269
0xbf , 0x35 , 0x73 , 0x9a , 0xdb , 0x31 , 0x0c , 0x60 };
264
270
265
271
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) {
267
273
ui8 result[32 ];
268
274
auto argon2d = factory.Create (
269
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2d,
275
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2d,
270
276
2 , 32 , 2 , GenKatSecret, sizeof (GenKatSecret));
271
277
272
278
argon2d->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -289,10 +295,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
289
295
0xca , 0x92 , 0xaa , 0xae , 0xba , 0x05 , 0x29 , 0xd8 };
290
296
291
297
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) {
293
299
ui8 result[32 ];
294
300
auto argon2id = factory.Create (
295
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2id,
301
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2id,
296
302
2 , 64 , 4 , GenKatSecret, sizeof (GenKatSecret));
297
303
298
304
argon2id->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -315,10 +321,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
315
321
0xca , 0xaf , 0xe4 , 0xdc , 0x61 , 0x4c , 0xae , 0xb2 };
316
322
317
323
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) {
319
325
ui8 result[32 ];
320
326
auto argon2d = factory.Create (
321
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2d,
327
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2d,
322
328
2 , 64 , 4 , GenKatSecret, sizeof (GenKatSecret));
323
329
324
330
argon2d->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -341,10 +347,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
341
347
0xb4 , 0x9c , 0x6c , 0x64 , 0xaf , 0xf0 , 0x79 , 0x0b };
342
348
343
349
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) {
345
351
ui8 result[32 ];
346
352
auto argon2i = factory.Create (
347
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2i,
353
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2i,
348
354
2 , 64 , 4 , GenKatSecret, sizeof (GenKatSecret));
349
355
350
356
argon2i->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -379,10 +385,10 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
379
385
0x9e , 0x62 , 0x65 , 0x89 , 0xbb , 0xce , 0x7d , 0x65 };
380
386
381
387
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) {
383
389
ui8 result[128 ];
384
390
auto argon2d = factory.Create (
385
- ( NArgonish::EInstructionSet)i , NArgonish::EArgon2Type::Argon2d,
391
+ static_cast < NArgonish::EInstructionSet>(i) , NArgonish::EArgon2Type::Argon2d,
386
392
1 , 32 , 1 , GenKatSecret, sizeof (GenKatSecret));
387
393
388
394
argon2d->Hash (GenKatPassword, sizeof (GenKatPassword), GenKatSalt, sizeof (GenKatSalt),
@@ -404,8 +410,8 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
404
410
const ui8 data[] = {' a' , ' b' , ' c' };
405
411
406
412
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));
409
415
ui8 hashResult[16 ] = {0 };
410
416
411
417
blake2b->Update (data, sizeof (data));
@@ -428,8 +434,8 @@ Y_UNIT_TEST_SUITE(ArgonishTest) {
428
434
const ui8 data[] = {' a' , ' b' , ' c' };
429
435
430
436
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));
433
439
ui8 hashResult[64 ] = {0 };
434
440
435
441
blake2b->Update (data, sizeof (data));
0 commit comments