mirror of
https://github.com/QuasarApp/qca.git
synced 2025-05-12 18:49:34 +00:00
dsa signature format option
svn path=/trunk/kdesupport/qca/; revision=395131
This commit is contained in:
parent
759bf1005a
commit
c579f4b56d
@ -72,6 +72,16 @@ namespace QCA
|
||||
EMSA3_RIPEMD160 ///< RIPEMD160, with EMSA3 (ie PKCS1 Version 1.5) encoding
|
||||
};
|
||||
|
||||
/**
|
||||
Signature formats (DSA only)
|
||||
*/
|
||||
enum SignatureFormat
|
||||
{
|
||||
DefaultFormat, ///< For DSA, this is the same as IEEE_1363
|
||||
IEEE_1363, ///< 40-byte format from IEEE 1363 (Botan/.NET)
|
||||
DERSequence ///< Signature wrapped in DER formatting (OpenSSL/Java)
|
||||
};
|
||||
|
||||
/**
|
||||
Password-based encryption
|
||||
*/
|
||||
@ -159,11 +169,11 @@ namespace QCA
|
||||
|
||||
// encrypt / verify
|
||||
int maximumEncryptSize(EncryptionAlgorithm alg) const;
|
||||
QSecureArray encrypt(EncryptionAlgorithm alg, const QSecureArray &a) const;
|
||||
void startVerify(SignatureAlgorithm alg);
|
||||
QSecureArray encrypt(const QSecureArray &a, EncryptionAlgorithm alg) const;
|
||||
void startVerify(SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
||||
void update(const QSecureArray &a);
|
||||
bool validSignature(const QSecureArray &sig);
|
||||
bool verifyMessage(SignatureAlgorithm alg, const QSecureArray &a, const QSecureArray &sig);
|
||||
bool verifyMessage(const QSecureArray &a, const QSecureArray &sig, SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
||||
|
||||
// import / export
|
||||
QSecureArray toDER() const;
|
||||
@ -191,11 +201,11 @@ namespace QCA
|
||||
bool canSign() const;
|
||||
|
||||
// decrypt / sign / key agreement
|
||||
bool decrypt(EncryptionAlgorithm alg, const QSecureArray &in, QSecureArray *out) const;
|
||||
void startSign(SignatureAlgorithm alg);
|
||||
void update(const QSecureArray &);
|
||||
bool decrypt(const QSecureArray &in, QSecureArray *out, EncryptionAlgorithm alg) const;
|
||||
void startSign(SignatureAlgorithm alg, SignatureFormat format = DefaultFormat);
|
||||
void update(const QSecureArray &a);
|
||||
QSecureArray signature();
|
||||
QSecureArray signMessage(SignatureAlgorithm alg, const QSecureArray &a);
|
||||
QSecureArray signMessage(const QSecureArray &a, SignatureAlgorithm alg, SignatureFormat = DefaultFormat);
|
||||
SymmetricKey deriveKey(const PublicKey &theirs) const;
|
||||
|
||||
// import / export
|
||||
|
@ -127,12 +127,12 @@ public:
|
||||
|
||||
// encrypt/decrypt
|
||||
virtual int maximumEncryptSize(EncryptionAlgorithm alg) const;
|
||||
virtual QSecureArray encrypt(EncryptionAlgorithm alg, const QSecureArray &in) const;
|
||||
virtual bool decrypt(EncryptionAlgorithm alg, const QSecureArray &in, QSecureArray *out) const;
|
||||
virtual QSecureArray encrypt(const QSecureArray &in, EncryptionAlgorithm alg) const;
|
||||
virtual bool decrypt(const QSecureArray &in, QSecureArray *out, EncryptionAlgorithm alg) const;
|
||||
|
||||
// sign / verify
|
||||
virtual void startSign(SignatureAlgorithm alg);
|
||||
virtual void startVerify(SignatureAlgorithm alg);
|
||||
virtual void startSign(SignatureAlgorithm alg, SignatureFormat format);
|
||||
virtual void startVerify(SignatureAlgorithm alg, SignatureFormat format);
|
||||
virtual void update(const QSecureArray &in);
|
||||
virtual QSecureArray endSign();
|
||||
virtual bool endVerify(const QSecureArray &sig);
|
||||
|
@ -393,21 +393,21 @@ int PKeyBase::maximumEncryptSize(EncryptionAlgorithm) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
QSecureArray PKeyBase::encrypt(EncryptionAlgorithm, const QSecureArray &) const
|
||||
QSecureArray PKeyBase::encrypt(const QSecureArray &, EncryptionAlgorithm) const
|
||||
{
|
||||
return QSecureArray();
|
||||
}
|
||||
|
||||
bool PKeyBase::decrypt(EncryptionAlgorithm, const QSecureArray &, QSecureArray *) const
|
||||
bool PKeyBase::decrypt(const QSecureArray &, QSecureArray *, EncryptionAlgorithm) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void PKeyBase::startSign(SignatureAlgorithm)
|
||||
void PKeyBase::startSign(SignatureAlgorithm, SignatureFormat)
|
||||
{
|
||||
}
|
||||
|
||||
void PKeyBase::startVerify(SignatureAlgorithm)
|
||||
void PKeyBase::startVerify(SignatureAlgorithm, SignatureFormat)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -307,14 +307,16 @@ int PublicKey::maximumEncryptSize(EncryptionAlgorithm alg) const
|
||||
return static_cast<const PKeyContext *>(context())->key()->maximumEncryptSize(alg);
|
||||
}
|
||||
|
||||
QSecureArray PublicKey::encrypt(EncryptionAlgorithm alg, const QSecureArray &a) const
|
||||
QSecureArray PublicKey::encrypt(const QSecureArray &a, EncryptionAlgorithm alg) const
|
||||
{
|
||||
return static_cast<const PKeyContext *>(context())->key()->encrypt(alg, a);
|
||||
return static_cast<const PKeyContext *>(context())->key()->encrypt(a, alg);
|
||||
}
|
||||
|
||||
void PublicKey::startVerify(SignatureAlgorithm alg)
|
||||
void PublicKey::startVerify(SignatureAlgorithm alg, SignatureFormat format)
|
||||
{
|
||||
static_cast<PKeyContext *>(context())->key()->startVerify(alg);
|
||||
if(isDSA() && format == DefaultFormat)
|
||||
format = IEEE_1363;
|
||||
static_cast<PKeyContext *>(context())->key()->startVerify(alg, format);
|
||||
}
|
||||
|
||||
void PublicKey::update(const QSecureArray &a)
|
||||
@ -327,9 +329,9 @@ bool PublicKey::validSignature(const QSecureArray &sig)
|
||||
return static_cast<PKeyContext *>(context())->key()->endVerify(sig);
|
||||
}
|
||||
|
||||
bool PublicKey::verifyMessage(SignatureAlgorithm alg, const QSecureArray &a, const QSecureArray &sig)
|
||||
bool PublicKey::verifyMessage(const QSecureArray &a, const QSecureArray &sig, SignatureAlgorithm alg, SignatureFormat format)
|
||||
{
|
||||
startVerify(alg);
|
||||
startVerify(alg, format);
|
||||
update(a);
|
||||
return validSignature(sig);
|
||||
}
|
||||
@ -427,14 +429,16 @@ bool PrivateKey::canSign() const
|
||||
return (isRSA() || isDSA());
|
||||
}
|
||||
|
||||
bool PrivateKey::decrypt(EncryptionAlgorithm alg, const QSecureArray &in, QSecureArray *out) const
|
||||
bool PrivateKey::decrypt(const QSecureArray &in, QSecureArray *out, EncryptionAlgorithm alg) const
|
||||
{
|
||||
return static_cast<const PKeyContext *>(context())->key()->decrypt(alg, in, out);
|
||||
return static_cast<const PKeyContext *>(context())->key()->decrypt(in, out, alg);
|
||||
}
|
||||
|
||||
void PrivateKey::startSign(SignatureAlgorithm alg)
|
||||
void PrivateKey::startSign(SignatureAlgorithm alg, SignatureFormat format)
|
||||
{
|
||||
static_cast<PKeyContext *>(context())->key()->startSign(alg);
|
||||
if(isDSA() && format == DefaultFormat)
|
||||
format = IEEE_1363;
|
||||
static_cast<PKeyContext *>(context())->key()->startSign(alg, format);
|
||||
}
|
||||
|
||||
void PrivateKey::update(const QSecureArray &a)
|
||||
@ -447,9 +451,9 @@ QSecureArray PrivateKey::signature()
|
||||
return static_cast<PKeyContext *>(context())->key()->endSign();
|
||||
}
|
||||
|
||||
QSecureArray PrivateKey::signMessage(SignatureAlgorithm alg, const QSecureArray &a)
|
||||
QSecureArray PrivateKey::signMessage(const QSecureArray &a, SignatureAlgorithm alg, SignatureFormat format)
|
||||
{
|
||||
startSign(alg);
|
||||
startSign(alg, format);
|
||||
update(a);
|
||||
return signature();
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ QSecureArray Hex::update(const QSecureArray &a)
|
||||
flag = true;
|
||||
}
|
||||
|
||||
QByteArray out(a.size() / 2, 0);
|
||||
QSecureArray out(a.size() / 2);
|
||||
int at = 0;
|
||||
int c;
|
||||
for(int n = 0; n < (int)a.size(); ++n)
|
||||
|
Loading…
x
Reference in New Issue
Block a user