4
0
mirror of https://github.com/QuasarApp/qca.git synced 2025-05-09 17:29:33 +00:00

remove unnecessary secure array usage in pkey api

svn path=/trunk/kdesupport/qca/; revision=674761
This commit is contained in:
Justin Karneges 2007-06-12 23:49:25 +00:00
parent 213edd7685
commit 2db0ae1fcb
8 changed files with 58 additions and 58 deletions
examples/rsatest
include/QtCrypto
plugins
qca-openssl
qca-pkcs11
qca-softstore
src

@ -113,7 +113,7 @@ int main(int argc, char **argv)
}
privateKey.startSign( QCA::EMSA3_MD5 );
privateKey.update( arg ); // just reuse the same message
QCA::SecureArray argSig = privateKey.signature();
QByteArray argSig = privateKey.signature();
// instead of using the startSign(), update(), signature() calls,
// you may be better doing the whole thing in one go, using the

@ -139,7 +139,7 @@ enum DLGroupSet
function of QCA and does not utilize a provider. SHA1, MD5, MD2,
and RIPEMD160 are supported.
*/
QCA_EXPORT SecureArray emsa3Encode(const QString &hashName, const SecureArray &digest, int size = -1);
QCA_EXPORT QByteArray emsa3Encode(const QString &hashName, const QByteArray &digest, int size = -1);
/**
\class DLGroup qca_publickey.h QtCrypto
@ -609,7 +609,7 @@ if( pubkey.canVerify() )
\return true if the signature is correct
*/
bool validSignature(const SecureArray &sig);
bool validSignature(const QByteArray &sig);
/**
Single step message verification
@ -624,12 +624,12 @@ if( pubkey.canVerify() )
\return true if the signature is valid for the message
*/
bool verifyMessage(const SecureArray &a, const SecureArray &sig, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
bool verifyMessage(const SecureArray &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
/**
Export the key in Distinguished Encoding Rules (DER) format
*/
SecureArray toDER() const;
QByteArray toDER() const;
/**
Export the key in Privacy Enhanced Mail (PEM) format
@ -676,7 +676,7 @@ if (! QCA::ConvertGood == conversionResult)
conversion succeeded (ConvertGood) or not
\param provider the name of the provider to use for the import.
*/
static PublicKey fromDER(const SecureArray &a, ConvertResult *result = 0, const QString &provider = QString());
static PublicKey fromDER(const QByteArray &a, ConvertResult *result = 0, const QString &provider = QString());
/**
Import a key in Privacy Enhanced Mail (PEM) format
@ -858,7 +858,7 @@ public:
\note This synchronous operation may require event handling, and so
it must not be called from the same thread as an EventHandler.
*/
SecureArray signature();
QByteArray signature();
/**
One step signature process
@ -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.
*/
SecureArray signMessage(const SecureArray &a, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
QByteArray signMessage(const SecureArray &a, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
/**
Derive a shared secret key from a public key

@ -138,8 +138,8 @@ public:
virtual void startSign(SignatureAlgorithm alg, SignatureFormat format);
virtual void startVerify(SignatureAlgorithm alg, SignatureFormat format);
virtual void update(const SecureArray &in);
virtual SecureArray endSign();
virtual bool endVerify(const SecureArray &sig);
virtual QByteArray endSign();
virtual bool endVerify(const QByteArray &sig);
// key agreement
virtual SymmetricKey deriveKey(const PKeyBase &theirs);
@ -205,9 +205,9 @@ public:
virtual bool importKey(const PKeyBase *key) = 0;
// import / export
virtual SecureArray publicToDER() const;
virtual QByteArray publicToDER() const;
virtual QString publicToPEM() const;
virtual ConvertResult publicFromDER(const SecureArray &a);
virtual ConvertResult publicFromDER(const QByteArray &a);
virtual ConvertResult publicFromPEM(const QString &s);
virtual SecureArray privateToDER(const SecureArray &passphrase, PBEAlgorithm pbe) const;
virtual QString privateToPEM(const SecureArray &passphrase, PBEAlgorithm pbe) const;

@ -1770,12 +1770,12 @@ public:
evp.update(in);
}
virtual SecureArray endSign()
virtual QByteArray endSign()
{
return evp.endSign();
return evp.endSign().toByteArray();
}
virtual bool endVerify(const SecureArray &sig)
virtual bool endVerify(const QByteArray &sig)
{
return evp.endVerify(sig);
}
@ -2039,16 +2039,16 @@ public:
evp.update(in);
}
virtual SecureArray endSign()
virtual QByteArray endSign()
{
SecureArray out = evp.endSign();
if(transformsig)
return dsasig_der_to_raw(out);
return dsasig_der_to_raw(out).toByteArray();
else
return out;
return out.toByteArray();
}
virtual bool endVerify(const SecureArray &sig)
virtual bool endVerify(const QByteArray &sig)
{
SecureArray in;
if(transformsig)
@ -2644,17 +2644,17 @@ public:
return 0;
}
virtual SecureArray publicToDER() const
virtual QByteArray publicToDER() const
{
EVP_PKEY *pkey = get_pkey();
// OpenSSL does not have DH import/export support
if(pkey->type == EVP_PKEY_DH)
return SecureArray();
return QByteArray();
BIO *bo = BIO_new(BIO_s_mem());
i2d_PUBKEY_bio(bo, pkey);
SecureArray buf = bio2buf(bo);
QByteArray buf = bio2ba(bo);
return buf;
}
@ -2668,11 +2668,11 @@ public:
BIO *bo = BIO_new(BIO_s_mem());
PEM_write_bio_PUBKEY(bo, pkey);
SecureArray buf = bio2buf(bo);
return QString::fromLatin1(buf.toByteArray());
QByteArray buf = bio2ba(bo);
return QString::fromLatin1(buf);
}
virtual ConvertResult publicFromDER(const SecureArray &in)
virtual ConvertResult publicFromDER(const QByteArray &in)
{
delete k;
k = 0;

@ -428,7 +428,7 @@ private:
struct _sign_data_s {
SignatureAlgorithm alg;
Hash *hash;
SecureArray raw;
QByteArray raw;
_sign_data_s() {
hash = NULL;
@ -776,7 +776,7 @@ public:
_sign_data.hash->update (in);
}
else {
_sign_data.raw.append (in);
_sign_data.raw.append (in.toByteArray ());
}
}
else {
@ -785,9 +785,9 @@ public:
}
virtual
SecureArray
QByteArray
endSign () {
SecureArray result;
QByteArray result;
bool session_locked = false;
QCA_logTextMessage (
@ -796,7 +796,7 @@ public:
);
try {
SecureArray final;
QByteArray final;
CK_RV rv;
// from some strange reason I got 2047... (for some) <---- BUG?!?!?!
@ -805,7 +805,7 @@ public:
if (_sign_data.hash != NULL) {
final = emsa3Encode (
_sign_data.hash->type (),
_sign_data.hash->final (),
_sign_data.hash->final ().toByteArray (),
myrsa_size
);
}
@ -907,7 +907,7 @@ public:
virtual
bool
validSignature (
const SecureArray &sig
const QByteArray &sig
) {
return _pubkey.validSignature (sig);
}
@ -1146,7 +1146,7 @@ public:
}
virtual
SecureArray
QByteArray
publicToDER () const {
return static_cast<pkcs11RSAContext *>(_k)->_publicKey ().toDER ();
}
@ -1160,7 +1160,7 @@ public:
virtual
ConvertResult
publicFromDER (
const SecureArray &in
const QByteArray &in
) {
Q_UNUSED(in);
return ErrorDecode;

@ -246,9 +246,9 @@ public:
}
virtual
SecureArray
QByteArray
endSign () {
SecureArray r = _privkeySign.signature ();
QByteArray r = _privkeySign.signature ();
_privkeySign = RSAPrivateKey ();
return r;
}
@ -256,7 +256,7 @@ public:
virtual
bool
validSignature (
const SecureArray &sig
const QByteArray &sig
) {
return _pubkey.validSignature (sig);
}
@ -596,7 +596,7 @@ public:
}
virtual
SecureArray
QByteArray
publicToDER () const {
return static_cast<softstoreRSAContext *>(_k)->_publicKey ().toDER ();
}
@ -610,7 +610,7 @@ public:
virtual
ConvertResult
publicFromDER (
const SecureArray &in
const QByteArray &in
) {
Q_UNUSED(in);
return ErrorDecode;

@ -895,12 +895,12 @@ void PKeyBase::update(const SecureArray &)
{
}
SecureArray PKeyBase::endSign()
QByteArray PKeyBase::endSign()
{
return SecureArray();
return QByteArray();
}
bool PKeyBase::endVerify(const SecureArray &)
bool PKeyBase::endVerify(const QByteArray &)
{
return false;
}
@ -913,9 +913,9 @@ SymmetricKey PKeyBase::deriveKey(const PKeyBase &)
//----------------------------------------------------------------------------
// PKeyContext
//----------------------------------------------------------------------------
SecureArray PKeyContext::publicToDER() const
QByteArray PKeyContext::publicToDER() const
{
return SecureArray();
return QByteArray();
}
QString PKeyContext::publicToPEM() const
@ -923,7 +923,7 @@ QString PKeyContext::publicToPEM() const
return QString();
}
ConvertResult PKeyContext::publicFromDER(const SecureArray &)
ConvertResult PKeyContext::publicFromDER(const QByteArray &)
{
return ErrorDecode;
}

@ -171,7 +171,7 @@ class Getter_PublicKey
{
public:
// DER
static ConvertResult fromData(PKeyContext *c, const SecureArray &in)
static ConvertResult fromData(PKeyContext *c, const QByteArray &in)
{
return c->publicFromDER(in);
}
@ -421,11 +421,11 @@ QByteArray get_hash_id(const QString &name)
return QByteArray();
}
SecureArray emsa3Encode(const QString &hashName, const SecureArray &digest, int size)
QByteArray emsa3Encode(const QString &hashName, const QByteArray &digest, int size)
{
QByteArray hash_id = get_hash_id(hashName);
if(hash_id.isEmpty())
return SecureArray();
return QByteArray();
// logic adapted from Botan
int basesize = hash_id.size() + digest.size() + 2;
@ -433,9 +433,9 @@ SecureArray emsa3Encode(const QString &hashName, const SecureArray &digest, int
size = basesize + 1; // default to 1-byte pad
int padlen = size - basesize;
if(padlen < 1)
return SecureArray();
return QByteArray();
SecureArray out(size, (char)0xff); // pad with 0xff
QByteArray out(size, (char)0xff); // pad with 0xff
out[0] = 0x01;
out[padlen + 1] = 0x00;
int at = padlen + 2;
@ -808,21 +808,21 @@ void PublicKey::update(const SecureArray &a)
static_cast<PKeyContext *>(context())->key()->update(a);
}
bool PublicKey::validSignature(const SecureArray &sig)
bool PublicKey::validSignature(const QByteArray &sig)
{
return static_cast<PKeyContext *>(context())->key()->endVerify(sig);
}
bool PublicKey::verifyMessage(const SecureArray &a, const SecureArray &sig, SignatureAlgorithm alg, SignatureFormat format)
bool PublicKey::verifyMessage(const SecureArray &a, const QByteArray &sig, SignatureAlgorithm alg, SignatureFormat format)
{
startVerify(alg, format);
update(a);
return validSignature(sig);
}
SecureArray PublicKey::toDER() const
QByteArray PublicKey::toDER() const
{
SecureArray out;
QByteArray out;
Provider *p = providerForIOType(type());
if(!p)
return out;
@ -867,9 +867,9 @@ bool PublicKey::toPEMFile(const QString &fileName) const
return stringToFile(fileName, toPEM());
}
PublicKey PublicKey::fromDER(const SecureArray &a, ConvertResult *result, const QString &provider)
PublicKey PublicKey::fromDER(const QByteArray &a, ConvertResult *result, const QString &provider)
{
return getKey<PublicKey, Getter_PublicKey<SecureArray>, SecureArray>(provider, a, SecureArray(), result);
return getKey<PublicKey, Getter_PublicKey<QByteArray>, QByteArray>(provider, a, SecureArray(), result);
}
PublicKey PublicKey::fromPEM(const QString &s, ConvertResult *result, const QString &provider)
@ -963,12 +963,12 @@ void PrivateKey::update(const SecureArray &a)
static_cast<PKeyContext *>(context())->key()->update(a);
}
SecureArray PrivateKey::signature()
QByteArray PrivateKey::signature()
{
return static_cast<PKeyContext *>(context())->key()->endSign();
}
SecureArray PrivateKey::signMessage(const SecureArray &a, SignatureAlgorithm alg, SignatureFormat format)
QByteArray PrivateKey::signMessage(const SecureArray &a, SignatureAlgorithm alg, SignatureFormat format)
{
startSign(alg, format);
update(a);