Adapt Salsa20 backend to the new interface.

This commit is contained in:
Felix Geyer 2015-05-09 21:10:52 +02:00
parent cfffdae573
commit e0d4b4b625
2 changed files with 29 additions and 6 deletions

View File

@ -33,23 +33,32 @@ SymmetricCipherSalsa20::~SymmetricCipherSalsa20()
{
}
void SymmetricCipherSalsa20::setKey(const QByteArray& key)
bool SymmetricCipherSalsa20::init()
{
return true;
}
bool SymmetricCipherSalsa20::setKey(const QByteArray& key)
{
Q_ASSERT((key.size() == 16) || (key.size() == 32));
m_key = key;
ECRYPT_keysetup(&m_ctx, reinterpret_cast<const u8*>(m_key.constData()), m_key.size()*8, 64);
return true;
}
void SymmetricCipherSalsa20::setIv(const QByteArray& iv)
bool SymmetricCipherSalsa20::setIv(const QByteArray& iv)
{
Q_ASSERT(iv.size() == 8);
m_iv = iv;
ECRYPT_ivsetup(&m_ctx, reinterpret_cast<const u8*>(m_iv.constData()));
return true;
}
QByteArray SymmetricCipherSalsa20::process(const QByteArray& data)
QByteArray SymmetricCipherSalsa20::process(const QByteArray& data, bool* ok)
{
Q_ASSERT((data.size() < blockSize()) || ((data.size() % blockSize()) == 0));
@ -59,18 +68,21 @@ QByteArray SymmetricCipherSalsa20::process(const QByteArray& data)
ECRYPT_encrypt_bytes(&m_ctx, reinterpret_cast<const u8*>(data.constData()),
reinterpret_cast<u8*>(result.data()), data.size());
*ok = true;
return result;
}
void SymmetricCipherSalsa20::processInPlace(QByteArray& data)
bool SymmetricCipherSalsa20::processInPlace(QByteArray& data)
{
Q_ASSERT((data.size() < blockSize()) || ((data.size() % blockSize()) == 0));
ECRYPT_encrypt_bytes(&m_ctx, reinterpret_cast<const u8*>(data.constData()),
reinterpret_cast<u8*>(data.data()), data.size());
return true;
}
void SymmetricCipherSalsa20::processInPlace(QByteArray& data, quint64 rounds)
bool SymmetricCipherSalsa20::processInPlace(QByteArray& data, quint64 rounds)
{
Q_ASSERT((data.size() < blockSize()) || ((data.size() % blockSize()) == 0));
@ -78,14 +90,23 @@ void SymmetricCipherSalsa20::processInPlace(QByteArray& data, quint64 rounds)
ECRYPT_encrypt_bytes(&m_ctx, reinterpret_cast<const u8*>(data.constData()),
reinterpret_cast<u8*>(data.data()), data.size());
}
return true;
}
void SymmetricCipherSalsa20::reset()
bool SymmetricCipherSalsa20::reset()
{
ECRYPT_ivsetup(&m_ctx, reinterpret_cast<const u8*>(m_iv.constData()));
return true;
}
int SymmetricCipherSalsa20::blockSize() const
{
return 64;
}
QString SymmetricCipherSalsa20::errorString() const
{
return QString();
}

View File

@ -42,6 +42,8 @@ public:
bool reset();
int blockSize() const;
QString errorString() const;
private:
ECRYPT_ctx m_ctx;
QByteArray m_key;