AbZip  1.0.0
CrcEncryption.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 #ifndef CRCENCRYPTION_H
23 #define CRCENCRYPTION_H
24 
25 #include "encryption.h"
26 
27 #define CRC_ENCRYPT_HEADER_SIZE 12
28 
29 class CrcEncryption : public Encryption
30 {
31 public:
32  CrcEncryption();
33 
34  virtual bool init( const QString& password );
35 
36  virtual void encryptBytes( char* buffer, qint64 read);
37  virtual void decryptBytes( char* buffer, qint64 read);
38 
39  virtual bool decryptHeader(QIODevice* ioDevice, const QString& password, quint16 crc );
40  virtual qint32 encryptHeader(QIODevice* ioDevice, const QString& password, quint16 crc );
41 
42  virtual qint32 size(){ return CRC_ENCRYPT_HEADER_SIZE; }
43 
44 private:
45  void initKeys( const QString& password );
46 
47  int decryptByte( );
48  quint32 updateChecksum(const quint32& crc, const quint32& val);
49  void updateKeys(int c);
50 
51  const quint32* crcTable;
52  quint32 keys[3];
53 };
54 
55 
56 #endif // CRCENCRYPTION_H
Definition: CrcEncryption.h:29
Definition: encryption.h:40