2004-11-20 06:07:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 Justin Karneges
|
|
|
|
* Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
2005-03-01 02:43:16 +00:00
|
|
|
#include <QtCore>
|
|
|
|
#include <QtCrypto>
|
|
|
|
|
2004-11-20 06:07:03 +00:00
|
|
|
#include <qstringlist.h>
|
|
|
|
#include <gcrypt.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
2005-03-21 07:21:44 +00:00
|
|
|
namespace gcryptQCAPlugin {
|
|
|
|
|
2005-03-26 11:26:56 +00:00
|
|
|
#include "pkcs5.c"
|
2005-03-25 11:07:16 +00:00
|
|
|
|
2004-11-20 06:07:03 +00:00
|
|
|
void check_error( gcry_error_t err )
|
|
|
|
{
|
2004-12-30 08:22:28 +00:00
|
|
|
// we ignore the case where it is not an error, and
|
|
|
|
// we also don't flag weak keys.
|
|
|
|
if ( ( GPG_ERR_NO_ERROR != err ) && ( GPG_ERR_WEAK_KEY != gpg_err_code(err) ) ) {
|
2004-11-20 06:07:03 +00:00
|
|
|
std::cout << "Failure: " ;
|
|
|
|
std::cout << gcry_strsource(err) << "/";
|
|
|
|
std::cout << gcry_strerror(err) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-23 08:51:35 +00:00
|
|
|
class gcryHashContext : public QCA::HashContext
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-11-23 08:51:35 +00:00
|
|
|
gcryHashContext(QCA::Provider *p, const QString &type) : QCA::HashContext(p, type) {};
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
gcry_md_reset( context );
|
|
|
|
}
|
|
|
|
|
|
|
|
void update(const QSecureArray &a)
|
|
|
|
{
|
|
|
|
gcry_md_write( context, a.data(), a.size() );
|
|
|
|
}
|
|
|
|
|
|
|
|
QSecureArray final()
|
|
|
|
{
|
|
|
|
unsigned char *md;
|
|
|
|
QSecureArray a( gcry_md_get_algo_dlen( hashAlgorithm ) );
|
|
|
|
md = gcry_md_read( context, hashAlgorithm );
|
|
|
|
memcpy( a.data(), md, a.size() );
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
gcry_md_hd_t context;
|
|
|
|
gcry_error_t err;
|
|
|
|
int hashAlgorithm;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SHA1Context : public gcryHashContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SHA1Context(QCA::Provider *p) : gcryHashContext(p, "sha1")
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
hashAlgorithm = GCRY_MD_SHA1;
|
|
|
|
err = gcry_md_open( &context, hashAlgorithm, 0 );
|
|
|
|
if ( GPG_ERR_NO_ERROR != err ) {
|
|
|
|
std::cout << "Failure: " ;
|
|
|
|
std::cout << gcry_strsource(err) << "/";
|
|
|
|
std::cout << gcry_strerror(err) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~SHA1Context()
|
|
|
|
{
|
|
|
|
gcry_md_close( context );
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new SHA1Context(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-12-30 08:22:28 +00:00
|
|
|
class MD4Context : public gcryHashContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MD4Context(QCA::Provider *p) : gcryHashContext(p, "md4")
|
|
|
|
{
|
|
|
|
hashAlgorithm = GCRY_MD_MD4;
|
|
|
|
err = gcry_md_open( &context, hashAlgorithm, 0 );
|
|
|
|
if ( GPG_ERR_NO_ERROR != err ) {
|
|
|
|
std::cout << "Failure: " ;
|
|
|
|
std::cout << gcry_strsource(err) << "/";
|
|
|
|
std::cout << gcry_strerror(err) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~MD4Context()
|
|
|
|
{
|
|
|
|
gcry_md_close( context );
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new MD4Context(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class MD5Context : public gcryHashContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MD5Context(QCA::Provider *p) : gcryHashContext(p, "md5")
|
|
|
|
{
|
|
|
|
hashAlgorithm = GCRY_MD_MD5;
|
|
|
|
err = gcry_md_open( &context, hashAlgorithm, 0 );
|
|
|
|
if ( GPG_ERR_NO_ERROR != err ) {
|
|
|
|
std::cout << "Failure: " ;
|
|
|
|
std::cout << gcry_strsource(err) << "/";
|
|
|
|
std::cout << gcry_strerror(err) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~MD5Context()
|
|
|
|
{
|
|
|
|
gcry_md_close( context );
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new MD5Context(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class RIPEMD160Context : public gcryHashContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RIPEMD160Context(QCA::Provider *p) : gcryHashContext(p, "ripemd160")
|
|
|
|
{
|
|
|
|
hashAlgorithm = GCRY_MD_RMD160;
|
|
|
|
err = gcry_md_open( &context, hashAlgorithm, 0 );
|
|
|
|
if ( GPG_ERR_NO_ERROR != err ) {
|
|
|
|
std::cout << "Failure: " ;
|
|
|
|
std::cout << gcry_strsource(err) << "/";
|
|
|
|
std::cout << gcry_strerror(err) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~RIPEMD160Context()
|
|
|
|
{
|
|
|
|
gcry_md_close( context );
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new RIPEMD160Context(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-11-20 06:07:03 +00:00
|
|
|
|
2004-11-23 08:51:35 +00:00
|
|
|
class SHA256Context : public gcryHashContext
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-11-23 08:51:35 +00:00
|
|
|
SHA256Context(QCA::Provider *p) : gcryHashContext(p, "sha256")
|
|
|
|
{
|
|
|
|
hashAlgorithm = GCRY_MD_SHA256;
|
|
|
|
err = gcry_md_open( &context, hashAlgorithm, 0 );
|
|
|
|
if ( GPG_ERR_NO_ERROR != err ) {
|
|
|
|
std::cout << "Failure: " ;
|
|
|
|
std::cout << gcry_strsource(err) << "/";
|
|
|
|
std::cout << gcry_strerror(err) << std::endl;
|
2004-11-20 06:07:03 +00:00
|
|
|
}
|
2004-11-23 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~SHA256Context()
|
|
|
|
{
|
|
|
|
gcry_md_close( context );
|
|
|
|
}
|
2004-11-20 06:07:03 +00:00
|
|
|
|
2004-11-23 08:51:35 +00:00
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new SHA256Context(*this);
|
|
|
|
}
|
2004-11-20 06:07:03 +00:00
|
|
|
};
|
|
|
|
|
2004-11-23 08:51:35 +00:00
|
|
|
class SHA384Context : public gcryHashContext
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-11-23 08:51:35 +00:00
|
|
|
SHA384Context(QCA::Provider *p) : gcryHashContext(p, "sha384")
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
hashAlgorithm = GCRY_MD_SHA384;
|
|
|
|
err = gcry_md_open( &context, hashAlgorithm, 0 );
|
|
|
|
if ( GPG_ERR_NO_ERROR != err ) {
|
|
|
|
std::cout << "Failure: " ;
|
|
|
|
std::cout << gcry_strsource(err) << "/";
|
|
|
|
std::cout << gcry_strerror(err) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~SHA384Context()
|
|
|
|
{
|
|
|
|
gcry_md_close( context );
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new SHA384Context(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 08:51:35 +00:00
|
|
|
class SHA512Context : public gcryHashContext
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-11-23 08:51:35 +00:00
|
|
|
SHA512Context(QCA::Provider *p) : gcryHashContext(p, "sha512")
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
hashAlgorithm = GCRY_MD_SHA512;
|
|
|
|
err = gcry_md_open( &context, hashAlgorithm, 0 );
|
|
|
|
if ( GPG_ERR_NO_ERROR != err ) {
|
|
|
|
std::cout << "Failure: " ;
|
|
|
|
std::cout << gcry_strsource(err) << "/";
|
|
|
|
std::cout << gcry_strerror(err) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~SHA512Context()
|
|
|
|
{
|
|
|
|
gcry_md_close( context );
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new SHA512Context(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-11-23 08:51:35 +00:00
|
|
|
class gcryCipherContext : public QCA::CipherContext
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2005-03-19 06:58:53 +00:00
|
|
|
gcryCipherContext(int algorithm, int mode, bool pad, QCA::Provider *p, const QString &type) : QCA::CipherContext(p, type)
|
|
|
|
{
|
|
|
|
m_cryptoAlgorithm = algorithm;
|
|
|
|
m_mode = mode;
|
|
|
|
m_pad = pad;
|
|
|
|
}
|
2004-11-20 06:07:03 +00:00
|
|
|
|
2005-03-19 01:05:32 +00:00
|
|
|
void setup(QCA::Direction dir,
|
|
|
|
const QCA::SymmetricKey &key,
|
2004-11-27 21:14:42 +00:00
|
|
|
const QCA::InitializationVector &iv)
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
|
|
|
m_direction = dir;
|
2005-03-19 06:58:53 +00:00
|
|
|
err = gcry_cipher_open( &context, m_cryptoAlgorithm, m_mode, 0 );
|
2004-11-20 06:07:03 +00:00
|
|
|
check_error( err );
|
|
|
|
err = gcry_cipher_setkey( context, key.data(), key.size() );
|
|
|
|
check_error( err );
|
|
|
|
err = gcry_cipher_setiv( context, iv.data(), iv.size() );
|
|
|
|
check_error( err );
|
|
|
|
}
|
|
|
|
|
2005-03-19 06:58:53 +00:00
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new gcryCipherContext( *this );
|
|
|
|
}
|
|
|
|
|
2004-11-28 11:15:52 +00:00
|
|
|
unsigned int blockSize() const
|
2004-11-20 06:07:03 +00:00
|
|
|
{
|
2004-11-28 11:15:52 +00:00
|
|
|
unsigned int blockSize;
|
2005-03-19 06:58:53 +00:00
|
|
|
gcry_cipher_algo_info( m_cryptoAlgorithm, GCRYCTL_GET_BLKLEN, 0, (size_t*)&blockSize );
|
2004-11-23 08:51:35 +00:00
|
|
|
return blockSize;
|
2004-11-20 06:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool update(const QSecureArray &in, QSecureArray *out)
|
|
|
|
{
|
|
|
|
QSecureArray result( in.size() );
|
|
|
|
if (QCA::Encode == m_direction) {
|
|
|
|
err = gcry_cipher_encrypt( context, (unsigned char*)result.data(), result.size(), (unsigned char*)in.data(), in.size() );
|
|
|
|
} else {
|
|
|
|
err = gcry_cipher_decrypt( context, (unsigned char*)result.data(), result.size(), (unsigned char*)in.data(), in.size() );
|
|
|
|
}
|
|
|
|
check_error(err );
|
|
|
|
result.resize( in.size() );
|
|
|
|
*out = result;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool final(QSecureArray *out)
|
|
|
|
{
|
2005-03-19 06:58:53 +00:00
|
|
|
QSecureArray result;
|
|
|
|
if (m_pad) {
|
|
|
|
result.resize( blockSize() );
|
|
|
|
if (QCA::Encode == m_direction) {
|
|
|
|
err = gcry_cipher_encrypt( context, (unsigned char*)result.data(), result.size(), NULL, 0 );
|
|
|
|
} else {
|
|
|
|
err = gcry_cipher_decrypt( context, (unsigned char*)result.data(), result.size(), NULL, 0 );
|
|
|
|
}
|
|
|
|
check_error(err );
|
|
|
|
} else {
|
|
|
|
// just return null
|
|
|
|
}
|
|
|
|
*out = result;
|
2004-11-20 06:07:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-11-23 08:51:35 +00:00
|
|
|
QCA::KeyLength keyLength() const
|
|
|
|
{
|
2005-03-19 06:58:53 +00:00
|
|
|
switch (m_cryptoAlgorithm)
|
|
|
|
{
|
|
|
|
case GCRY_CIPHER_DES:
|
|
|
|
return QCA::KeyLength( 8, 8, 1);
|
|
|
|
case GCRY_CIPHER_AES128:
|
|
|
|
return QCA::KeyLength( 16, 16, 1);
|
|
|
|
case GCRY_CIPHER_AES192:
|
|
|
|
case GCRY_CIPHER_3DES:
|
|
|
|
return QCA::KeyLength( 24, 24, 1);
|
|
|
|
case GCRY_CIPHER_AES256:
|
|
|
|
return QCA::KeyLength( 32, 32, 1);
|
|
|
|
case GCRY_CIPHER_BLOWFISH:
|
|
|
|
// Don't know - TODO
|
|
|
|
return QCA::KeyLength( 1, 32, 1);
|
|
|
|
default:
|
|
|
|
return QCA::KeyLength( 0, 1, 1);
|
|
|
|
}
|
2004-11-23 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-19 06:58:53 +00:00
|
|
|
protected:
|
|
|
|
gcry_cipher_hd_t context;
|
|
|
|
gcry_error_t err;
|
|
|
|
int m_cryptoAlgorithm;
|
|
|
|
QCA::Direction m_direction;
|
|
|
|
int m_mode;
|
|
|
|
bool m_pad;
|
2004-11-23 08:51:35 +00:00
|
|
|
};
|
|
|
|
|
2005-03-25 11:07:16 +00:00
|
|
|
class pbkdf2Context : public QCA::KDFContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pbkdf2Context(int algorithm, QCA::Provider *p, const QString &type) : QCA::KDFContext(p, type)
|
|
|
|
{
|
2005-03-26 11:26:56 +00:00
|
|
|
gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
|
|
|
|
m_algorithm = algorithm;
|
2005-03-25 11:07:16 +00:00
|
|
|
}
|
2005-03-21 07:21:44 +00:00
|
|
|
|
2005-03-25 11:07:16 +00:00
|
|
|
Context *clone() const
|
|
|
|
{
|
|
|
|
return new pbkdf2Context( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
QCA::SymmetricKey makeKey(const QSecureArray &secret, const QCA::InitializationVector &salt,
|
|
|
|
unsigned int keyLength, unsigned int iterationCount)
|
|
|
|
{
|
2005-03-26 11:26:56 +00:00
|
|
|
QCA::SymmetricKey result(keyLength);
|
|
|
|
int retval = gcry_pbkdf2(m_algorithm, secret.data(), secret.size(),
|
|
|
|
salt.data(), salt.size(),
|
|
|
|
iterationCount, keyLength, result.data());
|
|
|
|
if (retval == GPG_ERR_NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
std::cout << "got: " << retval << std::endl;
|
|
|
|
return QCA::SymmetricKey();
|
|
|
|
}
|
2005-03-25 11:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_algorithm;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2004-11-23 08:51:35 +00:00
|
|
|
|
2005-03-26 11:26:56 +00:00
|
|
|
// #define I_WANT_TO_CRASH 1
|
|
|
|
#ifdef I_WANT_TO_CRASH
|
|
|
|
static void * qca_func_malloc(size_t n)
|
|
|
|
{
|
|
|
|
return qca_secure_alloc(n);
|
|
|
|
};
|
|
|
|
|
|
|
|
static void * qca_func_secure_malloc(size_t n)
|
|
|
|
{
|
|
|
|
return qca_secure_alloc(n);
|
|
|
|
};
|
|
|
|
|
|
|
|
static void * qca_func_realloc(void *oldBlock, size_t newBlockSize)
|
|
|
|
{
|
|
|
|
std::cout << "re-alloc: " << newBlockSize << std::endl;
|
|
|
|
if (oldBlock == NULL) {
|
|
|
|
return qca_secure_alloc(newBlockSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// backtrack to read the size value
|
|
|
|
char *c = (char *)oldBlock;
|
|
|
|
c -= sizeof(int);
|
|
|
|
size_t oldBlockSize = ((size_t *)c)[0];
|
|
|
|
|
|
|
|
char *newBlock = (char *)qca_secure_alloc(newBlockSize);
|
|
|
|
if (newBlockSize < oldBlockSize) {
|
|
|
|
memcpy(newBlock, oldBlock, newBlockSize);
|
|
|
|
} else { // oldBlock is smaller
|
|
|
|
memcpy(newBlock, oldBlock, oldBlockSize);
|
|
|
|
}
|
|
|
|
qca_secure_free(oldBlock);
|
|
|
|
return newBlock;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void qca_func_free(void *mem)
|
|
|
|
{
|
|
|
|
qca_secure_free(mem);
|
|
|
|
};
|
|
|
|
|
|
|
|
int qca_func_secure_check (const void *)
|
|
|
|
{
|
|
|
|
return (int)QCA::haveSecureMemory();
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2005-03-19 06:58:53 +00:00
|
|
|
class gcryptProvider : public QCA::Provider
|
2004-11-23 08:51:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2005-03-19 06:58:53 +00:00
|
|
|
void init()
|
2004-11-23 08:51:35 +00:00
|
|
|
{
|
2005-03-26 11:26:56 +00:00
|
|
|
if (!gcry_control (GCRYCTL_ANY_INITIALIZATION_P))
|
|
|
|
{ /* No other library has already initialized libgcrypt. */
|
|
|
|
|
|
|
|
if (!gcry_check_version (GCRYPT_VERSION) )
|
|
|
|
{
|
|
|
|
std::cout << "libgcrypt is too old (need " << GCRYPT_VERSION;
|
|
|
|
std::cout << ", have " << gcry_check_version(NULL) << ")" << std::endl;
|
|
|
|
}
|
|
|
|
#ifdef I_WANT_TO_CRASH
|
|
|
|
gcry_set_allocation_handler (qca_func_malloc,
|
|
|
|
qca_func_secure_malloc,
|
|
|
|
qca_func_secure_check,
|
|
|
|
qca_func_realloc,
|
|
|
|
qca_func_free);
|
|
|
|
#endif
|
|
|
|
gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
|
|
|
|
}
|
2004-11-23 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
2005-03-19 06:58:53 +00:00
|
|
|
QString name() const
|
2004-11-23 08:51:35 +00:00
|
|
|
{
|
2005-03-19 06:58:53 +00:00
|
|
|
return "qca-gcrypt";
|
2004-11-23 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
2005-03-19 06:58:53 +00:00
|
|
|
QStringList features() const
|
2004-11-23 08:51:35 +00:00
|
|
|
{
|
2005-03-19 06:58:53 +00:00
|
|
|
QStringList list;
|
|
|
|
list += "sha1";
|
|
|
|
list += "md4";
|
|
|
|
list += "md5";
|
|
|
|
list += "ripemd160";
|
|
|
|
list += "sha256";
|
|
|
|
list += "sha384";
|
|
|
|
list += "sha512";
|
|
|
|
list += "aes128-ecb";
|
|
|
|
list += "aes128-cfb";
|
|
|
|
list += "aes128-cbc";
|
|
|
|
list += "aes192-ecb";
|
|
|
|
list += "aes192-cfb";
|
|
|
|
list += "aes192-cbc";
|
|
|
|
list += "aes256-ecb";
|
|
|
|
list += "aes256-cfb";
|
|
|
|
list += "aes256-cbc";
|
|
|
|
list += "blowfish-ecb";
|
|
|
|
list += "tripledes-ecb";
|
|
|
|
list += "des-ecb";
|
2005-03-25 11:07:16 +00:00
|
|
|
list += "pbkdf2(sha1)";
|
2005-03-19 06:58:53 +00:00
|
|
|
return list;
|
2004-11-23 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
2005-03-19 06:58:53 +00:00
|
|
|
Context *createContext(const QString &type)
|
2004-11-28 11:15:52 +00:00
|
|
|
{
|
2005-03-25 11:07:16 +00:00
|
|
|
// std::cout << "type: " << qPrintable(type) << std::endl;
|
2005-03-19 06:58:53 +00:00
|
|
|
if ( type == "sha1" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::SHA1Context( this );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "md4" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::MD4Context( this );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "md5" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::MD5Context( this );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "ripemd160" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::RIPEMD160Context( this );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "sha256" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::SHA256Context( this );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "sha384" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::SHA384Context( this );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "sha512" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::SHA512Context( this );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes128-ecb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes128-cfb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CFB, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes128-cbc" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes192-ecb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_ECB, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes192-cfb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CFB, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes192-cbc" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes256-ecb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_ECB, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes256-cfb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "aes256-cbc" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "blowfish-ecb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_ECB, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "tripledes-ecb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_ECB, false, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else if ( type == "des-ecb" )
|
2005-03-25 11:07:16 +00:00
|
|
|
return new gcryptQCAPlugin::gcryCipherContext( GCRY_CIPHER_DES, GCRY_CIPHER_MODE_ECB, false, this, type );
|
|
|
|
else if ( type == "pbkdf2(sha1)" )
|
|
|
|
return new gcryptQCAPlugin::pbkdf2Context( GCRY_MD_SHA1, this, type );
|
2005-03-19 06:58:53 +00:00
|
|
|
else
|
|
|
|
return 0;
|
2004-11-28 11:15:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-03-01 02:43:16 +00:00
|
|
|
class gcryptPlugin : public QCAPlugin
|
|
|
|
{
|
2005-03-19 06:58:53 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
virtual int version() const { return QCA_PLUGIN_VERSION; }
|
|
|
|
virtual QCA::Provider *createProvider() { return new gcryptProvider; }
|
2005-03-01 02:43:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#include "qca-gcrypt.moc"
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(gcryptPlugin);
|
|
|
|
|