mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-26 01:11:16 -05:00
Add reset() and blockSize().
This commit is contained in:
parent
26de957a98
commit
bb6ae3a014
@ -43,7 +43,8 @@ CryptoHash::CryptoHash(CryptoHash::Algorithm algo)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
gcry_md_open(&d->ctx, algoGcrypt, 0); // TODO error handling
|
gcry_error_t error = gcry_md_open(&d->ctx, algoGcrypt, 0);
|
||||||
|
Q_ASSERT(error == 0); // TODO error handling
|
||||||
|
|
||||||
d->hashLen = gcry_md_get_algo_dlen(algoGcrypt);
|
d->hashLen = gcry_md_get_algo_dlen(algoGcrypt);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ public:
|
|||||||
gcry_cipher_hd_t ctx;
|
gcry_cipher_hd_t ctx;
|
||||||
SymmetricCipher::Direction direction;
|
SymmetricCipher::Direction direction;
|
||||||
QByteArray key;
|
QByteArray key;
|
||||||
|
QByteArray iv;
|
||||||
|
int blockSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
|
SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
|
||||||
@ -35,6 +37,7 @@ SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCiphe
|
|||||||
|
|
||||||
d->direction = direction;
|
d->direction = direction;
|
||||||
d->key = key;
|
d->key = key;
|
||||||
|
d->iv = iv;
|
||||||
|
|
||||||
int algoGcrypt;
|
int algoGcrypt;
|
||||||
|
|
||||||
@ -68,10 +71,15 @@ SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCiphe
|
|||||||
|
|
||||||
error = gcry_cipher_open(&d->ctx, algoGcrypt, modeGcrypt, 0);
|
error = gcry_cipher_open(&d->ctx, algoGcrypt, modeGcrypt, 0);
|
||||||
Q_ASSERT(error == 0); // TODO real error checking
|
Q_ASSERT(error == 0); // TODO real error checking
|
||||||
error = gcry_cipher_setkey(d->ctx, d->key.constData(), d->key.size()); // TODO is key copied to gcrypt data structure?
|
error = gcry_cipher_setkey(d->ctx, d->key.constData(), d->key.size());
|
||||||
Q_ASSERT(error == 0);
|
Q_ASSERT(error == 0);
|
||||||
error = gcry_cipher_setiv(d->ctx, iv.constData(), iv.size());
|
error = gcry_cipher_setiv(d->ctx, d->iv.constData(), d->iv.size());
|
||||||
Q_ASSERT(error == 0);
|
Q_ASSERT(error == 0);
|
||||||
|
|
||||||
|
size_t blockSizeT;
|
||||||
|
error = gcry_cipher_algo_info(algoGcrypt, GCRYCTL_GET_BLKLEN, 0, &blockSizeT);
|
||||||
|
Q_ASSERT(error == 0);
|
||||||
|
d->blockSize = blockSizeT;
|
||||||
}
|
}
|
||||||
|
|
||||||
SymmetricCipher::~SymmetricCipher()
|
SymmetricCipher::~SymmetricCipher()
|
||||||
@ -123,3 +131,22 @@ void SymmetricCipher::processInPlace(QByteArray& data)
|
|||||||
|
|
||||||
Q_ASSERT(error == 0);
|
Q_ASSERT(error == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SymmetricCipher::reset()
|
||||||
|
{
|
||||||
|
Q_D(SymmetricCipher);
|
||||||
|
|
||||||
|
gcry_error_t error;
|
||||||
|
|
||||||
|
error = gcry_cipher_reset(d->ctx);
|
||||||
|
Q_ASSERT(error == 0);
|
||||||
|
error = gcry_cipher_setiv(d->ctx, d->iv.constData(), d->iv.size());
|
||||||
|
Q_ASSERT(error == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int SymmetricCipher::blockSize() const
|
||||||
|
{
|
||||||
|
Q_D(const SymmetricCipher);
|
||||||
|
|
||||||
|
return d->blockSize;
|
||||||
|
}
|
||||||
|
@ -45,9 +45,13 @@ public:
|
|||||||
SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
|
SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
|
||||||
SymmetricCipher::Direction direction, const QByteArray& key, const QByteArray& iv);
|
SymmetricCipher::Direction direction, const QByteArray& key, const QByteArray& iv);
|
||||||
~SymmetricCipher();
|
~SymmetricCipher();
|
||||||
|
|
||||||
QByteArray process(const QByteArray& data);
|
QByteArray process(const QByteArray& data);
|
||||||
void processInPlace(QByteArray& data);
|
void processInPlace(QByteArray& data);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
int blockSize() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SymmetricCipherPrivate* const d_ptr;
|
SymmetricCipherPrivate* const d_ptr;
|
||||||
Q_DECLARE_PRIVATE(SymmetricCipher);
|
Q_DECLARE_PRIVATE(SymmetricCipher);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user