00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00032 #ifndef QCA_BASIC_H
00033 #define QCA_BASIC_H
00034
00035 #include "qca_core.h"
00036
00037 namespace QCA {
00038
00061 class QCA_EXPORT Random : public Algorithm
00062 {
00063 public:
00070 Random(const QString &provider = QString());
00071
00077 Random(const Random &from);
00078
00079 ~Random();
00080
00086 Random & operator=(const Random &from);
00087
00096 uchar nextByte();
00097
00108 SecureArray nextBytes(int size);
00109
00121 static uchar randomChar();
00122
00132 static int randomInt();
00133
00144 static SecureArray randomArray(int size);
00145
00146 private:
00147 class Private;
00148 Private *d;
00149 };
00150
00204 class QCA_EXPORT Hash : public Algorithm, public BufferedComputation
00205 {
00206 public:
00215 explicit Hash(const QString &type, const QString &provider = QString());
00216
00222 Hash(const Hash &from);
00223
00224 ~Hash();
00225
00231 Hash & operator=(const Hash &from);
00232
00240 static QStringList supportedTypes(const QString &provider = QString());
00241
00245 QString type() const;
00246
00257 virtual void clear();
00258
00270 virtual void update(const MemoryRegion &a);
00271
00277 void update(const QByteArray &a);
00278
00293 void update(const char *data, int len = -1);
00294
00317 void update(QIODevice *file);
00318
00332 virtual MemoryRegion final();
00333
00354 MemoryRegion hash(const MemoryRegion &array);
00355
00370 QString hashToString(const MemoryRegion &array);
00371
00372 private:
00373 class Private;
00374 Private *d;
00375 };
00376
00574 class QCA_EXPORT Cipher : public Algorithm, public Filter
00575 {
00576 public:
00584 enum Mode
00585 {
00586 CBC,
00587 CFB,
00588 ECB,
00589 OFB
00590 };
00591
00598 enum Padding
00599 {
00600 DefaultPadding,
00601 NoPadding,
00602 PKCS7
00603 };
00604
00621 Cipher(const QString &type, Mode mode, Padding pad = DefaultPadding,
00622 Direction dir = Encode, const SymmetricKey &key = SymmetricKey(),
00623 const InitializationVector &iv = InitializationVector(),
00624 const QString &provider = QString());
00625
00631 Cipher(const Cipher &from);
00632
00633 ~Cipher();
00634
00640 Cipher & operator=(const Cipher &from);
00641
00649 static QStringList supportedTypes(const QString &provider = QString());
00650
00654 QString type() const;
00655
00659 Mode mode() const;
00660
00664 Padding padding() const;
00665
00669 Direction direction() const;
00670
00674 KeyLength keyLength() const;
00675
00682 bool validKeyLength(int n) const;
00683
00687 int blockSize() const;
00688
00692 virtual void clear();
00693
00701 virtual MemoryRegion update(const MemoryRegion &a);
00702
00707 virtual MemoryRegion final();
00708
00714 virtual bool ok() const;
00715
00729 void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector());
00730
00740 static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType);
00741
00742 private:
00743 class Private;
00744 Private *d;
00745 };
00746
00767 class QCA_EXPORT MessageAuthenticationCode : public Algorithm, public BufferedComputation
00768 {
00769 public:
00779 MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider = QString());
00780
00789 MessageAuthenticationCode(const MessageAuthenticationCode &from);
00790
00791 ~MessageAuthenticationCode();
00792
00801 MessageAuthenticationCode & operator=(const MessageAuthenticationCode &from);
00802
00811 static QStringList supportedTypes(const QString &provider = QString());
00812
00816 QString type() const;
00817
00821 KeyLength keyLength() const;
00822
00829 bool validKeyLength(int n) const;
00830
00843 virtual void clear();
00844
00852 virtual void update(const MemoryRegion &array);
00853
00865 virtual MemoryRegion final();
00866
00872 void setup(const SymmetricKey &key);
00873
00874 private:
00875 class Private;
00876 Private *d;
00877 };
00878
00893 class QCA_EXPORT KeyDerivationFunction : public Algorithm
00894 {
00895 public:
00901 KeyDerivationFunction(const KeyDerivationFunction &from);
00902
00903 ~KeyDerivationFunction();
00904
00913 KeyDerivationFunction & operator=(const KeyDerivationFunction &from);
00914
00927 SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, unsigned int keyLength, unsigned int iterationCount);
00928
00941 static QString withAlgorithm(const QString &kdfType, const QString &algType);
00942
00943 protected:
00950 KeyDerivationFunction(const QString &type, const QString &provider);
00951
00952 private:
00953 class Private;
00954 Private *d;
00955 };
00956
00967 class QCA_EXPORT PBKDF1 : public KeyDerivationFunction
00968 {
00969 public:
00976 explicit PBKDF1(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf1", algorithm), provider) {}
00977 };
00978
00989 class QCA_EXPORT PBKDF2 : public KeyDerivationFunction
00990 {
00991 public:
00998 explicit PBKDF2(const QString &algorithm = "sha1", const QString &provider = QString()) : KeyDerivationFunction(withAlgorithm("pbkdf2", algorithm), provider) {}
00999 };
01000
01001 }
01002
01003 #endif