@@ -265,13 +265,13 @@ bool ValidateSHAKE_XOF()
265
265
266
266
StringSource (msg, true , new HexDecoder (new StringSink (m)));
267
267
StringSource (out, true , new HexDecoder (new StringSink (o)));
268
- r.reserve (o.size ());
268
+ r.resize (o.size ());
269
269
270
- SHAKE128 hash ((unsigned int )r .size ());
271
- hash.Update (( const byte*)&m[ 0 ], m. size ( ));
272
- hash.TruncatedFinal ((byte*)&o[ 0 ], o. size ( ));
270
+ SHAKE128 hash ((unsigned int )o .size ());
271
+ hash.Update (ConstBytePtr (m), BytePtrSize (m ));
272
+ hash.TruncatedFinal (BytePtr (r), BytePtrSize (r ));
273
273
274
- fail = (std::memcmp (r.data (), r .data (), o.size ()) != 0 );
274
+ fail = (std::memcmp (r.data (), o .data (), o.size ()) != 0 );
275
275
pass = pass & !fail;
276
276
277
277
if (fail)
@@ -292,13 +292,13 @@ bool ValidateSHAKE_XOF()
292
292
293
293
StringSource (msg, true , new HexDecoder (new StringSink (m)));
294
294
StringSource (out, true , new HexDecoder (new StringSink (o)));
295
- r.reserve (o.size ());
295
+ r.resize (o.size ());
296
296
297
- SHAKE128 hash ((unsigned int )r .size ());
298
- hash.Update (( const byte*)&m[ 0 ], m. size ( ));
299
- hash.TruncatedFinal ((byte*)&o[ 0 ], o. size ( ));
297
+ SHAKE128 hash ((unsigned int )o .size ());
298
+ hash.Update (ConstBytePtr (m), BytePtrSize (m ));
299
+ hash.TruncatedFinal (BytePtr (r), BytePtrSize (r ));
300
300
301
- fail = (std::memcmp (r.data (), r .data (), o.size ()) != 0 );
301
+ fail = (std::memcmp (r.data (), o .data (), o.size ()) != 0 );
302
302
pass = pass & !fail;
303
303
304
304
if (fail)
@@ -317,13 +317,13 @@ bool ValidateSHAKE_XOF()
317
317
318
318
StringSource (msg, true , new HexDecoder (new StringSink (m)));
319
319
StringSource (out, true , new HexDecoder (new StringSink (o)));
320
- r.reserve (o.size ());
320
+ r.resize (o.size ());
321
321
322
- SHAKE256 hash ((unsigned int )r .size ());
323
- hash.Update (( const byte*)&m[ 0 ], m. size ( ));
324
- hash.TruncatedFinal ((byte*)&o[ 0 ], o. size ( ));
322
+ SHAKE256 hash ((unsigned int )o .size ());
323
+ hash.Update (ConstBytePtr (m), BytePtrSize (m ));
324
+ hash.TruncatedFinal (BytePtr (r), BytePtrSize (r ));
325
325
326
- fail = (std::memcmp (r.data (), r .data (), o.size ()) != 0 );
326
+ fail = (std::memcmp (r.data (), o .data (), o.size ()) != 0 );
327
327
pass = pass & !fail;
328
328
329
329
if (fail)
@@ -347,13 +347,13 @@ bool ValidateSHAKE_XOF()
347
347
348
348
StringSource (msg, true , new HexDecoder (new StringSink (m)));
349
349
StringSource (out, true , new HexDecoder (new StringSink (o)));
350
- r.reserve (o.size ());
350
+ r.resize (o.size ());
351
351
352
- SHAKE256 hash ((unsigned int )r .size ());
353
- hash.Update (( const byte*)&m[ 0 ], m. size ( ));
354
- hash.TruncatedFinal ((byte*)&o[ 0 ], o. size ( ));
352
+ SHAKE256 hash ((unsigned int )o .size ());
353
+ hash.Update (ConstBytePtr (m), BytePtrSize (m ));
354
+ hash.TruncatedFinal (BytePtr (r), BytePtrSize (r ));
355
355
356
- fail = (std::memcmp (r.data (), r .data (), o.size ()) != 0 );
356
+ fail = (std::memcmp (r.data (), o .data (), o.size ()) != 0 );
357
357
pass = pass & !fail;
358
358
359
359
if (fail)
@@ -362,7 +362,7 @@ bool ValidateSHAKE_XOF()
362
362
pass = pass && !fail;
363
363
}
364
364
365
- std::cout << (!pass ? " FAILED " : " passed " ) << " SHAKE XOF message digests" << std::endl;
365
+ std::cout << (!pass ? " FAILED " : " passed " ) << " SHAKE XOF message digests" << std::endl;
366
366
367
367
return pass;
368
368
}
@@ -729,11 +729,11 @@ bool TestPBKDF(KeyDerivationFunction &pbkdf, const PBKDF_TestTuple *testSet, uns
729
729
730
730
double timeInSeconds = 0 .0f ;
731
731
AlgorithmParameters params = MakeParameters (" Purpose" , (int )tuple.purpose )
732
- (Name::Salt (), ConstByteArrayParameter (( const byte*)& salt[ 0 ], salt. size ( )))
732
+ (Name::Salt (), ConstByteArrayParameter (ConstBytePtr ( salt), BytePtrSize (salt )))
733
733
(" Iterations" , (int )tuple.iterations )(" TimeInSeconds" , timeInSeconds);
734
734
735
735
SecByteBlock derived (derivedKey.size ());
736
- pbkdf.DeriveKey (derived, derived.size (), ( const byte *) password. data ( ), password. size ( ), params);
736
+ pbkdf.DeriveKey (derived, derived.size (), ConstBytePtr ( password), BytePtrSize (password ), params);
737
737
bool fail = !!memcmp (derived, derivedKey.data (), derived.size ()) != 0 ;
738
738
pass = pass && !fail;
739
739
@@ -815,13 +815,13 @@ bool TestHKDF(KeyDerivationFunction &kdf, const HKDF_TestTuple *testSet, unsigne
815
815
816
816
AlgorithmParameters params;
817
817
if (tuple.hexSalt )
818
- params (Name::Salt (), ConstByteArrayParameter (( const byte*)& salt[ 0 ], salt. size ( )));
818
+ params (Name::Salt (), ConstByteArrayParameter (ConstBytePtr ( salt), BytePtrSize (salt )));
819
819
if (tuple.hexSalt )
820
- params (" Info" , ConstByteArrayParameter (( const byte*)& info[ 0 ], info. size ( )));
820
+ params (" Info" , ConstByteArrayParameter (ConstBytePtr ( info), BytePtrSize (info )));
821
821
822
- kdf.DeriveKey ((byte*)& derived[ 0 ] , derived.size (), ( const byte*)& secret[ 0 ], secret. size ( ), params);
822
+ kdf.DeriveKey (derived, derived.size (), ConstBytePtr ( secret), BytePtrSize (secret ), params);
823
823
824
- bool fail = !VerifyBufsEqual (derived, ( const byte*)& expected[ 0 ], derived. size ( ));
824
+ bool fail = !VerifyBufsEqual (derived, ConstBytePtr ( expected), BytePtrSize (expected ));
825
825
pass = pass && !fail;
826
826
827
827
HexEncoder enc (new FileSink (std::cout));
@@ -946,10 +946,10 @@ bool TestScrypt(KeyDerivationFunction &pbkdf, const Scrypt_TestTuple *testSet, u
946
946
947
947
AlgorithmParameters params = MakeParameters (" Cost" , (word64)tuple.n )
948
948
(" BlockSize" , (word64)tuple.r )(" Parallelization" , (word64)tuple.p )
949
- (Name::Salt (), ConstByteArrayParameter (( const byte*)& salt[ 0 ], salt. size ( )));
949
+ (Name::Salt (), ConstByteArrayParameter (ConstBytePtr ( salt), BytePtrSize (salt )));
950
950
951
951
SecByteBlock derived (expect.size ());
952
- pbkdf.DeriveKey (derived, derived.size (), ( const byte *) password. data ( ), password. size ( ), params);
952
+ pbkdf.DeriveKey (derived, derived.size (), ConstBytePtr ( password), BytePtrSize (password ), params);
953
953
bool fail = !!memcmp (derived, expect.data (), expect.size ()) != 0 ;
954
954
pass = pass && !fail;
955
955
0 commit comments