Initial cut-over to the new padding approach. We still don't actually

support PKCS7, but I'll try to finish that off today.

This also brings in some API docs changes that I had lying around, they
aren't related, but I was too lazy to split it out.

svn path=/trunk/kdesupport/qca/; revision=366744
This commit is contained in:
Brad Hards 2004-11-27 21:14:42 +00:00
parent 382daa7c1a
commit 15b15a266e
5 changed files with 28 additions and 28 deletions

View File

@ -198,11 +198,9 @@ public:
void setup(const QCA::SymmetricKey &key,
QCA::CipherContext::Mode m,
QCA::Direction dir,
const QCA::InitializationVector &iv,
bool pad)
const QCA::InitializationVector &iv)
{
m_direction = dir;
m_pad = pad;
err = gcry_cipher_open( &context, cryptoAlgorithm, gcry_mode(m), 0 );
check_error( err );
err = gcry_cipher_setkey( context, key.data(), key.size() );
@ -234,20 +232,13 @@ public:
bool final(QSecureArray *out)
{
if (m_pad) {
// TODO - we need to pad
// abort();
} else {
*out = QSecureArray();
}
*out = QSecureArray();
return true;
}
protected:
gcry_cipher_hd_t context;
gcry_error_t err;
bool m_pad;
int cryptoAlgorithm;
QCA::Direction m_direction;
};

View File

@ -400,7 +400,7 @@ INPUT =
# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp
# *.h++ *.idl *.odl *.cs *.php *.php3 *.inc
FILE_PATTERNS = *.h
FILE_PATTERNS = *.h *.doco
# The RECURSIVE tag can be used to turn specify whether or not subdirectories
# should be searched for input files as well. Possible values are YES and NO.
@ -434,7 +434,7 @@ EXCLUDE_PATTERNS = *.moc.* \
# directories that contain example code fragments that are included (see
# the \include command).
EXAMPLE_PATH =
EXAMPLE_PATH = ../examples/hashtest
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp

View File

@ -75,7 +75,7 @@ class QCA_CertContext;
* - X509 certificate (Cert) (TBC)
* - Simple Authentication and Security Layer (SASL) (TBC)
* - RSA (TBC)
* - Hashing
* - Hashing (QCA::Hash)
* - QCA::SHA0
* - QCA::SHA1
* - QCA::MD2
@ -85,7 +85,7 @@ class QCA_CertContext;
* - QCA::SHA256
* - QCA::SHA384
* - QCA::SHA512
* - Ciphers
* - Ciphers (QCA::Cipher)
* - BlowFish (QCA::BlowFish)
* - Triple DES (QCA::TripleDES)
* - AES (QCA::AES128, QCA::AES192, QCA::AES256)
@ -1479,6 +1479,15 @@ namespace QCA
ECB ///< operate in Electronic Code Book mode
};
/**
* Padding variations for cipher algorithms
*/
enum Padding
{
NoPadding, ///< Do no padding
PKCS7 ///< Pad using the scheme in PKCS#7
};
/**
* Standard copy constructor
*/
@ -1529,10 +1538,10 @@ namespace QCA
// note: padding only applies to CBC and ECB. CFB ciphertext is
// always the length of the plaintext.
void setup(Mode m, Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector(), bool pad = true);
void setup(Mode m, Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector(), Padding pad = PKCS7);
protected:
Cipher(const QString &type, Mode m, Direction dir, const SymmetricKey &key, const InitializationVector &iv, bool pad, const QString &provider);
Cipher(const QString &type, Mode m, Direction dir, const SymmetricKey &key, const InitializationVector &iv, Padding pad, const QString &provider);
private:
class Private;
@ -2033,7 +2042,7 @@ namespace QCA
* \param provider the provider to use (eg "qca-gcrypt" )
*
*/
BlowFish(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), bool pad = true, const QString &provider = "")
BlowFish(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), Padding pad = PKCS7, const QString &provider = "")
:Cipher("blowfish", m, dir, key, iv, pad, provider) {}
};
@ -2058,7 +2067,7 @@ namespace QCA
*
*/
public:
TripleDES(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), bool pad = true, const QString &provider = "")
TripleDES(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), Padding pad = PKCS7, const QString &provider = "")
:Cipher("tripledes", m, dir, key, iv, pad, provider) {}
};
@ -2083,7 +2092,7 @@ namespace QCA
* \param provider the provider to use (eg "qca-gcrypt" )
*
*/
AES128(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), bool pad = true, const QString &provider = "")
AES128(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), Padding pad = PKCS7, const QString &provider = "")
:Cipher("aes128", m, dir, key, iv, pad, provider) {}
};
@ -2108,7 +2117,7 @@ namespace QCA
* \param provider the provider to use (eg "qca-gcrypt" )
*
*/
AES192(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), bool pad = true, const QString &provider = "")
AES192(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), Padding pad = PKCS7, const QString &provider = "")
:Cipher("aes192", m, dir, key, iv, pad, provider) {}
};
@ -2133,7 +2142,7 @@ namespace QCA
* \param provider the provider to use (eg "qca-gcrypt" )
*
*/
AES256(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), bool pad = true, const QString &provider = "")
AES256(Mode m = CBC, Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), const InitializationVector &iv = InitializationVector(), Padding pad = PKCS7, const QString &provider = "")
:Cipher("aes256", m, dir, key, iv, pad, provider) {}
};

View File

@ -145,13 +145,13 @@ public:
Mode mode;
Direction dir;
SymmetricKey key;
QSecureArray iv;
bool pad;
InitializationVector iv;
Padding pad;
bool ok, done;
};
Cipher::Cipher(const QString &type, Mode m, Direction dir, const SymmetricKey &key, const InitializationVector &iv, bool pad, const QString &provider)
Cipher::Cipher(const QString &type, Mode m, Direction dir, const SymmetricKey &key, const InitializationVector &iv, Padding pad, const QString &provider)
:Algorithm(type, provider)
{
d = new Private;
@ -196,7 +196,7 @@ void Cipher::clear()
{
detach();
d->done = false;
((CipherContext *)context())->setup(d->key, (CipherContext::Mode)d->mode, d->dir, d->iv, d->pad);
((CipherContext *)context())->setup(d->key, (CipherContext::Mode)d->mode, d->dir, d->iv);
}
QSecureArray Cipher::update(const QSecureArray &a)
@ -225,7 +225,7 @@ bool Cipher::ok() const
return d->ok;
}
void Cipher::setup(Mode m, Direction dir, const SymmetricKey &key, const InitializationVector &iv, bool pad)
void Cipher::setup(Mode m, Direction dir, const SymmetricKey &key, const InitializationVector &iv, Padding pad)
{
d->mode = m;
d->dir = dir;

View File

@ -76,7 +76,7 @@ class CipherContext : public Provider::Context
public:
enum Mode { CBC, CFB, ECB };
CipherContext(Provider *p, const QString &type) : Provider::Context(p, type) {}
virtual void setup(const SymmetricKey &key, Mode m, Direction dir, const InitializationVector &iv, bool pad) = 0;
virtual void setup(const SymmetricKey &key, Mode m, Direction dir, const InitializationVector &iv) = 0;
virtual KeyLength keyLength() const = 0;
virtual int blockSize() const = 0;