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-2006  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  02110-1301, USA
00019  *
00020  */
00021 
00032 #ifndef QCA_BASIC_H
00033 #define QCA_BASIC_H
00034 
00035 #include "qca_core.h"
00036 
00037 namespace QCA {
00038 
00052 class QCA_EXPORT Random : public Algorithm
00053 {
00054 public:
00061         Random(const QString &provider = QString());
00062 
00068         Random(const Random &from);
00069 
00070         ~Random();
00071 
00077         Random & operator=(const Random &from);
00078 
00087         uchar nextByte();
00088 
00099         SecureArray nextBytes(int size);
00100 
00112         static uchar randomChar();
00113 
00123         static int randomInt();
00124 
00135         static SecureArray randomArray(int size);
00136 
00137 private:
00138         class Private;
00139         Private *d;
00140 };
00141 
00191 class QCA_EXPORT Hash : public Algorithm, public BufferedComputation
00192 {
00193 public:
00202         explicit Hash(const QString &type, const QString &provider = QString());
00208         Hash(const Hash &from);
00209 
00210         ~Hash();
00211 
00217         Hash & operator=(const Hash &from);
00218 
00222         QString type() const;
00223 
00234         virtual void clear();
00235 
00247         virtual void update(const MemoryRegion &a);
00248 
00254         void update(const QByteArray &a);
00255 
00270         void update(const char *data, int len = -1);
00271 
00294         void update(QIODevice *file);
00295 
00309         virtual MemoryRegion final();
00310 
00331         MemoryRegion hash(const MemoryRegion &array);
00332 
00347         QString hashToString(const MemoryRegion &array);
00348 
00349 private:
00350         class Private;
00351         Private *d;
00352 };
00353 
00525 class QCA_EXPORT Cipher : public Algorithm, public Filter
00526 {
00527 public:
00531         enum Mode
00532         {
00533                 CBC, 
00534                 CFB, 
00535                 ECB, 
00536                 OFB  
00537         };
00538 
00542         enum Padding
00543         {
00544                 DefaultPadding, 
00545                 NoPadding,      
00546                 PKCS7           
00547         };
00548 
00565         Cipher(const QString &type, Mode mode, Padding pad = DefaultPadding,
00566                 Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), 
00567                 const InitializationVector &iv = InitializationVector(),
00568                 const QString &provider = QString());
00569 
00573         Cipher(const Cipher &from);
00574         ~Cipher();
00575 
00581         Cipher & operator=(const Cipher &from);
00582 
00586         QString type() const;
00587 
00591         Mode mode() const;
00592 
00596         Padding padding() const;
00597 
00601         Direction direction() const;
00602 
00606         KeyLength keyLength() const;
00607 
00614         bool validKeyLength(int n) const;
00615 
00619         int blockSize() const;
00620 
00624         virtual void clear();
00625 
00633         virtual MemoryRegion update(const MemoryRegion &a);
00634 
00639         virtual MemoryRegion final();
00640 
00646         virtual bool ok() const;
00647 
00659         void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector());
00660 
00670         static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType);
00671 
00672 private:
00673         class Private;
00674         Private *d;
00675 };
00676 
00695 class QCA_EXPORT MessageAuthenticationCode : public Algorithm, public BufferedComputation
00696 {
00697 public:
00707         MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider = QString());
00708 
00712         MessageAuthenticationCode(const MessageAuthenticationCode &from);
00713 
00714         ~MessageAuthenticationCode();
00715 
00722         MessageAuthenticationCode & operator=(const MessageAuthenticationCode &from);
00723 
00727         QString type() const;
00728 
00732         KeyLength keyLength() const;
00733 
00740         bool validKeyLength(int n) const;
00741 
00754         virtual void clear();
00755 
00763         virtual void update(const MemoryRegion &array);
00764 
00776         virtual MemoryRegion final();
00777 
00783         void setup(const SymmetricKey &key);
00784 
00785 private:
00786         class Private;
00787         Private *d;
00788 };
00789 
00801 class QCA_EXPORT KeyDerivationFunction : public Algorithm
00802 {
00803 public:
00807         KeyDerivationFunction(const KeyDerivationFunction &from);
00808         ~KeyDerivationFunction();
00809 
00816         KeyDerivationFunction & operator=(const KeyDerivationFunction &from);
00817 
00830         SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, unsigned int keyLength, unsigned int iterationCount);
00831 
00839         static QString withAlgorithm(const QString &kdfType, const QString &algType);
00840 
00841 protected:
00845         KeyDerivationFunction(const QString &type, const QString &provider);
00846 
00847 private:
00848         class Private;
00849         Private *d;
00850 };
00851 
00860 class QCA_EXPORT PBKDF1 : public KeyDerivationFunction
00861 {
00862 public:
00869         explicit PBKDF1(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf1", algorithm), provider) {}
00870 };
00871 
00880 class QCA_EXPORT PBKDF2 : public KeyDerivationFunction
00881 {
00882 public:
00889         explicit PBKDF2(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf2", algorithm), provider) {}
00890 };
00891 
00892 }
00893 
00894 #endif

Generated on Fri Jul 6 13:22:42 2007 for Qt Cryptographic Architecture by  doxygen 1.4.6