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 
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 
00206 class QCA_EXPORT Hash : public Algorithm, public BufferedComputation
00207 {
00208 public:
00217         explicit Hash(const QString &type, const QString &provider = QString());
00223         Hash(const Hash &from);
00224 
00225         ~Hash();
00226 
00232         Hash & operator=(const Hash &from);
00233 
00237         QString type() const;
00238 
00249         virtual void clear();
00250 
00262         virtual void update(const MemoryRegion &a);
00263 
00269         void update(const QByteArray &a);
00270 
00285         void update(const char *data, int len = -1);
00286 
00309         void update(QIODevice *file);
00310 
00324         virtual MemoryRegion final();
00325 
00346         MemoryRegion hash(const MemoryRegion &array);
00347 
00362         QString hashToString(const MemoryRegion &array);
00363 
00364 private:
00365         class Private;
00366         Private *d;
00367 };
00368 
00369 
00555 class QCA_EXPORT Cipher : public Algorithm, public Filter
00556 {
00557 public:
00565         enum Mode
00566         {
00567                 CBC, 
00568                 CFB, 
00569                 ECB, 
00570                 OFB  
00571         };
00572 
00579         enum Padding
00580         {
00581                 DefaultPadding, 
00582                 NoPadding,      
00583                 PKCS7           
00584         };
00585 
00602         Cipher(const QString &type, Mode mode, Padding pad = DefaultPadding,
00603                 Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), 
00604                 const InitializationVector &iv = InitializationVector(),
00605                 const QString &provider = QString());
00606 
00610         Cipher(const Cipher &from);
00611         ~Cipher();
00612 
00618         Cipher & operator=(const Cipher &from);
00619 
00623         QString type() const;
00624 
00628         Mode mode() const;
00629 
00633         Padding padding() const;
00634 
00638         Direction direction() const;
00639 
00643         KeyLength keyLength() const;
00644 
00651         bool validKeyLength(int n) const;
00652 
00656         int blockSize() const;
00657 
00661         virtual void clear();
00662 
00670         virtual MemoryRegion update(const MemoryRegion &a);
00671 
00676         virtual MemoryRegion final();
00677 
00683         virtual bool ok() const;
00684 
00698         void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector());
00699 
00709         static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType);
00710 
00711 private:
00712         class Private;
00713         Private *d;
00714 };
00715 
00737 class QCA_EXPORT MessageAuthenticationCode : public Algorithm, public BufferedComputation
00738 {
00739 public:
00749         MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider = QString());
00750 
00754         MessageAuthenticationCode(const MessageAuthenticationCode &from);
00755 
00756         ~MessageAuthenticationCode();
00757 
00764         MessageAuthenticationCode & operator=(const MessageAuthenticationCode &from);
00765 
00769         QString type() const;
00770 
00774         KeyLength keyLength() const;
00775 
00782         bool validKeyLength(int n) const;
00783 
00796         virtual void clear();
00797 
00805         virtual void update(const MemoryRegion &array);
00806 
00818         virtual MemoryRegion final();
00819 
00825         void setup(const SymmetricKey &key);
00826 
00827 private:
00828         class Private;
00829         Private *d;
00830 };
00831 
00846 class QCA_EXPORT KeyDerivationFunction : public Algorithm
00847 {
00848 public:
00852         KeyDerivationFunction(const KeyDerivationFunction &from);
00853         ~KeyDerivationFunction();
00854 
00861         KeyDerivationFunction & operator=(const KeyDerivationFunction &from);
00862 
00875         SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, unsigned int keyLength, unsigned int iterationCount);
00876 
00884         static QString withAlgorithm(const QString &kdfType, const QString &algType);
00885 
00886 protected:
00890         KeyDerivationFunction(const QString &type, const QString &provider);
00891 
00892 private:
00893         class Private;
00894         Private *d;
00895 };
00896 
00907 class QCA_EXPORT PBKDF1 : public KeyDerivationFunction
00908 {
00909 public:
00916         explicit PBKDF1(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf1", algorithm), provider) {}
00917 };
00918 
00930 class QCA_EXPORT PBKDF2 : public KeyDerivationFunction
00931 {
00932 public:
00939         explicit PBKDF2(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf2", algorithm), provider) {}
00940 };
00941 
00942 }
00943 
00944 #endif

Generated on Tue Aug 28 08:19:58 2007 for Qt Cryptographic Architecture by  doxygen 1.5.2