mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-09 06:52:50 -04:00
SymmetricCipher: Add keySize(), don't rely on state for sizes
This additionally makes keySize() and blockSize() work before setting the key and IV. Required for SSH agent decryption.
This commit is contained in:
parent
a81a5fa31b
commit
248ae9d4ba
5 changed files with 28 additions and 11 deletions
|
@ -74,6 +74,11 @@ bool SymmetricCipher::reset()
|
||||||
return m_backend->reset();
|
return m_backend->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SymmetricCipher::keySize() const
|
||||||
|
{
|
||||||
|
return m_backend->keySize();
|
||||||
|
}
|
||||||
|
|
||||||
int SymmetricCipher::blockSize() const
|
int SymmetricCipher::blockSize() const
|
||||||
{
|
{
|
||||||
return m_backend->blockSize();
|
return m_backend->blockSize();
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reset();
|
bool reset();
|
||||||
|
int keySize() const;
|
||||||
int blockSize() const;
|
int blockSize() const;
|
||||||
QString errorString() const;
|
QString errorString() const;
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
Q_REQUIRED_RESULT virtual bool processInPlace(QByteArray& data, quint64 rounds) = 0;
|
Q_REQUIRED_RESULT virtual bool processInPlace(QByteArray& data, quint64 rounds) = 0;
|
||||||
|
|
||||||
virtual bool reset() = 0;
|
virtual bool reset() = 0;
|
||||||
|
virtual int keySize() const = 0;
|
||||||
virtual int blockSize() const = 0;
|
virtual int blockSize() const = 0;
|
||||||
|
|
||||||
virtual QString errorString() const = 0;
|
virtual QString errorString() const = 0;
|
||||||
|
|
|
@ -26,7 +26,6 @@ SymmetricCipherGcrypt::SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, Sy
|
||||||
, m_algo(gcryptAlgo(algo))
|
, m_algo(gcryptAlgo(algo))
|
||||||
, m_mode(gcryptMode(mode))
|
, m_mode(gcryptMode(mode))
|
||||||
, m_direction(direction)
|
, m_direction(direction)
|
||||||
, m_blockSize(-1)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +94,6 @@ bool SymmetricCipherGcrypt::init()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t blockSizeT;
|
|
||||||
error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_BLKLEN, nullptr, &blockSizeT);
|
|
||||||
if (error != 0) {
|
|
||||||
setErrorString(error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_blockSize = blockSizeT;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,9 +228,28 @@ bool SymmetricCipherGcrypt::reset()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SymmetricCipherGcrypt::keySize() const
|
||||||
|
{
|
||||||
|
gcry_error_t error;
|
||||||
|
size_t keySizeT;
|
||||||
|
|
||||||
|
error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_KEYLEN, nullptr, &keySizeT);
|
||||||
|
if (error != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return keySizeT;
|
||||||
|
}
|
||||||
|
|
||||||
int SymmetricCipherGcrypt::blockSize() const
|
int SymmetricCipherGcrypt::blockSize() const
|
||||||
{
|
{
|
||||||
return m_blockSize;
|
gcry_error_t error;
|
||||||
|
size_t blockSizeT;
|
||||||
|
|
||||||
|
error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_BLKLEN, nullptr, &blockSizeT);
|
||||||
|
if (error != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return blockSizeT;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SymmetricCipherGcrypt::errorString() const
|
QString SymmetricCipherGcrypt::errorString() const
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
Q_REQUIRED_RESULT bool processInPlace(QByteArray& data, quint64 rounds);
|
Q_REQUIRED_RESULT bool processInPlace(QByteArray& data, quint64 rounds);
|
||||||
|
|
||||||
bool reset();
|
bool reset();
|
||||||
|
int keySize() const;
|
||||||
int blockSize() const;
|
int blockSize() const;
|
||||||
|
|
||||||
QString errorString() const;
|
QString errorString() const;
|
||||||
|
@ -54,7 +55,6 @@ private:
|
||||||
const SymmetricCipher::Direction m_direction;
|
const SymmetricCipher::Direction m_direction;
|
||||||
QByteArray m_key;
|
QByteArray m_key;
|
||||||
QByteArray m_iv;
|
QByteArray m_iv;
|
||||||
int m_blockSize;
|
|
||||||
QString m_errorString;
|
QString m_errorString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue