mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-08 06:22:53 -04:00
SymmetricCipher: Support CTR mode
Includes AES-256-CTR non-stream tests
This commit is contained in:
parent
8625e2c051
commit
a81a5fa31b
4 changed files with 53 additions and 1 deletions
|
@ -38,6 +38,7 @@ public:
|
|||
enum Mode
|
||||
{
|
||||
Cbc,
|
||||
Ctr,
|
||||
Ecb,
|
||||
Stream
|
||||
};
|
||||
|
|
|
@ -62,6 +62,9 @@ int SymmetricCipherGcrypt::gcryptMode(SymmetricCipher::Mode mode)
|
|||
case SymmetricCipher::Cbc:
|
||||
return GCRY_CIPHER_MODE_CBC;
|
||||
|
||||
case SymmetricCipher::Ctr:
|
||||
return GCRY_CIPHER_MODE_CTR;
|
||||
|
||||
case SymmetricCipher::Stream:
|
||||
return GCRY_CIPHER_MODE_STREAM;
|
||||
|
||||
|
@ -119,7 +122,13 @@ bool SymmetricCipherGcrypt::setKey(const QByteArray& key)
|
|||
bool SymmetricCipherGcrypt::setIv(const QByteArray& iv)
|
||||
{
|
||||
m_iv = iv;
|
||||
gcry_error_t error = gcry_cipher_setiv(m_ctx, m_iv.constData(), m_iv.size());
|
||||
gcry_error_t error;
|
||||
|
||||
if (m_mode == GCRY_CIPHER_MODE_CTR) {
|
||||
error = gcry_cipher_setctr(m_ctx, m_iv.constData(), m_iv.size());
|
||||
} else {
|
||||
error = gcry_cipher_setiv(m_ctx, m_iv.constData(), m_iv.size());
|
||||
}
|
||||
|
||||
if (error != 0) {
|
||||
setErrorString(error);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue