AbZip  1.0.0
AesEncryption.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Andy Bray
4 **
5 ** This file is part of AbZip.
6 **
7 ** AbZip is free software: you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation, either version 3 of the License, or
10 ** (at your option) any later version.
11 **
12 ** AbZip 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
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with AbZip. If not, see <http://www.gnu.org/licenses/>.
19 **
20 ****************************************************************************/
21 /*
22  ---------------------------------------------------------------------------
23  Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
24 
25  LICENSE TERMS
26 
27  The redistribution and use of this software (with or without changes)
28  is allowed without the payment of fees or royalties provided that:
29 
30  1. source code distributions include the above copyright notice, this
31  list of conditions and the following disclaimer;
32 
33  2. binary distributions include the above copyright notice, this list
34  of conditions and the following disclaimer in their documentation;
35 
36  3. the name of the copyright holder is not used to endorse products
37  built using this software without specific written permission.
38 
39  DISCLAIMER
40 
41  This software is provided 'as is' with no explicit or implied warranties
42  in respect of its properties, including, but not limited to, correctness
43  and/or fitness for purpose.
44  ---------------------------------------------------------------------------
45  */
46 
47 
48 
49 #ifndef AESENCRYPTION_H
50 #define AESENCRYPTION_H
51 
52 #ifdef USE_AES
53 
54 #include "encryption.h"
55 
56 #define CRC_ENCRYPT_HEADER_SIZE 12
57 
58 #define AES_PWVERIFYSIZE (2)
59 #define AES_AUTHCODESIZE (10)
60 #define AES_MAXSALTLENGTH (16)
61 #define AES_VERSION (0x0001)
62 #define AES_ENCRYPTIONMODE (0x03)
63 #define AES_HEADERSIZE (11)
64 #define AES_KEYSIZE(mode) (64 + (mode * 64))
65 
66 #include <aes.h>
67 #include <fileenc.h>
68 #include <prng.h>
69 #include <entropy.h>
70 
71 class AesEncryption : public Encryption
72 {
73 public:
74  AesEncryption( );
75  virtual ~AesEncryption();
76 
77  virtual bool init( const QString& password );
78 
79  virtual void encryptBytes( char* buffer, qint64 read);
80  virtual void decryptBytes( char* buffer, qint64 read);
81 
82  virtual bool decryptHeader(QIODevice* ioDevice, const QString& password, quint16 crc );
83  virtual qint32 encryptHeader(QIODevice* ioDevice, const QString& password, quint16 crc );
84 
85  virtual qint32 decryptFooter(QIODevice* ioDevice, quint16 crc );
86  virtual qint32 encryptFooter(QIODevice* ioDevice );
87 
88  virtual qint32 size(){ return headerSize; }
89 
90 
91 
92 private:
93  qint32 headerSize;
94 
95  unsigned char passverify[AES_PWVERIFYSIZE];
96  unsigned char saltvalue[AES_MAXSALTLENGTH];
97  quint32 saltlength;
98 
99 
100  fcrypt_ctx aes_ctx;
101  prng_ctx aes_rng[1];
102 };
103 
104 #endif // USE_AES
105 
106 #endif // CRCENCRYPTION_H
Definition: fileenc.h:84
Definition: prng.h:62
Definition: encryption.h:40