Qt Cryptographic Architecture: qca_basic.h Source File

Qt Cryptographic Architecture

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

qca_basic.h
Go to the documentation of this file.
1 /*
2 * qca_basic.h - Qt Cryptographic Architecture
3 * Copyright (C) 2003-2007 Justin Karneges <justin@affinix.com>
4 * Copyright (C) 2004-2007 Brad Hards <bradh@frogmouth.net>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
33 #ifndef QCA_BASIC_H
34 #define QCA_BASIC_H
35
36 #include "qca_core.h"
37
38 #include <QIODevice>
39
40 // Qt5 comes with QStringLiteral for wrapping string literals, which Qt4 does
41 // not have. It is needed if the headers are built with QT_NO_CAST_FROM_ASCII.
42 // Defining it here as QString::fromUtf8 for convenience.
43 #ifndef QStringLiteral
44 #define QStringLiteral(str) QString::fromUtf8(str)
45 #endif
46
47 namespace QCA {
48
71 class QCA_EXPORT Random : public Algorithm
72 {
73 public:
80 Random(const QString &provider = QString());
81
87 Random(const Random &from);
88
89 ~Random();
90
96 Random & operator=(const Random &from);
97
106 uchar nextByte();
107
118 SecureArray nextBytes(int size);
119
131 static uchar randomChar();
132
142 static int randomInt();
143
154 static SecureArray randomArray(int size);
155
156 private:
157 class Private;
158 Private *d;
159 };
160
214 class QCA_EXPORT Hash : public Algorithm, public BufferedComputation
215 {
216 public:
225 explicit Hash(const QString &type, const QString &provider = QString());
226
232 Hash(const Hash &from);
233
234 ~Hash();
235
241 Hash & operator=(const Hash &from);
242
250 static QStringList supportedTypes(const QString &provider = QString());
251
255 QString type() const;
256
267 virtual void clear();
268
280 virtual void update(const MemoryRegion &a);
281
287 void update(const QByteArray &a);
288
303 void update(const char *data, int len = -1);
304
327 void update(QIODevice *file);
328
342 virtual MemoryRegion final();
343
364 MemoryRegion hash(const MemoryRegion &array);
365
380 QString hashToString(const MemoryRegion &array);
381
382 private:
383 class Private;
384 Private *d;
385 };
386
584 class QCA_EXPORT Cipher : public Algorithm, public Filter
585 {
586 public:
594 enum Mode
595 {
596 CBC,
597 CFB,
598 ECB,
599 OFB,
600 CTR
601 };
602
609 enum Padding
610 {
611 DefaultPadding,
612 NoPadding,
613 PKCS7
614 };
615
632 Cipher(const QString &type, Mode mode, Padding pad = DefaultPadding,
633 Direction dir = Encode, const SymmetricKey &key = SymmetricKey(),
634 const InitializationVector &iv = InitializationVector(),
635 const QString &provider = QString());
636
642 Cipher(const Cipher &from);
643
644 ~Cipher();
645
651 Cipher & operator=(const Cipher &from);
652
660 static QStringList supportedTypes(const QString &provider = QString());
661
665 QString type() const;
666
670 Mode mode() const;
671
675 Padding padding() const;
676
680 Direction direction() const;
681
685 KeyLength keyLength() const;
686
693 bool validKeyLength(int n) const;
694
698 int blockSize() const;
699
703 virtual void clear();
704
712 virtual MemoryRegion update(const MemoryRegion &a);
713
718 virtual MemoryRegion final();
719
725 virtual bool ok() const;
726
740 void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector());
741
751 static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType);
752
753 private:
754 class Private;
755 Private *d;
756 };
757
778 class QCA_EXPORT MessageAuthenticationCode : public Algorithm, public BufferedComputation
779 {
780 public:
790 MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider = QString());
791
800 MessageAuthenticationCode(const MessageAuthenticationCode &from);
801
802 ~MessageAuthenticationCode();
803
812 MessageAuthenticationCode & operator=(const MessageAuthenticationCode &from);
813
822 static QStringList supportedTypes(const QString &provider = QString());
823
827 QString type() const;
828
832 KeyLength keyLength() const;
833
840 bool validKeyLength(int n) const;
841
854 virtual void clear();
855
863 virtual void update(const MemoryRegion &array);
864
876 virtual MemoryRegion final();
877
883 void setup(const SymmetricKey &key);
884
885 private:
886 class Private;
887 Private *d;
888 };
889
904 class QCA_EXPORT KeyDerivationFunction : public Algorithm
905 {
906 public:
912 KeyDerivationFunction(const KeyDerivationFunction &from);
913
914 ~KeyDerivationFunction();
915
924 KeyDerivationFunction & operator=(const KeyDerivationFunction &from);
925
938 SymmetricKey makeKey(const SecureArray &secret, const InitializationVector &salt, unsigned int keyLength, unsigned int iterationCount);
939
953 SymmetricKey makeKey(const SecureArray &secret,
954 const InitializationVector &salt,
955 unsigned int keyLength,
956 int msecInterval,
957 unsigned int *iterationCount);
958
971 static QString withAlgorithm(const QString &kdfType, const QString &algType);
972
973 protected:
980 KeyDerivationFunction(const QString &type, const QString &provider);
981
982 private:
983 class Private;
984 Private *d;
985 };
986
997 class QCA_EXPORT PBKDF1 : public KeyDerivationFunction
998 {
999 public:
1006 explicit PBKDF1(const QString &algorithm = QStringLiteral("sha1"), const QString &provider = QString())
1007 : KeyDerivationFunction(withAlgorithm(QStringLiteral("pbkdf1"), algorithm), provider) {}
1008 };
1009
1020 class QCA_EXPORT PBKDF2 : public KeyDerivationFunction
1021 {
1022 public:
1029 explicit PBKDF2(const QString &algorithm = QStringLiteral("sha1"), const QString &provider = QString())
1030 : KeyDerivationFunction(withAlgorithm(QStringLiteral("pbkdf2"), algorithm), provider) {}
1031 };
1032
1033 }
1034
1035 #endif
QCA::PBKDF2::PBKDF2
PBKDF2(const QString &algorithm=QStringLiteral("sha1"), const QString &provider=QString())
Standard constructor.
Definition: qca_basic.h:1029
QCA::Algorithm
General superclass for an algorithm.
Definition: qca_core.h:1121
QCA::Cipher::Padding
Padding
Padding variations for cipher algorithms.
Definition: qca_basic.h:609
QCA::Cipher
General class for cipher (encryption / decryption) algorithms.
Definition: qca_basic.h:584
QCA::Cipher::Mode
Mode
Mode settings for cipher algorithms.
Definition: qca_basic.h:594
QCA::Random
Source of random numbers.
Definition: qca_basic.h:71
QCA::BufferedComputation
General superclass for buffered computation algorithms.
Definition: qca_core.h:1009
QCA::Cipher::OFB
operate in Output FeedBack Mode
Definition: qca_basic.h:599
QCA::SymmetricKey
Container for keys for symmetric encryption algorithms.
Definition: qca_core.h:1221
QCA::MessageAuthenticationCode
General class for message authentication code (MAC) algorithms.
Definition: qca_basic.h:778
QCA::KeyLength
Simple container for acceptable key lengths.
Definition: qca_core.h:670
QCA::PBKDF1::PBKDF1
PBKDF1(const QString &algorithm=QStringLiteral("sha1"), const QString &provider=QString())
Standard constructor.
Definition: qca_basic.h:1006
qca_core.h
Header file for core QCA infrastructure.
QCA::Cipher::DefaultPadding
Default for cipher-mode.
Definition: qca_basic.h:611
QCA::Cipher::ECB
operate in Electronic Code Book mode
Definition: qca_basic.h:598
QCA::InitializationVector
Container for initialisation vectors and nonces.
Definition: qca_core.h:1267
QCA::Direction
Direction
Direction settings for symmetric algorithms.
Definition: qca_core.h:139
QCA
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:47
QCA::Cipher::CBC
operate in Cipher Block Chaining mode
Definition: qca_basic.h:596
QCA::Cipher::NoPadding
Do not use padding.
Definition: qca_basic.h:612
QCA::Hash
General class for hashing algorithms.
Definition: qca_basic.h:214
QCA::SecureArray
Secure array of bytes.
Definition: qca_tools.h:316
QCA::PBKDF1
Password based key derivation function version 1.
Definition: qca_basic.h:997
QCA::Encode
Operate in the "forward" direction; for example, encrypting.
Definition: qca_core.h:141
QCA::Filter
General superclass for filtering transformation algorithms.
Definition: qca_core.h:1065
QCA::KeyDerivationFunction
General superclass for key derivation algorithms.
Definition: qca_basic.h:904
QCA::Cipher::CFB
operate in Cipher FeedBack mode
Definition: qca_basic.h:597
QCA::PBKDF2
Password based key derivation function version 2.
Definition: qca_basic.h:1020
QCA::MemoryRegion
Array of bytes that may be optionally secured.
Definition: qca_tools.h:90