Qt Cryptographic Architecture: qca_basic.h Source File

# qca_basic.h

Go to the documentation of this file.

    00001 /*
    00002  * qca_basic.h - Qt Cryptographic Architecture
    00003  * Copyright (C) 2003-2007  Justin Karneges <justin@affinix.com>
    00004  * Copyright (C) 2004-2007  Brad Hards <bradh@frogmouth.net>
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the GNU Lesser General Public
    00008  * License as published by the Free Software Foundation; either
    00009  * version 2.1 of the License, or (at your option) any later version.
    00010  *
    00011  * This library is distributed in the hope that it will be useful,
    00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  * Lesser General Public License for more details.
    00015  *
    00016  * You should have received a copy of the GNU Lesser General Public
    00017  * License along with this library; if not, write to the Free Software
    00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    00019  * 02110-1301  USA
    00020  *
    00021  */
    00022
    00033 #ifndef QCA_BASIC_H
    00034 #define QCA_BASIC_H
    00035
    00036 #include "qca_core.h"
    00037
    00038 namespace QCA {
    00039
    00062 class QCA_EXPORT Random : public Algorithm
    00063 {
    00064 public:
    00071         Random(const QString &provider = QString());
    00072
    00078         Random(const Random &from);
    00079
    00080         ~Random();
    00081
    00087         Random & operator=(const Random &from);
    00088
    00097         uchar nextByte();
    00098
    00109         SecureArray nextBytes(int size);
    00110
    00122         static uchar randomChar();
    00123
    00133         static int randomInt();
    00134
    00145         static SecureArray randomArray(int size);
    00146
    00147 private:
    00148         class Private;
    00149         Private *d;
    00150 };
    00151
    00205 class QCA_EXPORT Hash : public Algorithm, public BufferedComputation
    00206 {
    00207 public:
    00216         explicit Hash(const QString &type, const QString &provider = QString());
    00217
    00223         Hash(const Hash &from);
    00224
    00225         ~Hash();
    00226
    00232         Hash & operator=(const Hash &from);
    00233
    00241         static QStringList supportedTypes(const QString &provider = QString());
    00242
    00246         QString type() const;
    00247
    00258         virtual void clear();
    00259
    00271         virtual void update(const MemoryRegion &a);
    00272
    00278         void update(const QByteArray &a);
    00279
    00294         void update(const char *data, int len = -1);
    00295
    00318         void update(QIODevice *file);
    00319
    00333         virtual MemoryRegion final();
    00334
    00355         MemoryRegion hash(const MemoryRegion &array);
    00356
    00371         QString hashToString(const MemoryRegion &array);
    00372
    00373 private:
    00374         class Private;
    00375         Private *d;
    00376 };
    00377
    00575 class QCA_EXPORT Cipher : public Algorithm, public Filter
    00576 {
    00577 public:
    00585         enum Mode
    00586         {
    00587                 CBC,
    00588                 CFB,
    00589                 ECB,
    00590                 OFB
    00591         };
    00592
    00599         enum Padding
    00600         {
    00601                 DefaultPadding,
    00602                 NoPadding,
    00603                 PKCS7
    00604         };
    00605
    00622         Cipher(const QString &type, Mode mode, Padding pad = DefaultPadding,
    00623                 Direction dir = Encode, const SymmetricKey &key = SymmetricKey(),
    00624                 const InitializationVector &iv = InitializationVector(),
    00625                 const QString &provider = QString());
    00626
    00632         Cipher(const Cipher &from);
    00633
    00634         ~Cipher();
    00635
    00641         Cipher & operator=(const Cipher &from);
    00642
    00650         static QStringList supportedTypes(const QString &provider = QString());
    00651
    00655         QString type() const;
    00656
    00660         Mode mode() const;
    00661
    00665         Padding padding() const;
    00666
    00670         Direction direction() const;
    00671
    00675         KeyLength keyLength() const;
    00676
    00683         bool validKeyLength(int n) const;
    00684
    00688         int blockSize() const;
    00689
    00693         virtual void clear();
    00694
    00702         virtual MemoryRegion update(const MemoryRegion &a);
    00703
    00708         virtual MemoryRegion final();
    00709
    00715         virtual bool ok() const;
    00716
    00730         void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector());
    00731
    00741         static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType);
    00742
    00743 private:
    00744         class Private;
    00745         Private *d;
    00746 };
    00747
    00768 class QCA_EXPORT MessageAuthenticationCode : public Algorithm, public BufferedComputation
    00769 {
    00770 public:
    00780         MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider = QString());
    00781
    00790         MessageAuthenticationCode(const MessageAuthenticationCode &from);
    00791
    00792         ~MessageAuthenticationCode();
    00793
    00802         MessageAuthenticationCode & operator=(const MessageAuthenticationCode &from);
    00803
    00812         static QStringList supportedTypes(const QString &provider = QString());
    00813
    00817         QString type() const;
    00818
    00822         KeyLength keyLength() const;
    00823
    00830         bool validKeyLength(int n) const;
    00831
    00844         virtual void clear();
    00845
    00853         virtual void update(const MemoryRegion &array);
    00854
    00866         virtual MemoryRegion final();
    00867
    00873         void setup(const SymmetricKey &key);
    00874
    00875 private:
    00876         class Private;
    00877         Private *d;
    00878 };
    00879
    00894 class QCA_EXPORT KeyDerivationFunction : public Algorithm
    00895 {
    00896 public:
    00902         KeyDerivationFunction(const KeyDerivationFunction &from);
    00903
    00904         ~KeyDerivationFunction();
    00905
    00914         KeyDerivationFunction & operator=(const KeyDerivationFunction &from);
    00915
    00928         SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, unsigned int keyLength, unsigned int iterationCount);
    00929
    00942         static QString withAlgorithm(const QString &kdfType, const QString &algType);
    00943
    00944 protected:
    00951         KeyDerivationFunction(const QString &type, const QString &provider);
    00952
    00953 private:
    00954         class Private;
    00955         Private *d;
    00956 };
    00957
    00968 class QCA_EXPORT PBKDF1 : public KeyDerivationFunction
    00969 {
    00970 public:
    00977         explicit PBKDF1(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf1", algorithm), provider) {}
    00978 };
    00979
    00990 class QCA_EXPORT PBKDF2 : public KeyDerivationFunction
    00991 {
    00992 public:
    00999         explicit PBKDF2(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf2", algorithm), provider) {}
    01000 };
    01001
    01002 }
    01003
    01004 #endif