@@ -52,7 +52,7 @@ template <template<class> class TScheme, class TCipher>
52
52
class StandardCipherScheme : public CryptoController::CipherScheme
53
53
{
54
54
public:
55
- typedef TScheme<TCipher> Scheme ;
55
+ using Scheme = TScheme<TCipher>;
56
56
57
57
QByteArray name () const override ;
58
58
quint32 defaultKeyLength () const override ;
@@ -130,7 +130,7 @@ QStringList CryptoController::allKeystoreKeys()
130
130
QStringList CryptoController::availableKeystoreKeys ()
131
131
{
132
132
QStringList keys;
133
- for (auto key : factory->allKeys ()) {
133
+ for (const auto & key : factory->allKeys ()) {
134
134
if (factory->isAvailable (key))
135
135
keys.append (key);
136
136
}
@@ -211,7 +211,7 @@ void CryptoController::acquireStore(bool existing)
211
211
logDebug () << " Created keystore instance of type" << provider;
212
212
}
213
213
214
- void CryptoController::loadKeyMaterial (const QUuid & deviceId)
214
+ void CryptoController::loadKeyMaterial (QUuid deviceId)
215
215
{
216
216
try {
217
217
ensureStoreOpen ();
@@ -259,7 +259,7 @@ void CryptoController::clearKeyMaterial()
259
259
emit fingerprintChanged (QByteArray ());
260
260
}
261
261
262
- void CryptoController::deleteKeyMaterial (const QUuid & deviceId)
262
+ void CryptoController::deleteKeyMaterial (QUuid deviceId)
263
263
{
264
264
// remove all saved keys
265
265
auto keyDir = keysDir ();
@@ -291,7 +291,8 @@ void CryptoController::createPrivateKeys(const QByteArray &nonce)
291
291
{
292
292
try {
293
293
if (_asymCrypto->rng ().CanIncorporateEntropy ())
294
- _asymCrypto->rng ().IncorporateEntropy (reinterpret_cast <const byte*>(nonce.constData ()), nonce.size ());
294
+ _asymCrypto->rng ().IncorporateEntropy (reinterpret_cast <const byte*>(nonce.constData ()),
295
+ static_cast <size_t >(nonce.size ()));
295
296
296
297
// generate private signature and encryption keys
297
298
_asymCrypto->generate (static_cast <Setup::SignatureScheme>(defaults ().property (Defaults::SignScheme).toInt ()),
@@ -315,7 +316,7 @@ void CryptoController::createPrivateKeys(const QByteArray &nonce)
315
316
}
316
317
}
317
318
318
- void CryptoController::storePrivateKeys (const QUuid & deviceId) const
319
+ void CryptoController::storePrivateKeys (QUuid deviceId) const
319
320
{
320
321
try {
321
322
ensureStoreOpen ();
@@ -364,8 +365,9 @@ tuple<quint32, QByteArray, QByteArray> CryptoController::encryptData(const QByte
364
365
{
365
366
try {
366
367
auto info = getInfo (_localCipher);
367
- QByteArray salt (info.scheme ->ivLength (), Qt::Uninitialized);
368
- _asymCrypto->rng ().GenerateBlock (reinterpret_cast <byte*>(salt.data ()), salt.size ());
368
+ QByteArray salt (static_cast <int >(info.scheme ->ivLength ()), Qt::Uninitialized);
369
+ _asymCrypto->rng ().GenerateBlock (reinterpret_cast <byte*>(salt.data ()),
370
+ static_cast <size_t >(salt.size ()));
369
371
370
372
auto cipher = encryptImpl (info, salt, plain);
371
373
@@ -457,7 +459,8 @@ void CryptoController::decryptSecretKey(quint32 keyIndex, const QByteArray &sche
457
459
458
460
CipherInfo info;
459
461
createScheme (scheme, info.scheme );
460
- info.key .Assign (reinterpret_cast <const byte*>(key.constData ()), key.size ());
462
+ info.key .Assign (reinterpret_cast <const byte*>(key.constData ()),
463
+ static_cast <size_t >(key.size ()));
461
464
462
465
_loadedChiphers.insert (keyIndex, info);
463
466
if (grantInit) {// only set key index. Storing is done a step later for granting
@@ -582,14 +585,18 @@ tuple<QByteArray, QByteArray, SecByteBlock> CryptoController::generateExportKey(
582
585
auto pw = password.toUtf8 ();
583
586
584
587
// create a salt
585
- salt.resize (info.scheme ->ivLength ());
586
- _asymCrypto->rng ().GenerateBlock (reinterpret_cast <byte*>(salt.data ()), salt.size ());
588
+ salt.resize (static_cast <int >(info.scheme ->ivLength ()));
589
+ _asymCrypto->rng ().GenerateBlock (reinterpret_cast <byte*>(salt.data ()),
590
+ static_cast <size_t >(salt.size ()));
587
591
588
592
// generate the key
589
593
PKCS5_PBKDF2_HMAC<SHA3_256> keydev;
590
594
keydev.DeriveKey (info.key .data (), info.key .size (),
591
- PwPurpose, reinterpret_cast <const byte*>(pw.constData ()), pw.size (),
592
- reinterpret_cast <const byte*>(salt.constData ()), salt.size (), PwRounds);
595
+ PwPurpose, reinterpret_cast <const byte*>(pw.constData ()),
596
+ static_cast <size_t >(pw.size ()),
597
+ reinterpret_cast <const byte*>(salt.constData ()),
598
+ static_cast <size_t >(salt.size ()),
599
+ PwRounds);
593
600
}
594
601
595
602
return make_tuple (info.scheme ->name (), salt, info.key );
@@ -613,8 +620,11 @@ SecByteBlock CryptoController::recoverExportKey(const QByteArray &scheme, const
613
620
// generate the key
614
621
PKCS5_PBKDF2_HMAC<SHA3_256> keydev;
615
622
keydev.DeriveKey (info.key .data (), info.key .size (),
616
- PwPurpose, reinterpret_cast <const byte*>(pw.constData ()), pw.size (),
617
- reinterpret_cast <const byte*>(salt.constData ()), salt.size (), PwRounds);
623
+ PwPurpose, reinterpret_cast <const byte*>(pw.constData ()),
624
+ static_cast <size_t >(pw.size ()),
625
+ reinterpret_cast <const byte*>(salt.constData ()),
626
+ static_cast <size_t >(salt.size ()),
627
+ PwRounds);
618
628
619
629
return info.key ;
620
630
} catch (CppException &e) {
@@ -662,7 +672,7 @@ void CryptoController::verifyImportCmac(const QByteArray &scheme, const SecByteB
662
672
CipherInfo info;
663
673
createScheme (scheme, info.scheme );
664
674
info.key = key;
665
- return verifyCmacImpl (info, data, mac);
675
+ verifyCmacImpl (info, data, mac);
666
676
} catch (CppException &e) {
667
677
throw CryptoException (defaults (),
668
678
QStringLiteral (" Failed to verify cmac for import data" ),
@@ -680,7 +690,7 @@ void CryptoController::verifyImportCmacForCrypto(const QByteArray &scheme, const
680
690
CipherInfo info;
681
691
createScheme (scheme, info.scheme );
682
692
info.key = key;
683
- return verifyCmacImpl (info, trustMessage, mac);
693
+ verifyCmacImpl (info, trustMessage, mac);
684
694
} catch (CppException &e) {
685
695
throw CryptoException (defaults (),
686
696
QStringLiteral (" Failed to verify cmac for crypto keys" ),
@@ -829,8 +839,9 @@ const CryptoController::CipherInfo &CryptoController::getInfo(quint32 keyIndex)
829
839
keyFile.close ();
830
840
831
841
auto key = _asymCrypto->decrypt (encData);
832
- info.key .Assign (reinterpret_cast <const byte*>(key.constData ()), key.size ());
833
- memset (key.data (), 0 , key.size ());
842
+ info.key .Assign (reinterpret_cast <const byte*>(key.constData ()),
843
+ static_cast <size_t >(key.size ()));
844
+ memset (key.data (), 0 , static_cast <size_t >(key.size ()));
834
845
835
846
// test if the key is of valid length
836
847
if (info.key .size () != info.scheme ->toKeyLength (static_cast <quint32>(info.key .size ())))
@@ -866,7 +877,7 @@ void CryptoController::cleanCiphers() const
866
877
auto keys = settings ()->childKeys ();
867
878
settings ()->endGroup ();
868
879
869
- for (auto key : keys) {
880
+ for (const auto & key : qAsConst ( keys) ) {
870
881
auto ok = false ;
871
882
auto keyIndex = key.toUInt (&ok);
872
883
if (!ok)
@@ -910,7 +921,8 @@ QByteArray CryptoController::encryptImpl(const CryptoController::CipherInfo &inf
910
921
{
911
922
auto enc = info.scheme ->encryptor ();
912
923
enc->SetKeyWithIV (info.key .data (), info.key .size (),
913
- reinterpret_cast <const byte*>(salt.constData ()), salt.size ());
924
+ reinterpret_cast <const byte*>(salt.constData ()),
925
+ static_cast <size_t >(salt.size ()));
914
926
915
927
QByteArray cipher;
916
928
QByteArraySource (plain, true ,
@@ -925,7 +937,8 @@ QByteArray CryptoController::decryptImpl(const CryptoController::CipherInfo &inf
925
937
{
926
938
auto dec = info.scheme ->decryptor ();
927
939
dec->SetKeyWithIV (info.key .data (), info.key .size (),
928
- reinterpret_cast <const byte*>(salt.constData ()), salt.size ());
940
+ reinterpret_cast <const byte*>(salt.constData ()),
941
+ static_cast <size_t >(salt.size ()));
929
942
930
943
QByteArray plain;
931
944
QByteArraySource (cipher, true ,
0 commit comments