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 
00204 class QCA_EXPORT Hash : public Algorithm, public BufferedComputation
00205 {
00206 public:
00215         explicit Hash(const QString &type, const QString &provider = QString());
00221         Hash(const Hash &from);
00222 
00223         ~Hash();
00224 
00230         Hash & operator=(const Hash &from);
00231 
00235         QString type() const;
00236 
00247         virtual void clear();
00248 
00260         virtual void update(const MemoryRegion &a);
00261 
00267         void update(const QByteArray &a);
00268 
00283         void update(const char *data, int len = -1);
00284 
00307         void update(QIODevice *file);
00308 
00322         virtual MemoryRegion final();
00323 
00344         MemoryRegion hash(const MemoryRegion &array);
00345 
00360         QString hashToString(const MemoryRegion &array);
00361 
00362 private:
00363         class Private;
00364         Private *d;
00365 };
00366 
00367 
00553 class QCA_EXPORT Cipher : public Algorithm, public Filter
00554 {
00555 public:
00559         enum Mode
00560         {
00561                 CBC, 
00562                 CFB, 
00563                 ECB, 
00564                 OFB  
00565         };
00566 
00570         enum Padding
00571         {
00572                 DefaultPadding, 
00573                 NoPadding,      
00574                 PKCS7           
00575         };
00576 
00593         Cipher(const QString &type, Mode mode, Padding pad = DefaultPadding,
00594                 Direction dir = Encode, const SymmetricKey &key = SymmetricKey(), 
00595                 const InitializationVector &iv = InitializationVector(),
00596                 const QString &provider = QString());
00597 
00601         Cipher(const Cipher &from);
00602         ~Cipher();
00603 
00609         Cipher & operator=(const Cipher &from);
00610 
00614         QString type() const;
00615 
00619         Mode mode() const;
00620 
00624         Padding padding() const;
00625 
00629         Direction direction() const;
00630 
00634         KeyLength keyLength() const;
00635 
00642         bool validKeyLength(int n) const;
00643 
00647         int blockSize() const;
00648 
00652         virtual void clear();
00653 
00661         virtual MemoryRegion update(const MemoryRegion &a);
00662 
00667         virtual MemoryRegion final();
00668 
00674         virtual bool ok() const;
00675 
00687         void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector());
00688 
00698         static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType);
00699 
00700 private:
00701         class Private;
00702         Private *d;
00703 };
00704 
00726 class QCA_EXPORT MessageAuthenticationCode : public Algorithm, public BufferedComputation
00727 {
00728 public:
00738         MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider = QString());
00739 
00743         MessageAuthenticationCode(const MessageAuthenticationCode &from);
00744 
00745         ~MessageAuthenticationCode();
00746 
00753         MessageAuthenticationCode & operator=(const MessageAuthenticationCode &from);
00754 
00758         QString type() const;
00759 
00763         KeyLength keyLength() const;
00764 
00771         bool validKeyLength(int n) const;
00772 
00785         virtual void clear();
00786 
00794         virtual void update(const MemoryRegion &array);
00795 
00807         virtual MemoryRegion final();
00808 
00814         void setup(const SymmetricKey &key);
00815 
00816 private:
00817         class Private;
00818         Private *d;
00819 };
00820 
00835 class QCA_EXPORT KeyDerivationFunction : public Algorithm
00836 {
00837 public:
00841         KeyDerivationFunction(const KeyDerivationFunction &from);
00842         ~KeyDerivationFunction();
00843 
00850         KeyDerivationFunction & operator=(const KeyDerivationFunction &from);
00851 
00864         SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, unsigned int keyLength, unsigned int iterationCount);
00865 
00873         static QString withAlgorithm(const QString &kdfType, const QString &algType);
00874 
00875 protected:
00879         KeyDerivationFunction(const QString &type, const QString &provider);
00880 
00881 private:
00882         class Private;
00883         Private *d;
00884 };
00885 
00896 class QCA_EXPORT PBKDF1 : public KeyDerivationFunction
00897 {
00898 public:
00905         explicit PBKDF1(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf1", algorithm), provider) {}
00906 };
00907 
00919 class QCA_EXPORT PBKDF2 : public KeyDerivationFunction
00920 {
00921 public:
00928         explicit PBKDF2(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf2", algorithm), provider) {}
00929 };
00930 
00931 }
00932 
00933 #endif

Generated on Tue Aug 7 18:06:27 2007 for Qt Cryptographic Architecture by  doxygen 1.5.1