qca_basic.h
Go to the documentation of this file.
/*
* qca_basic.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2007 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004-2007 Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2013-2016 Ivan Romanov <drizt@land.ru>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef QCA_BASIC_H
#define QCA_BASIC_H
#include "qca_core.h"
#include <QIODevice>
namespace QCA {
class QCA_EXPORT Random : public Algorithm
{
public:
Random(const QString &provider = QString());
Random(const Random &from);
~Random() override;
Random &operator=(const Random &from);
uchar nextByte();
SecureArray nextBytes(int size);
static uchar randomChar();
static int randomInt();
static SecureArray randomArray(int size);
private:
class Private;
Private *d;
};
class QCA_EXPORT Hash : public Algorithm, public BufferedComputation
{
public:
explicit Hash(const QString &type, const QString &provider = QString());
Hash(const Hash &from);
~Hash() override;
Hash &operator=(const Hash &from);
static QStringList supportedTypes(const QString &provider = QString());
QString type() const;
void clear() override;
void update(const MemoryRegion &a) override;
void update(const QByteArray &a);
void update(const char *data, int len = -1);
void update(QIODevice *file);
MemoryRegion final() override;
MemoryRegion hash(const MemoryRegion &array);
QString hashToString(const MemoryRegion &array);
private:
class Private;
Private *d;
};
class QCA_EXPORT Cipher : public Algorithm, public Filter
{
public:
enum Mode
{
CBC,
CFB,
ECB,
OFB,
CTR,
GCM,
CCM
};
enum Padding
{
DefaultPadding,
NoPadding,
PKCS7
};
Cipher(const QString &type,
Mode mode,
Padding pad = DefaultPadding,
Direction dir = Encode,
const SymmetricKey &key = SymmetricKey(),
const InitializationVector &iv = InitializationVector(),
const QString &provider = QString());
Cipher(const QString &type,
Mode mode,
Padding pad,
Direction dir,
const SymmetricKey &key,
const InitializationVector &iv,
const AuthTag &tag,
const QString &provider = QString());
Cipher(const Cipher &from);
~Cipher() override;
Cipher &operator=(const Cipher &from);
static QStringList supportedTypes(const QString &provider = QString());
QString type() const;
Mode mode() const;
Padding padding() const;
Direction direction() const;
KeyLength keyLength() const;
bool validKeyLength(int n) const;
int blockSize() const;
AuthTag tag() const;
void clear() override;
MemoryRegion update(const MemoryRegion &a) override;
MemoryRegion final() override;
bool ok() const override;
void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector());
void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv, const AuthTag &tag);
static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType);
private:
class Private;
Private *d;
};
class QCA_EXPORT MessageAuthenticationCode : public Algorithm, public BufferedComputation
{
public:
MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider = QString());
MessageAuthenticationCode(const MessageAuthenticationCode &from);
~MessageAuthenticationCode() override;
MessageAuthenticationCode &operator=(const MessageAuthenticationCode &from);
static QStringList supportedTypes(const QString &provider = QString());
QString type() const;
KeyLength keyLength() const;
bool validKeyLength(int n) const;
void clear() override;
void update(const MemoryRegion &array) override;
MemoryRegion final() override;
void setup(const SymmetricKey &key);
private:
class Private;
Private *d;
};
class QCA_EXPORT KeyDerivationFunction : public Algorithm
{
public:
KeyDerivationFunction(const KeyDerivationFunction &from);
~KeyDerivationFunction() override;
KeyDerivationFunction &operator=(const KeyDerivationFunction &from);
SymmetricKey makeKey(const SecureArray &secret,
const InitializationVector &salt,
unsigned int keyLength,
unsigned int iterationCount);
SymmetricKey makeKey(const SecureArray &secret,
const InitializationVector &salt,
unsigned int keyLength,
int msecInterval,
unsigned int *iterationCount);
static QString withAlgorithm(const QString &kdfType, const QString &algType);
protected:
KeyDerivationFunction(const QString &type, const QString &provider);
private:
class Private;
Private *d;
};
class QCA_EXPORT PBKDF1 : public KeyDerivationFunction
{
public:
explicit PBKDF1(const QString &algorithm = QStringLiteral("sha1"), const QString &provider = QString())
: KeyDerivationFunction(withAlgorithm(QStringLiteral("pbkdf1"), algorithm), provider)
{
}
};
class QCA_EXPORT PBKDF2 : public KeyDerivationFunction
{
public:
explicit PBKDF2(const QString &algorithm = QStringLiteral("sha1"), const QString &provider = QString())
: KeyDerivationFunction(withAlgorithm(QStringLiteral("pbkdf2"), algorithm), provider)
{
}
};
class QCA_EXPORT HKDF : public Algorithm
{
public:
explicit HKDF(const QString &algorithm = QStringLiteral("sha256"), const QString &provider = QString());
HKDF(const HKDF &from);
~HKDF() override;
HKDF &operator=(const HKDF &from);
SymmetricKey makeKey(const SecureArray &secret,
const InitializationVector &salt,
const InitializationVector &info,
unsigned int keyLength);
};
}
#endif
QCA::Algorithm::type
QString type() const
The name of the algorithm type.
QCA::Algorithm::provider
Provider * provider() const
The name of the provider.
QCA::Algorithm::Algorithm
Algorithm(const Algorithm &from)
Standard copy constructor.
QCA::AuthTag
Container for authentication tag.
Definition qca_core.h:1347
QCA::BufferedComputation
General superclass for buffered computation algorithms.
Definition qca_core.h:1052
QCA::Cipher::validKeyLength
bool validKeyLength(int n) const
Test if a key length is valid for the cipher algorithm.
QCA::Cipher::Cipher
Cipher(const QString &type, Mode mode, Padding pad, Direction dir, const SymmetricKey &key, const InitializationVector &iv, const AuthTag &tag, const QString &provider=QString())
Standard constructor.
QCA::Cipher::direction
Direction direction() const
Return the cipher direction.
QCA::Cipher::operator=
Cipher & operator=(const Cipher &from)
Assignment operator.
QCA::Cipher::supportedTypes
static QStringList supportedTypes(const QString &provider=QString())
Returns a list of all of the cipher types available.
QCA::Cipher::padding
Padding padding() const
Return the cipher padding type.
QCA::Cipher::Mode
Mode
Mode settings for cipher algorithms.
Definition qca_basic.h:592
QCA::Cipher::ECB
@ ECB
operate in Electronic Code Book mode
Definition qca_basic.h:595
QCA::Cipher::OFB
@ OFB
operate in Output FeedBack Mode
Definition qca_basic.h:596
QCA::Cipher::CCM
@ CCM
operate in Counter with CBC-MAC
Definition qca_basic.h:599
QCA::Cipher::CFB
@ CFB
operate in Cipher FeedBack mode
Definition qca_basic.h:594
QCA::Cipher::GCM
@ GCM
operate in Galois Counter Mode
Definition qca_basic.h:598
QCA::Cipher::CTR
@ CTR
operate in CounTer Mode
Definition qca_basic.h:597
QCA::Cipher::CBC
@ CBC
operate in Cipher Block Chaining mode
Definition qca_basic.h:593
QCA::Cipher::setup
void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv=InitializationVector())
Reset / reconfigure the Cipher.
QCA::Cipher::type
QString type() const
Return the cipher type.
QCA::Cipher::withAlgorithms
static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType)
Construct a Cipher type string.
QCA::Cipher::Cipher
Cipher(const QString &type, Mode mode, Padding pad=DefaultPadding, Direction dir=Encode, const SymmetricKey &key=SymmetricKey(), const InitializationVector &iv=InitializationVector(), const QString &provider=QString())
Standard constructor.
QCA::Cipher::tag
AuthTag tag() const
return the authentication tag for the cipher object
QCA::Cipher::update
MemoryRegion update(const MemoryRegion &a) override
pass in a byte array of data, which will be encrypted or decrypted (according to the Direction that w...
QCA::Cipher::setup
void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv, const AuthTag &tag)
Reset / reconfigure the Cipher.
QCA::Cipher::ok
bool ok() const override
Test if an update() or final() call succeeded.
QCA::Cipher::clear
void clear() override
reset the cipher object, to allow re-use
QCA::Cipher::Cipher
Cipher(const Cipher &from)
Standard copy constructor.
QCA::Cipher::mode
Mode mode() const
Return the cipher mode.
QCA::Cipher::keyLength
KeyLength keyLength() const
Return acceptable key lengths.
QCA::Cipher::Padding
Padding
Padding variations for cipher algorithms.
Definition qca_basic.h:609
QCA::Cipher::NoPadding
@ NoPadding
Do not use padding.
Definition qca_basic.h:611
QCA::Cipher::DefaultPadding
@ DefaultPadding
Default for cipher-mode.
Definition qca_basic.h:610
QCA::Cipher::PKCS7
@ PKCS7
Pad using the scheme in PKCS#7.
Definition qca_basic.h:612
QCA::Cipher::blockSize
int blockSize() const
return the block size for the cipher object
QCA::Filter
General superclass for filtering transformation algorithms.
Definition qca_core.h:1108
QCA::HKDF::operator=
HKDF & operator=(const HKDF &from)
Assignment operator.
QCA::HKDF::HKDF
HKDF(const QString &algorithm=QStringLiteral("sha256"), const QString &provider=QString())
Standard constructor.
QCA::HKDF::HKDF
HKDF(const HKDF &from)
Standard copy constructor.
QCA::HKDF::makeKey
SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, const InitializationVector &info, unsigned int keyLength)
Generate the key from a specified secret, salt value, and an additional info.
QCA::Hash::supportedTypes
static QStringList supportedTypes(const QString &provider=QString())
Returns a list of all of the hash types available.
QCA::Hash::update
void update(QIODevice *file)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QCA::Hash::update
void update(const MemoryRegion &a) override
Update a hash, adding more of the message contents to the digest.
QCA::Hash::hash
MemoryRegion hash(const MemoryRegion &array)
Hash a byte array, returning it as another byte array
QCA::Hash::type
QString type() const
Return the hash type.
QCA::Hash::clear
void clear() override
Reset a hash, dumping all previous parts of the message.
QCA::Hash::update
void update(const QByteArray &a)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QCA::Hash::operator=
Hash & operator=(const Hash &from)
Assignment operator.
QCA::Hash::Hash
Hash(const Hash &from)
Copy constructor.
QCA::Hash::hashToString
QString hashToString(const MemoryRegion &array)
Hash a byte array, returning it as a printable string
QCA::Hash::Hash
Hash(const QString &type, const QString &provider=QString())
Constructor.
QCA::Hash::update
void update(const char *data, int len=-1)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QCA::InitializationVector
Container for initialisation vectors and nonces.
Definition qca_core.h:1310
QCA::KeyDerivationFunction::KeyDerivationFunction
KeyDerivationFunction(const KeyDerivationFunction &from)
Standard copy constructor.
QCA::KeyDerivationFunction::withAlgorithm
static QString withAlgorithm(const QString &kdfType, const QString &algType)
Construct the name of the algorithm.
QCA::KeyDerivationFunction::operator=
KeyDerivationFunction & operator=(const KeyDerivationFunction &from)
Assignment operator.
QCA::KeyDerivationFunction::makeKey
SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, unsigned int keyLength, int msecInterval, unsigned int *iterationCount)
Generate the key from a specified secret and salt value.
QCA::KeyDerivationFunction::makeKey
SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, unsigned int keyLength, unsigned int iterationCount)
Generate the key from a specified secret and salt value.
QCA::KeyDerivationFunction::KeyDerivationFunction
KeyDerivationFunction(const QString &type, const QString &provider)
Special constructor for subclass initialisation.
QCA::KeyLength
Simple container for acceptable key lengths.
Definition qca_core.h:701
QCA::MemoryRegion
Array of bytes that may be optionally secured.
Definition qca_tools.h:91
QCA::MessageAuthenticationCode::validKeyLength
bool validKeyLength(int n) const
Test if a key length is valid for the MAC algorithm.
QCA::MessageAuthenticationCode::MessageAuthenticationCode
MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider=QString())
Standard constructor.
QCA::MessageAuthenticationCode::supportedTypes
static QStringList supportedTypes(const QString &provider=QString())
Returns a list of all of the message authentication code types available.
QCA::MessageAuthenticationCode::setup
void setup(const SymmetricKey &key)
Initialise the MAC algorithm.
QCA::MessageAuthenticationCode::operator=
MessageAuthenticationCode & operator=(const MessageAuthenticationCode &from)
Assignment operator.
QCA::MessageAuthenticationCode::type
QString type() const
Return the MAC type.
QCA::MessageAuthenticationCode::update
void update(const MemoryRegion &array) override
Update the MAC, adding more of the message contents to the digest.
QCA::MessageAuthenticationCode::MessageAuthenticationCode
MessageAuthenticationCode(const MessageAuthenticationCode &from)
Standard copy constructor.
QCA::MessageAuthenticationCode::keyLength
KeyLength keyLength() const
Return acceptable key lengths.
QCA::MessageAuthenticationCode::clear
void clear() override
Reset a MessageAuthenticationCode, dumping all previous parts of the message.
QCA::PBKDF1::PBKDF1
PBKDF1(const QString &algorithm=QStringLiteral("sha1"), const QString &provider=QString())
Standard constructor.
Definition qca_basic.h:1058
QCA::PBKDF2::PBKDF2
PBKDF2(const QString &algorithm=QStringLiteral("sha1"), const QString &provider=QString())
Standard constructor.
Definition qca_basic.h:1083
QCA::Random::nextByte
uchar nextByte()
Provide a random byte.
QCA::Random::operator=
Random & operator=(const Random &from)
Assignment operator.
QCA::Random::Random
Random(const Random &from)
Copy constructor.
QCA::Random::randomArray
static SecureArray randomArray(int size)
Provide a specified number of random bytes.
QCA::Random::randomInt
static int randomInt()
Provide a random integer.
QCA::Random::Random
Random(const QString &provider=QString())
Standard Constructor.
QCA::Random::randomChar
static uchar randomChar()
Provide a random character (byte).
QCA::Random::nextBytes
SecureArray nextBytes(int size)
Provide a specified number of random bytes.
QCA::SecureArray
Secure array of bytes.
Definition qca_tools.h:317
QCA::SymmetricKey
Container for keys for symmetric encryption algorithms.
Definition qca_core.h:1264
QCA
QCA - the Qt Cryptographic Architecture.
Definition qca_basic.h:41
QCA::Direction
Direction
Direction settings for symmetric algorithms.
Definition qca_core.h:141
QCA::Encode
@ Encode
Operate in the "forward" direction; for example, encrypting.
Definition qca_core.h:142
qca_core.h
Header file for core QCA infrastructure.