QCA

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 <[email protected]>
4  * Copyright (C) 2004-2007 Brad Hards <[email protected]>
5  * Copyright (C) 2013-2016 Ivan Romanov <[email protected]>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 
34 #ifndef QCA_BASIC_H
35 #define QCA_BASIC_H
36 
37 #include "qca_core.h"
38 
39 #include <QIODevice>
40 
41 namespace QCA {
42 
65 class QCA_EXPORT Random : public Algorithm
66 {
67 public:
74  Random(const QString &provider = QString());
75 
81  Random(const Random &from);
82 
83  ~Random() override;
84 
90  Random &operator=(const Random &from);
91 
100  uchar nextByte();
101 
112  SecureArray nextBytes(int size);
113 
125  static uchar randomChar();
126 
136  static int randomInt();
137 
148  static SecureArray randomArray(int size);
149 
150 private:
151  class Private;
152  Private *d;
153 };
154 
208 class QCA_EXPORT Hash : public Algorithm, public BufferedComputation
209 {
210 public:
219  explicit Hash(const QString &type, const QString &provider = QString());
220 
226  Hash(const Hash &from);
227 
228  ~Hash() override;
229 
235  Hash &operator=(const Hash &from);
236 
244  static QStringList supportedTypes(const QString &provider = QString());
245 
249  QString type() const;
250 
261  void clear() override;
262 
274  void update(const MemoryRegion &a) override;
275 
281  void update(const QByteArray &a);
282 
297  void update(const char *data, int len = -1);
298 
321  void update(QIODevice *file);
322 
336  MemoryRegion final() override;
337 
358  MemoryRegion hash(const MemoryRegion &array);
359 
374  QString hashToString(const MemoryRegion &array);
375 
376 private:
377  class Private;
378  Private *d;
379 };
380 
581 class QCA_EXPORT Cipher : public Algorithm, public Filter
582 {
583 public:
591  enum Mode
592  {
593  CBC,
594  CFB,
595  ECB,
596  OFB,
597  CTR,
598  GCM,
599  CCM
600  };
601 
608  enum Padding
609  {
612  PKCS7
613  };
614 
631  Cipher(const QString & type,
632  Mode mode,
633  Padding pad = DefaultPadding,
634  Direction dir = Encode,
635  const SymmetricKey & key = SymmetricKey(),
637  const QString & provider = QString());
638 
656  Cipher(const QString & type,
657  Mode mode,
658  Padding pad,
659  Direction dir,
660  const SymmetricKey & key,
661  const InitializationVector &iv,
662  const AuthTag & tag,
663  const QString & provider = QString());
664 
670  Cipher(const Cipher &from);
671 
672  ~Cipher() override;
673 
679  Cipher &operator=(const Cipher &from);
680 
688  static QStringList supportedTypes(const QString &provider = QString());
689 
693  QString type() const;
694 
698  Mode mode() const;
699 
703  Padding padding() const;
704 
708  Direction direction() const;
709 
713  KeyLength keyLength() const;
714 
721  bool validKeyLength(int n) const;
722 
726  int blockSize() const;
727 
731  AuthTag tag() const;
732 
736  void clear() override;
737 
745  MemoryRegion update(const MemoryRegion &a) override;
746 
751  MemoryRegion final() override;
752 
758  bool ok() const override;
759 
773  void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv = InitializationVector());
774 
789  void setup(Direction dir, const SymmetricKey &key, const InitializationVector &iv, const AuthTag &tag);
790 
800  static QString withAlgorithms(const QString &cipherType, Mode modeType, Padding paddingType);
801 
802 private:
803  class Private;
804  Private *d;
805 };
806 
827 class QCA_EXPORT MessageAuthenticationCode : public Algorithm, public BufferedComputation
828 {
829 public:
839  MessageAuthenticationCode(const QString &type, const SymmetricKey &key, const QString &provider = QString());
840 
850 
851  ~MessageAuthenticationCode() override;
852 
862 
871  static QStringList supportedTypes(const QString &provider = QString());
872 
876  QString type() const;
877 
881  KeyLength keyLength() const;
882 
889  bool validKeyLength(int n) const;
890 
903  void clear() override;
904 
912  void update(const MemoryRegion &array) override;
913 
925  MemoryRegion final() override;
926 
932  void setup(const SymmetricKey &key);
933 
934 private:
935  class Private;
936  Private *d;
937 };
938 
953 class QCA_EXPORT KeyDerivationFunction : public Algorithm
954 {
955 public:
962 
963  ~KeyDerivationFunction() override;
964 
973  KeyDerivationFunction &operator=(const KeyDerivationFunction &from);
974 
987  SymmetricKey makeKey(const SecureArray & secret,
988  const InitializationVector &salt,
989  unsigned int keyLength,
990  unsigned int iterationCount);
991 
1005  SymmetricKey makeKey(const SecureArray & secret,
1006  const InitializationVector &salt,
1007  unsigned int keyLength,
1008  int msecInterval,
1009  unsigned int * iterationCount);
1010 
1023  static QString withAlgorithm(const QString &kdfType, const QString &algType);
1024 
1025 protected:
1032  KeyDerivationFunction(const QString &type, const QString &provider);
1033 
1034 private:
1035  class Private;
1036  Private *d;
1037 };
1038 
1049 class QCA_EXPORT PBKDF1 : public KeyDerivationFunction
1050 {
1051 public:
1058  explicit PBKDF1(const QString &algorithm = QStringLiteral("sha1"), const QString &provider = QString())
1059  : KeyDerivationFunction(withAlgorithm(QStringLiteral("pbkdf1"), algorithm), provider)
1060  {
1061  }
1062 };
1063 
1074 class QCA_EXPORT PBKDF2 : public KeyDerivationFunction
1075 {
1076 public:
1083  explicit PBKDF2(const QString &algorithm = QStringLiteral("sha1"), const QString &provider = QString())
1084  : KeyDerivationFunction(withAlgorithm(QStringLiteral("pbkdf2"), algorithm), provider)
1085  {
1086  }
1087 };
1088 
1100 class QCA_EXPORT HKDF : public Algorithm
1101 {
1102 public:
1109  explicit HKDF(const QString &algorithm = QStringLiteral("sha256"), const QString &provider = QString());
1110 
1116  HKDF(const HKDF &from);
1117 
1118  ~HKDF() override;
1119 
1128  HKDF &operator=(const HKDF &from);
1129 
1142  SymmetricKey makeKey(const SecureArray & secret,
1143  const InitializationVector &salt,
1144  const InitializationVector &info,
1145  unsigned int keyLength);
1146 };
1147 
1148 }
1149 
1150 #endif
PBKDF2(const QString &algorithm=QStringLiteral("sha1"), const QString &provider=QString())
Standard constructor.
Definition: qca_basic.h:1083
General superclass for an algorithm.
Definition: qca_core.h:1163
Padding
Padding variations for cipher algorithms.
Definition: qca_basic.h:608
General class for cipher (encryption / decryption) algorithms.
Definition: qca_basic.h:581
Mode
Mode settings for cipher algorithms.
Definition: qca_basic.h:591
Source of random numbers.
Definition: qca_basic.h:65
General superclass for buffered computation algorithms.
Definition: qca_core.h:1051
operate in Galois Counter Mode
Definition: qca_basic.h:598
operate in Output FeedBack Mode
Definition: qca_basic.h:596
Container for keys for symmetric encryption algorithms.
Definition: qca_core.h:1263
Container for authentication tag.
Definition: qca_core.h:1346
General class for message authentication code (MAC) algorithms.
Definition: qca_basic.h:827
Simple container for acceptable key lengths.
Definition: qca_core.h:700
PBKDF1(const QString &algorithm=QStringLiteral("sha1"), const QString &provider=QString())
Standard constructor.
Definition: qca_basic.h:1058
Header file for core QCA infrastructure.
Default for cipher-mode.
Definition: qca_basic.h:610
operate in Electronic Code Book mode
Definition: qca_basic.h:595
Container for initialisation vectors and nonces.
Definition: qca_core.h:1309
Direction
Direction settings for symmetric algorithms.
Definition: qca_core.h:140
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:41
operate in Cipher Block Chaining mode
Definition: qca_basic.h:593
Do not use padding.
Definition: qca_basic.h:611
General class for hashing algorithms.
Definition: qca_basic.h:208
Secure array of bytes.
Definition: qca_tools.h:316
Password based key derivation function version 1.
Definition: qca_basic.h:1049
operate in CounTer Mode
Definition: qca_basic.h:597
Operate in the "forward" direction; for example, encrypting.
Definition: qca_core.h:142
General superclass for filtering transformation algorithms.
Definition: qca_core.h:1107
General superclass for key derivation algorithms.
Definition: qca_basic.h:953
operate in Cipher FeedBack mode
Definition: qca_basic.h:594
Password based key derivation function version 2.
Definition: qca_basic.h:1074
Array of bytes that may be optionally secured.
Definition: qca_tools.h:90
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 23:03:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.