Use quint64 everywhere for the transform rounds number.

This commit is contained in:
Felix Geyer 2012-05-08 22:31:09 +02:00
parent ebce183925
commit 8122ab2b2c
8 changed files with 13 additions and 13 deletions

View file

@ -57,7 +57,7 @@ public:
m_backend->processInPlace(data); m_backend->processInPlace(data);
} }
inline void processInPlace(QByteArray& data, int rounds) { inline void processInPlace(QByteArray& data, quint64 rounds) {
Q_ASSERT(rounds > 0); Q_ASSERT(rounds > 0);
m_backend->processInPlace(data, rounds); m_backend->processInPlace(data, rounds);
} }

View file

@ -30,7 +30,7 @@ public:
virtual QByteArray process(const QByteArray& data) = 0; virtual QByteArray process(const QByteArray& data) = 0;
virtual void processInPlace(QByteArray& data) = 0; virtual void processInPlace(QByteArray& data) = 0;
virtual void processInPlace(QByteArray& data, int rounds) = 0; virtual void processInPlace(QByteArray& data, quint64 rounds) = 0;
virtual void reset() = 0; virtual void reset() = 0;
virtual int blockSize() const = 0; virtual int blockSize() const = 0;

View file

@ -113,20 +113,20 @@ void SymmetricCipherGcrypt::processInPlace(QByteArray& data)
Q_ASSERT(error == 0); Q_ASSERT(error == 0);
} }
void SymmetricCipherGcrypt::processInPlace(QByteArray& data, int rounds) void SymmetricCipherGcrypt::processInPlace(QByteArray& data, quint64 rounds)
{ {
// TODO check block size // TODO check block size
gcry_error_t error; gcry_error_t error;
if (m_direction == SymmetricCipher::Decrypt) { if (m_direction == SymmetricCipher::Decrypt) {
for (int i = 0; i != rounds; ++i) { for (quint64 i = 0; i != rounds; ++i) {
error = gcry_cipher_decrypt(m_ctx, data.data(), data.size(), 0, 0); error = gcry_cipher_decrypt(m_ctx, data.data(), data.size(), 0, 0);
Q_ASSERT(error == 0); Q_ASSERT(error == 0);
} }
} }
else { else {
for (int i = 0; i != rounds; ++i) { for (quint64 i = 0; i != rounds; ++i) {
error = gcry_cipher_encrypt(m_ctx, data.data(), data.size(), 0, 0); error = gcry_cipher_encrypt(m_ctx, data.data(), data.size(), 0, 0);
Q_ASSERT(error == 0); Q_ASSERT(error == 0);
} }

View file

@ -35,7 +35,7 @@ public:
QByteArray process(const QByteArray& data); QByteArray process(const QByteArray& data);
void processInPlace(QByteArray& data); void processInPlace(QByteArray& data);
void processInPlace(QByteArray& data, int rounds); void processInPlace(QByteArray& data, quint64 rounds);
void reset(); void reset();
int blockSize() const; int blockSize() const;

View file

@ -74,11 +74,11 @@ void SymmetricCipherSalsa20::processInPlace(QByteArray& data)
reinterpret_cast<u8*>(data.data()), data.size()); reinterpret_cast<u8*>(data.data()), data.size());
} }
void SymmetricCipherSalsa20::processInPlace(QByteArray& data, int rounds) void SymmetricCipherSalsa20::processInPlace(QByteArray& data, quint64 rounds)
{ {
Q_ASSERT((data.size() < blockSize()) || ((data.size() % blockSize()) == 0)); Q_ASSERT((data.size() < blockSize()) || ((data.size() % blockSize()) == 0));
for (int i = 0; i != rounds; ++i) { for (quint64 i = 0; i != rounds; ++i) {
ECRYPT_encrypt_bytes(&m_ctx, reinterpret_cast<const u8*>(data.constData()), ECRYPT_encrypt_bytes(&m_ctx, reinterpret_cast<const u8*>(data.constData()),
reinterpret_cast<u8*>(data.data()), data.size()); reinterpret_cast<u8*>(data.data()), data.size());
} }

View file

@ -37,7 +37,7 @@ public:
QByteArray process(const QByteArray& data); QByteArray process(const QByteArray& data);
void processInPlace(QByteArray& data); void processInPlace(QByteArray& data);
void processInPlace(QByteArray& data, int rounds); void processInPlace(QByteArray& data, quint64 rounds);
void reset(); void reset();
int blockSize() const; int blockSize() const;

View file

@ -71,7 +71,7 @@ QByteArray CompositeKey::rawKey() const
return cryptoHash.result(); return cryptoHash.result();
} }
QByteArray CompositeKey::transform(const QByteArray& seed, int rounds) const QByteArray CompositeKey::transform(const QByteArray& seed, quint64 rounds) const
{ {
Q_ASSERT(seed.size() == 32); Q_ASSERT(seed.size() == 32);
Q_ASSERT(rounds > 0); Q_ASSERT(rounds > 0);
@ -89,7 +89,7 @@ QByteArray CompositeKey::transform(const QByteArray& seed, int rounds) const
} }
QByteArray CompositeKey::transformKeyRaw(const QByteArray& key, const QByteArray& seed, QByteArray CompositeKey::transformKeyRaw(const QByteArray& key, const QByteArray& seed,
int rounds) { quint64 rounds) {
QByteArray iv(16, 0); QByteArray iv(16, 0);
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb, SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb,
SymmetricCipher::Encrypt, seed, iv); SymmetricCipher::Encrypt, seed, iv);

View file

@ -33,14 +33,14 @@ public:
CompositeKey& operator=(const CompositeKey& key); CompositeKey& operator=(const CompositeKey& key);
QByteArray rawKey() const; QByteArray rawKey() const;
QByteArray transform(const QByteArray& seed, int rounds) const; QByteArray transform(const QByteArray& seed, quint64 rounds) const;
void addKey(const Key& key); void addKey(const Key& key);
static int transformKeyBenchmark(int msec); static int transformKeyBenchmark(int msec);
private: private:
static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed, static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed,
int rounds); quint64 rounds);
QList<Key*> m_keys; QList<Key*> m_keys;
}; };