Decrypt.h
1//========================================================================
2//
3// Decrypt.h
4//
5// Copyright 1996-2002 Glyph & Cog, LLC
6//
7//========================================================================
8
9#ifndef DECRYPT_H
10#define DECRYPT_H
11
12#include <aconf.h>
13
14#ifdef USE_GCC_PRAGMAS
15#pragma interface
16#endif
17
18#include "gtypes.h"
19#include "GString.h"
20
21//------------------------------------------------------------------------
22// Decrypt
23//------------------------------------------------------------------------
24
25class Decrypt {
26public:
27
28 // Initialize the decryptor object.
29 Decrypt(Guchar *fileKey, int keyLength, int objNum, int objGen);
30
31 // Reset decryption.
32 void reset();
33
34 // Decrypt one byte.
35 Guchar decryptByte(Guchar c);
36
37 // Generate a file key. The <fileKey> buffer must have space for at
38 // least 16 bytes. Checks <ownerPassword> and then <userPassword>
39 // and returns true if either is correct. Sets <ownerPasswordOk> if
40 // the owner password was correct. Either or both of the passwords
41 // may be NULL, which is treated as an empty string.
42 static GBool makeFileKey(int encVersion, int encRevision, int keyLength,
43 GString *ownerKey, GString *userKey,
44 int permissions, GString *fileID,
45 GString *ownerPassword, GString *userPassword,
46 Guchar *fileKey, GBool *ownerPasswordOk);
47
48private:
49
50 static GBool makeFileKey2(int encVersion, int encRevision, int keyLength,
51 GString *ownerKey, GString *userKey,
52 int permissions, GString *fileID,
53 GString *userPassword, Guchar *fileKey);
54
55 int objKeyLength;
56 Guchar objKey[21];
57 Guchar state[256];
58 Guchar x, y;
59};
60
61#endif