mirror of
https://github.com/QuasarApp/qca.git
synced 2025-04-26 11:34:32 +00:00
use MemoryRegion instead of SecureArray, for hash, mac, and pkey sign/verify
svn path=/trunk/kdesupport/qca/; revision=677315
This commit is contained in:
parent
8d2d39c34c
commit
bf27824a9a
@ -130,7 +130,7 @@ public:
|
||||
|
||||
// This is a bit different to the way the I-D does it,
|
||||
// to allow for multiple update() calls.
|
||||
void update(const QCA::SecureArray &a)
|
||||
void update(const QCA::MemoryRegion &a)
|
||||
{
|
||||
QCA::SecureArray bytesToProcess = m_residual + a;
|
||||
int blockNum;
|
||||
@ -157,7 +157,7 @@ public:
|
||||
m_residual[yalv] = bytesToProcess[blockNum*16 + yalv];
|
||||
}
|
||||
|
||||
void final( QCA::SecureArray *out)
|
||||
void final( QCA::MemoryRegion *out)
|
||||
{
|
||||
QCA::SecureArray lastBlock;
|
||||
int numBytesLeft = m_residual.size();
|
||||
|
@ -120,7 +120,7 @@ int main(int argc, char **argv)
|
||||
// instead of update() and final(), you can do the whole thing
|
||||
// in one step, using process()
|
||||
printf("One step decryption using AES128: %s\n",
|
||||
(cipher.process(cipherText)).data() );
|
||||
QCA::SecureArray(cipher.process(cipherText)).data() );
|
||||
|
||||
}
|
||||
|
||||
|
@ -244,14 +244,14 @@ public:
|
||||
|
||||
\param a the byte array to add to the hash
|
||||
*/
|
||||
virtual void update(const SecureArray &a);
|
||||
virtual void update(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
\overload
|
||||
|
||||
\param a the QByteArray to add to the hash
|
||||
*/
|
||||
virtual void update(const QByteArray &a);
|
||||
void update(const QByteArray &a);
|
||||
|
||||
/**
|
||||
\overload
|
||||
@ -267,7 +267,7 @@ public:
|
||||
determined with strlen(), which may not be what you want
|
||||
if the array contains a null (0x00) character.
|
||||
*/
|
||||
virtual void update(const char *data, int len = -1);
|
||||
void update(const char *data, int len = -1);
|
||||
|
||||
/**
|
||||
\overload
|
||||
@ -291,7 +291,7 @@ if ( f1.open( IO_ReadOnly ) )
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
virtual void update(QIODevice *file);
|
||||
void update(QIODevice *file);
|
||||
|
||||
/**
|
||||
Finalises input and returns the hash result
|
||||
@ -306,7 +306,7 @@ if ( f1.open( IO_ReadOnly ) )
|
||||
reuse the Hash object, you should call clear() and
|
||||
start to update() again.
|
||||
*/
|
||||
virtual SecureArray final();
|
||||
virtual MemoryRegion final();
|
||||
|
||||
/**
|
||||
%Hash a byte array, returning it as another
|
||||
@ -328,7 +328,7 @@ SecureArray outputArray = QCA::Hash("md2")::hash(sampleArray);
|
||||
consider creating an Hash object, and then calling
|
||||
update() and final().
|
||||
*/
|
||||
SecureArray hash(const SecureArray &array);
|
||||
MemoryRegion hash(const MemoryRegion &array);
|
||||
|
||||
/**
|
||||
%Hash a byte array, returning it as a printable
|
||||
@ -344,7 +344,7 @@ SecureArray outputArray = QCA::Hash("md2")::hash(sampleArray);
|
||||
object, call Hash::update() as required, then call
|
||||
Hash::final(), before using the static arrayToHex() method.
|
||||
*/
|
||||
QString hashToString(const SecureArray &array);
|
||||
QString hashToString(const MemoryRegion &array);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
@ -630,13 +630,13 @@ public:
|
||||
|
||||
\param a the array of data to encrypt / decrypt
|
||||
*/
|
||||
virtual SecureArray update(const SecureArray &a);
|
||||
virtual MemoryRegion update(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
complete the block of data, padding as required, and returning
|
||||
the completed block
|
||||
*/
|
||||
virtual SecureArray final();
|
||||
virtual MemoryRegion final();
|
||||
|
||||
/**
|
||||
Test if an update() or final() call succeeded.
|
||||
@ -760,7 +760,7 @@ public:
|
||||
|
||||
\param array the message contents
|
||||
*/
|
||||
virtual void update(const SecureArray &array);
|
||||
virtual void update(const MemoryRegion &array);
|
||||
|
||||
/**
|
||||
Finalises input and returns the MAC result
|
||||
@ -773,7 +773,7 @@ public:
|
||||
reuse the %MessageAuthenticationCode object, you
|
||||
should call clear() and start to update() again.
|
||||
*/
|
||||
virtual SecureArray final();
|
||||
virtual MemoryRegion final();
|
||||
|
||||
/**
|
||||
Initialise the MAC algorithm
|
||||
|
@ -929,12 +929,12 @@ public:
|
||||
\param a the byte array of data that is to
|
||||
be used to update the internal state.
|
||||
*/
|
||||
virtual void update(const SecureArray &a) = 0;
|
||||
virtual void update(const MemoryRegion &a) = 0;
|
||||
|
||||
/**
|
||||
Complete the algorithm and return the internal state
|
||||
*/
|
||||
virtual SecureArray final() = 0;
|
||||
virtual MemoryRegion final() = 0;
|
||||
|
||||
/**
|
||||
Perform an "all in one" update, returning
|
||||
@ -946,7 +946,7 @@ public:
|
||||
\note This will invalidate any previous
|
||||
computation using this object.
|
||||
*/
|
||||
SecureArray process(const SecureArray &a);
|
||||
MemoryRegion process(const MemoryRegion &a);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -981,13 +981,13 @@ public:
|
||||
|
||||
\param a the array containing data to process
|
||||
*/
|
||||
virtual SecureArray update(const SecureArray &a) = 0;
|
||||
virtual MemoryRegion update(const MemoryRegion &a) = 0;
|
||||
|
||||
/**
|
||||
Complete the algorithm, returning any
|
||||
additional results.
|
||||
*/
|
||||
virtual SecureArray final() = 0;
|
||||
virtual MemoryRegion final() = 0;
|
||||
|
||||
/**
|
||||
Test if an update() or final() call succeeded.
|
||||
@ -1006,7 +1006,7 @@ public:
|
||||
\note This will invalidate any previous
|
||||
computation using this object.
|
||||
*/
|
||||
SecureArray process(const SecureArray &a);
|
||||
MemoryRegion process(const MemoryRegion &a);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -582,7 +582,7 @@ public:
|
||||
|
||||
\param a the array containing the data that should be added to the signature
|
||||
*/
|
||||
void update(const SecureArray &a);
|
||||
void update(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
Check the signature is valid for the message
|
||||
@ -624,7 +624,7 @@ if( pubkey.canVerify() )
|
||||
|
||||
\return true if the signature is valid for the message
|
||||
*/
|
||||
bool verifyMessage(const SecureArray &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
||||
bool verifyMessage(const MemoryRegion &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
||||
|
||||
/**
|
||||
Export the key in Distinguished Encoding Rules (DER) format
|
||||
@ -850,7 +850,7 @@ public:
|
||||
\note This synchronous operation may require event handling, and so
|
||||
it must not be called from the same thread as an EventHandler.
|
||||
*/
|
||||
void update(const SecureArray &a);
|
||||
void update(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
The resulting signature
|
||||
@ -872,7 +872,7 @@ public:
|
||||
\note This synchronous operation may require event handling, and so
|
||||
it must not be called from the same thread as an EventHandler.
|
||||
*/
|
||||
QByteArray signMessage(const SecureArray &a, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
||||
QByteArray signMessage(const MemoryRegion &a, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
||||
|
||||
/**
|
||||
Derive a shared secret key from a public key
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
|
||||
\param a the array to encode
|
||||
*/
|
||||
SecureArray encode(const SecureArray &a);
|
||||
MemoryRegion encode(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
Process an array in the "reverse" direction,
|
||||
@ -89,11 +89,11 @@ public:
|
||||
This method runs in the reverse direction, so
|
||||
for something like a Base64 encoding, it takes
|
||||
a Base64 encoded array, and returns the "native"
|
||||
representation..
|
||||
representation.
|
||||
|
||||
\param a the array to decode
|
||||
*/
|
||||
SecureArray decode(const SecureArray &a);
|
||||
MemoryRegion decode(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
Process an array in the "forward" direction,
|
||||
@ -105,7 +105,7 @@ public:
|
||||
|
||||
\param a the array to encode
|
||||
*/
|
||||
QString arrayToString(const SecureArray &a);
|
||||
QString arrayToString(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
Process an string in the "reverse" direction,
|
||||
@ -117,7 +117,7 @@ public:
|
||||
|
||||
\param s the array to decode
|
||||
*/
|
||||
SecureArray stringToArray(const QString &s);
|
||||
MemoryRegion stringToArray(const QString &s);
|
||||
|
||||
/**
|
||||
Process a string in the "forward" direction,
|
||||
@ -190,7 +190,7 @@ public:
|
||||
|
||||
\param a the array containing data to process
|
||||
*/
|
||||
virtual SecureArray update(const SecureArray &a);
|
||||
virtual MemoryRegion update(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
Complete the algorithm
|
||||
@ -200,7 +200,7 @@ public:
|
||||
zero length array - any output will have been returned
|
||||
from the update() call.
|
||||
*/
|
||||
virtual SecureArray final();
|
||||
virtual MemoryRegion final();
|
||||
|
||||
/**
|
||||
Test if an update() or final() call succeeded.
|
||||
@ -210,6 +210,8 @@ public:
|
||||
virtual bool ok() const;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(Hex)
|
||||
|
||||
uchar val;
|
||||
bool partial;
|
||||
bool _ok;
|
||||
@ -277,7 +279,7 @@ public:
|
||||
|
||||
\param a the array containing data to process
|
||||
*/
|
||||
virtual SecureArray update(const SecureArray &a);
|
||||
virtual MemoryRegion update(const MemoryRegion &a);
|
||||
|
||||
/**
|
||||
Complete the algorithm
|
||||
@ -287,7 +289,7 @@ public:
|
||||
empty array, or an array containing one or two
|
||||
"=" (equals, 0x3D) characters.
|
||||
*/
|
||||
virtual SecureArray final();
|
||||
virtual MemoryRegion final();
|
||||
|
||||
/**
|
||||
Test if an update() or final() call succeeded.
|
||||
@ -297,11 +299,16 @@ public:
|
||||
virtual bool ok() const;
|
||||
|
||||
private:
|
||||
SecureArray partial;
|
||||
Q_DISABLE_COPY(Base64)
|
||||
|
||||
QByteArray partial;
|
||||
bool _ok;
|
||||
int col;
|
||||
bool _lb_enabled;
|
||||
int _lb_column;
|
||||
|
||||
class Private;
|
||||
Private *d;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -316,13 +316,13 @@ public:
|
||||
Equality operator. Returns true if both arrays have the same
|
||||
data (and the same length, of course).
|
||||
*/
|
||||
bool operator==(const SecureArray &other) const;
|
||||
bool operator==(const MemoryRegion &other) const;
|
||||
|
||||
/**
|
||||
Inequality operator. Returns true if both arrays have different
|
||||
length, or the same length but different data.
|
||||
*/
|
||||
inline bool operator!=(const SecureArray &other) const
|
||||
inline bool operator!=(const MemoryRegion &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ class QCA_EXPORT HashContext : public BasicContext
|
||||
public:
|
||||
HashContext(Provider *p, const QString &type) : BasicContext(p, type) {}
|
||||
virtual void clear() = 0;
|
||||
virtual void update(const SecureArray &a) = 0;
|
||||
virtual SecureArray final() = 0;
|
||||
virtual void update(const MemoryRegion &a) = 0;
|
||||
virtual MemoryRegion final() = 0;
|
||||
};
|
||||
|
||||
class QCA_EXPORT CipherContext : public BasicContext
|
||||
@ -82,8 +82,8 @@ public:
|
||||
virtual void setup(const SymmetricKey &key) = 0;
|
||||
virtual KeyLength keyLength() const = 0;
|
||||
|
||||
virtual void update(const SecureArray &in) = 0;
|
||||
virtual void final(SecureArray *out) = 0;
|
||||
virtual void update(const MemoryRegion &in) = 0;
|
||||
virtual void final(MemoryRegion *out) = 0;
|
||||
|
||||
protected:
|
||||
KeyLength anyKeyLength() const
|
||||
@ -137,7 +137,7 @@ public:
|
||||
// sign / verify
|
||||
virtual void startSign(SignatureAlgorithm alg, SignatureFormat format);
|
||||
virtual void startVerify(SignatureAlgorithm alg, SignatureFormat format);
|
||||
virtual void update(const SecureArray &in);
|
||||
virtual void update(const MemoryRegion &in);
|
||||
virtual QByteArray endSign();
|
||||
virtual bool endVerify(const QByteArray &sig);
|
||||
|
||||
|
@ -991,12 +991,12 @@ public:
|
||||
EVP_DigestInit( &m_context, m_algorithm );
|
||||
}
|
||||
|
||||
void update(const SecureArray &a)
|
||||
void update(const MemoryRegion &a)
|
||||
{
|
||||
EVP_DigestUpdate( &m_context, (unsigned char*)a.data(), a.size() );
|
||||
}
|
||||
|
||||
SecureArray final()
|
||||
MemoryRegion final()
|
||||
{
|
||||
SecureArray a( EVP_MD_size( m_algorithm ) );
|
||||
EVP_DigestFinal( &m_context, (unsigned char*)a.data(), 0 );
|
||||
@ -1099,16 +1099,17 @@ public:
|
||||
return anyKeyLength();
|
||||
}
|
||||
|
||||
void update(const SecureArray &a)
|
||||
void update(const MemoryRegion &a)
|
||||
{
|
||||
HMAC_Update( &m_context, (unsigned char *)a.data(), a.size() );
|
||||
}
|
||||
|
||||
void final( SecureArray *out)
|
||||
void final(MemoryRegion *out)
|
||||
{
|
||||
out->resize( EVP_MD_size( m_algorithm ) );
|
||||
HMAC_Final(&m_context, (unsigned char *)out->data(), 0 );
|
||||
SecureArray sa( EVP_MD_size( m_algorithm ), 0 );
|
||||
HMAC_Final(&m_context, (unsigned char *)sa.data(), 0 );
|
||||
HMAC_CTX_cleanup(&m_context);
|
||||
*out = sa;
|
||||
}
|
||||
|
||||
Provider::Context *clone() const
|
||||
@ -1197,7 +1198,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void update(const SecureArray &in)
|
||||
void update(const MemoryRegion &in)
|
||||
{
|
||||
if(state == SignActive)
|
||||
{
|
||||
@ -1765,7 +1766,7 @@ public:
|
||||
evp.startVerify(md);
|
||||
}
|
||||
|
||||
virtual void update(const SecureArray &in)
|
||||
virtual void update(const MemoryRegion &in)
|
||||
{
|
||||
evp.update(in);
|
||||
}
|
||||
@ -2034,7 +2035,7 @@ public:
|
||||
evp.startVerify(EVP_dss1());
|
||||
}
|
||||
|
||||
virtual void update(const SecureArray &in)
|
||||
virtual void update(const MemoryRegion &in)
|
||||
{
|
||||
evp.update(in);
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ void Hash::clear()
|
||||
static_cast<HashContext *>(context())->clear();
|
||||
}
|
||||
|
||||
void Hash::update(const SecureArray &a)
|
||||
void Hash::update(const MemoryRegion &a)
|
||||
{
|
||||
static_cast<HashContext *>(context())->update(a);
|
||||
}
|
||||
@ -149,17 +149,17 @@ void Hash::update(QIODevice *file)
|
||||
update(buffer, len);
|
||||
}
|
||||
|
||||
SecureArray Hash::final()
|
||||
MemoryRegion Hash::final()
|
||||
{
|
||||
return static_cast<HashContext *>(context())->final();
|
||||
}
|
||||
|
||||
SecureArray Hash::hash(const SecureArray &a)
|
||||
MemoryRegion Hash::hash(const MemoryRegion &a)
|
||||
{
|
||||
return process(a);
|
||||
}
|
||||
|
||||
QString Hash::hashToString(const SecureArray &a)
|
||||
QString Hash::hashToString(const MemoryRegion &a)
|
||||
{
|
||||
return arrayToHex(hash(a).toByteArray());
|
||||
}
|
||||
@ -254,7 +254,7 @@ void Cipher::clear()
|
||||
static_cast<CipherContext *>(context())->setup(d->dir, d->key, d->iv);
|
||||
}
|
||||
|
||||
SecureArray Cipher::update(const SecureArray &a)
|
||||
MemoryRegion Cipher::update(const MemoryRegion &a)
|
||||
{
|
||||
SecureArray out;
|
||||
if(d->done)
|
||||
@ -263,7 +263,7 @@ SecureArray Cipher::update(const SecureArray &a)
|
||||
return out;
|
||||
}
|
||||
|
||||
SecureArray Cipher::final()
|
||||
MemoryRegion Cipher::final()
|
||||
{
|
||||
SecureArray out;
|
||||
if(d->done)
|
||||
@ -338,7 +338,7 @@ public:
|
||||
SymmetricKey key;
|
||||
|
||||
bool done;
|
||||
SecureArray buf;
|
||||
MemoryRegion buf;
|
||||
};
|
||||
|
||||
|
||||
@ -392,14 +392,14 @@ void MessageAuthenticationCode::clear()
|
||||
static_cast<MACContext *>(context())->setup(d->key);
|
||||
}
|
||||
|
||||
void MessageAuthenticationCode::update(const SecureArray &a)
|
||||
void MessageAuthenticationCode::update(const MemoryRegion &a)
|
||||
{
|
||||
if(d->done)
|
||||
return;
|
||||
static_cast<MACContext *>(context())->update(a);
|
||||
}
|
||||
|
||||
SecureArray MessageAuthenticationCode::final()
|
||||
MemoryRegion MessageAuthenticationCode::final()
|
||||
{
|
||||
if(!d->done)
|
||||
{
|
||||
|
@ -891,7 +891,7 @@ void PKeyBase::startVerify(SignatureAlgorithm, SignatureFormat)
|
||||
{
|
||||
}
|
||||
|
||||
void PKeyBase::update(const SecureArray &)
|
||||
void PKeyBase::update(const MemoryRegion &)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1080,7 +1080,7 @@ BufferedComputation::~BufferedComputation()
|
||||
{
|
||||
}
|
||||
|
||||
SecureArray BufferedComputation::process(const SecureArray &a)
|
||||
MemoryRegion BufferedComputation::process(const MemoryRegion &a)
|
||||
{
|
||||
clear();
|
||||
update(a);
|
||||
@ -1094,19 +1094,19 @@ Filter::~Filter()
|
||||
{
|
||||
}
|
||||
|
||||
SecureArray Filter::process(const SecureArray &a)
|
||||
MemoryRegion Filter::process(const MemoryRegion &a)
|
||||
{
|
||||
clear();
|
||||
SecureArray buf = update(a);
|
||||
MemoryRegion buf = update(a);
|
||||
if(!ok())
|
||||
return SecureArray();
|
||||
SecureArray fin = final();
|
||||
return MemoryRegion();
|
||||
MemoryRegion fin = final();
|
||||
if(!ok())
|
||||
return SecureArray();
|
||||
int oldsize = buf.size();
|
||||
buf.resize(oldsize + fin.size());
|
||||
memcpy(buf.data() + oldsize, fin.data(), fin.size());
|
||||
return buf;
|
||||
return MemoryRegion();
|
||||
if(buf.isSecure() || fin.isSecure())
|
||||
return (SecureArray(buf) + SecureArray(fin));
|
||||
else
|
||||
return (buf.toByteArray() + fin.toByteArray());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -529,21 +529,34 @@ public:
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
secure = true;
|
||||
md5_init(&md5);
|
||||
}
|
||||
|
||||
virtual void update(const SecureArray &in)
|
||||
virtual void update(const MemoryRegion &in)
|
||||
{
|
||||
if(!in.isSecure())
|
||||
secure = false;
|
||||
md5_append(&md5, (const md5_byte_t *)in.data(), in.size());
|
||||
}
|
||||
|
||||
virtual SecureArray final()
|
||||
virtual MemoryRegion final()
|
||||
{
|
||||
SecureArray b(16);
|
||||
md5_finish(&md5, (md5_byte_t *)b.data());
|
||||
return b;
|
||||
if(secure)
|
||||
{
|
||||
SecureArray b(16, 0);
|
||||
md5_finish(&md5, (md5_byte_t *)b.data());
|
||||
return b;
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray b(16, 0);
|
||||
md5_finish(&md5, (md5_byte_t *)b.data());
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
bool secure;
|
||||
md5_state_t md5;
|
||||
};
|
||||
|
||||
@ -607,6 +620,7 @@ class DefaultSHA1Context : public HashContext
|
||||
public:
|
||||
SHA1_CONTEXT _context;
|
||||
CHAR64LONG16* block;
|
||||
bool secure;
|
||||
|
||||
DefaultSHA1Context(Provider *p) : HashContext(p, "sha1")
|
||||
{
|
||||
@ -620,19 +634,31 @@ public:
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
secure = true;
|
||||
sha1_init(&_context);
|
||||
}
|
||||
|
||||
virtual void update(const SecureArray &in)
|
||||
virtual void update(const MemoryRegion &in)
|
||||
{
|
||||
if(!in.isSecure())
|
||||
secure = false;
|
||||
sha1_update(&_context, (unsigned char *)in.data(), (unsigned int)in.size());
|
||||
}
|
||||
|
||||
virtual SecureArray final()
|
||||
virtual MemoryRegion final()
|
||||
{
|
||||
SecureArray b(20);
|
||||
sha1_final((unsigned char *)b.data(), &_context);
|
||||
return b;
|
||||
if(secure)
|
||||
{
|
||||
SecureArray b(20, 0);
|
||||
sha1_final((unsigned char *)b.data(), &_context);
|
||||
return b;
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray b(20, 0);
|
||||
sha1_final((unsigned char *)b.data(), &_context);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned long blk0(quint32 i)
|
||||
|
@ -803,7 +803,7 @@ void PublicKey::startVerify(SignatureAlgorithm alg, SignatureFormat format)
|
||||
static_cast<PKeyContext *>(context())->key()->startVerify(alg, format);
|
||||
}
|
||||
|
||||
void PublicKey::update(const SecureArray &a)
|
||||
void PublicKey::update(const MemoryRegion &a)
|
||||
{
|
||||
static_cast<PKeyContext *>(context())->key()->update(a);
|
||||
}
|
||||
@ -813,7 +813,7 @@ bool PublicKey::validSignature(const QByteArray &sig)
|
||||
return static_cast<PKeyContext *>(context())->key()->endVerify(sig);
|
||||
}
|
||||
|
||||
bool PublicKey::verifyMessage(const SecureArray &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format)
|
||||
bool PublicKey::verifyMessage(const MemoryRegion &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format)
|
||||
{
|
||||
startVerify(alg, format);
|
||||
update(a);
|
||||
@ -958,7 +958,7 @@ void PrivateKey::startSign(SignatureAlgorithm alg, SignatureFormat format)
|
||||
static_cast<PKeyContext *>(context())->key()->startSign(alg, format);
|
||||
}
|
||||
|
||||
void PrivateKey::update(const SecureArray &a)
|
||||
void PrivateKey::update(const MemoryRegion &a)
|
||||
{
|
||||
static_cast<PKeyContext *>(context())->key()->update(a);
|
||||
}
|
||||
@ -968,7 +968,7 @@ QByteArray PrivateKey::signature()
|
||||
return static_cast<PKeyContext *>(context())->key()->endSign();
|
||||
}
|
||||
|
||||
QByteArray PrivateKey::signMessage(const SecureArray &a, SignatureAlgorithm alg, SignatureFormat format)
|
||||
QByteArray PrivateKey::signMessage(const MemoryRegion &a, SignatureAlgorithm alg, SignatureFormat format)
|
||||
{
|
||||
startSign(alg, format);
|
||||
update(a);
|
||||
|
@ -40,27 +40,27 @@ Direction TextFilter::direction() const
|
||||
return _dir;
|
||||
}
|
||||
|
||||
SecureArray TextFilter::encode(const SecureArray &a)
|
||||
MemoryRegion TextFilter::encode(const MemoryRegion &a)
|
||||
{
|
||||
setup(Encode);
|
||||
return process(a);
|
||||
}
|
||||
|
||||
SecureArray TextFilter::decode(const SecureArray &a)
|
||||
MemoryRegion TextFilter::decode(const MemoryRegion &a)
|
||||
{
|
||||
setup(Decode);
|
||||
return process(a);
|
||||
}
|
||||
|
||||
QString TextFilter::arrayToString(const SecureArray &a)
|
||||
QString TextFilter::arrayToString(const MemoryRegion &a)
|
||||
{
|
||||
return QString::fromLatin1(encode(a).toByteArray());
|
||||
}
|
||||
|
||||
SecureArray TextFilter::stringToArray(const QString &s)
|
||||
MemoryRegion TextFilter::stringToArray(const QString &s)
|
||||
{
|
||||
if(s.isEmpty())
|
||||
return SecureArray();
|
||||
return MemoryRegion();
|
||||
return decode(s.toLatin1());
|
||||
}
|
||||
|
||||
@ -111,11 +111,12 @@ void Hex::clear()
|
||||
_ok = true;
|
||||
}
|
||||
|
||||
SecureArray Hex::update(const SecureArray &a)
|
||||
MemoryRegion Hex::update(const MemoryRegion &m)
|
||||
{
|
||||
QByteArray a = m.toByteArray();
|
||||
if(_dir == Encode)
|
||||
{
|
||||
SecureArray out(a.size() * 2);
|
||||
QByteArray out(a.size() * 2, 0);
|
||||
int at = 0;
|
||||
int c;
|
||||
for(int n = 0; n < (int)a.size(); ++n)
|
||||
@ -138,7 +139,7 @@ SecureArray Hex::update(const SecureArray &a)
|
||||
out[at++] = (char)c;
|
||||
}
|
||||
if(!_ok)
|
||||
return SecureArray();
|
||||
return MemoryRegion();
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -153,7 +154,7 @@ SecureArray Hex::update(const SecureArray &a)
|
||||
flag = true;
|
||||
}
|
||||
|
||||
SecureArray out(a.size() / 2);
|
||||
QByteArray out(a.size() / 2, 0);
|
||||
int at = 0;
|
||||
int c;
|
||||
for(int n = 0; n < (int)a.size(); ++n)
|
||||
@ -178,7 +179,7 @@ SecureArray Hex::update(const SecureArray &a)
|
||||
}
|
||||
}
|
||||
if(!_ok)
|
||||
return SecureArray();
|
||||
return MemoryRegion();
|
||||
|
||||
if(flag)
|
||||
{
|
||||
@ -189,11 +190,11 @@ SecureArray Hex::update(const SecureArray &a)
|
||||
}
|
||||
}
|
||||
|
||||
SecureArray Hex::final()
|
||||
MemoryRegion Hex::final()
|
||||
{
|
||||
if(partial)
|
||||
_ok = false;
|
||||
return SecureArray();
|
||||
return MemoryRegion();
|
||||
}
|
||||
|
||||
bool Hex::ok() const
|
||||
@ -241,7 +242,7 @@ void Base64::setLineBreaksColumn(int column)
|
||||
_lb_column = 76;
|
||||
}
|
||||
|
||||
static SecureArray b64encode(const SecureArray &s)
|
||||
static QByteArray b64encode(const QByteArray &s)
|
||||
{
|
||||
int i;
|
||||
int len = s.size();
|
||||
@ -257,7 +258,7 @@ static SecureArray b64encode(const SecureArray &s)
|
||||
"=";
|
||||
int a, b, c;
|
||||
|
||||
SecureArray p((len + 2) / 3 * 4);
|
||||
QByteArray p((len + 2) / 3 * 4, 0);
|
||||
int at = 0;
|
||||
for(i = 0; i < len; i += 3)
|
||||
{
|
||||
@ -285,7 +286,7 @@ static SecureArray b64encode(const SecureArray &s)
|
||||
return p;
|
||||
}
|
||||
|
||||
static SecureArray b64decode(const SecureArray &s, bool *ok)
|
||||
static QByteArray b64decode(const QByteArray &s, bool *ok)
|
||||
{
|
||||
// -1 specifies invalid
|
||||
// 64 specifies eof
|
||||
@ -312,7 +313,7 @@ static SecureArray b64decode(const SecureArray &s, bool *ok)
|
||||
};
|
||||
|
||||
// return value
|
||||
SecureArray p;
|
||||
QByteArray p;
|
||||
*ok = true;
|
||||
|
||||
// this should be a multiple of 4
|
||||
@ -356,7 +357,7 @@ static SecureArray b64decode(const SecureArray &s, bool *ok)
|
||||
return p;
|
||||
}
|
||||
|
||||
static int findLF(const SecureArray &in, int offset)
|
||||
static int findLF(const QByteArray &in, int offset)
|
||||
{
|
||||
for(int n = offset; n < in.size(); ++n)
|
||||
{
|
||||
@ -366,9 +367,9 @@ static int findLF(const SecureArray &in, int offset)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static SecureArray insert_linebreaks(const SecureArray &s, int *col, int lfAt)
|
||||
static QByteArray insert_linebreaks(const QByteArray &s, int *col, int lfAt)
|
||||
{
|
||||
SecureArray out = s;
|
||||
QByteArray out = s;
|
||||
|
||||
int needed = (out.size() + *col) / lfAt; // how many newlines needed?
|
||||
if(needed > 0)
|
||||
@ -404,9 +405,9 @@ static SecureArray insert_linebreaks(const SecureArray &s, int *col, int lfAt)
|
||||
return out;
|
||||
}
|
||||
|
||||
static SecureArray remove_linebreaks(const SecureArray &s)
|
||||
static QByteArray remove_linebreaks(const QByteArray &s)
|
||||
{
|
||||
SecureArray out = s;
|
||||
QByteArray out = s;
|
||||
|
||||
int removed = 0;
|
||||
int at = findLF(out, 0);
|
||||
@ -432,23 +433,21 @@ static SecureArray remove_linebreaks(const SecureArray &s)
|
||||
return out;
|
||||
}
|
||||
|
||||
static void appendArray(SecureArray *a, const SecureArray &b)
|
||||
static void appendArray(QByteArray *a, const QByteArray &b)
|
||||
{
|
||||
int oldsize = a->size();
|
||||
a->resize(oldsize + b.size());
|
||||
memcpy(a->data() + oldsize, b.data(), b.size());
|
||||
a->append(b);
|
||||
}
|
||||
|
||||
SecureArray Base64::update(const SecureArray &a)
|
||||
MemoryRegion Base64::update(const MemoryRegion &m)
|
||||
{
|
||||
SecureArray in;
|
||||
QByteArray in;
|
||||
if(_dir == Decode && _lb_enabled)
|
||||
in = remove_linebreaks(a);
|
||||
in = remove_linebreaks(m.toByteArray());
|
||||
else
|
||||
in = a;
|
||||
in = m.toByteArray();
|
||||
|
||||
if(in.isEmpty())
|
||||
return SecureArray();
|
||||
return MemoryRegion();
|
||||
|
||||
int chunk;
|
||||
if(_dir == Encode)
|
||||
@ -460,13 +459,13 @@ SecureArray Base64::update(const SecureArray &a)
|
||||
if(size < chunk)
|
||||
{
|
||||
appendArray(&partial, in);
|
||||
return SecureArray();
|
||||
return MemoryRegion();
|
||||
}
|
||||
|
||||
int eat = size % chunk;
|
||||
|
||||
// s = partial + a - eat
|
||||
SecureArray s(partial.size() + in.size() - eat);
|
||||
QByteArray s(partial.size() + in.size() - eat, 0);
|
||||
memcpy(s.data(), partial.data(), partial.size());
|
||||
memcpy(s.data() + partial.size(), in.data(), in.size() - eat);
|
||||
|
||||
@ -483,14 +482,14 @@ SecureArray Base64::update(const SecureArray &a)
|
||||
else
|
||||
{
|
||||
bool ok;
|
||||
SecureArray out = b64decode(s, &ok);
|
||||
QByteArray out = b64decode(s, &ok);
|
||||
if(!ok)
|
||||
_ok = false;
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
SecureArray Base64::final()
|
||||
MemoryRegion Base64::final()
|
||||
{
|
||||
if(_dir == Encode)
|
||||
{
|
||||
@ -502,7 +501,7 @@ SecureArray Base64::final()
|
||||
else
|
||||
{
|
||||
bool ok;
|
||||
SecureArray out = b64decode(partial, &ok);
|
||||
QByteArray out = b64decode(partial, &ok);
|
||||
if(!ok)
|
||||
_ok = false;
|
||||
return out;
|
||||
|
@ -650,7 +650,7 @@ SecureArray & SecureArray::append(const SecureArray &a)
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool SecureArray::operator==(const SecureArray &other) const
|
||||
bool SecureArray::operator==(const MemoryRegion &other) const
|
||||
{
|
||||
if(this == &other)
|
||||
return true;
|
||||
|
@ -99,7 +99,7 @@ void HexUnitTest::testIncrementalUpdate()
|
||||
QCOMPARE( result2[1], '3' );
|
||||
QCOMPARE( result2[2], '6' );
|
||||
QCOMPARE( result2[3], '4' );
|
||||
QCOMPARE( QCA::SecureArray(), hexObject.final() );
|
||||
QCOMPARE( QCA::SecureArray(), QCA::SecureArray(hexObject.final()) );
|
||||
QCOMPARE( hexObject.ok(), true );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user