fixed l_reserveobj (thanks to Marcel F. Krüger zauguin@gmail.com )
[luatex.git] / source / libs / poppler / poppler-0.34.0 / poppler / Decrypt.h
blob10a6386c6b55525aa7946adeeea86af50fcc5e61
1 //========================================================================
2 //
3 // Decrypt.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2008 Julien Rebetez <julien@fhtagn.net>
17 // Copyright (C) 2009 David Benjamin <davidben@mit.edu>
18 // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
19 // Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
20 // Copyright (C) 2013 Albert Astals Cid <aacid@kde.org>
21 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
23 // To see a description of the changes please see the Changelog file that
24 // came with your tarball or type make ChangeLog if you are building from git
26 //========================================================================
28 #ifndef DECRYPT_H
29 #define DECRYPT_H
31 #ifdef USE_GCC_PRAGMAS
32 #pragma interface
33 #endif
35 #include "goo/gtypes.h"
36 #include "goo/GooString.h"
37 #include "Object.h"
38 #include "Stream.h"
40 //------------------------------------------------------------------------
41 // Decrypt
42 //------------------------------------------------------------------------
44 class Decrypt {
45 public:
47 // Generate a file key. The <fileKey> buffer must have space for at
48 // least 16 bytes. Checks <ownerPassword> and then <userPassword>
49 // and returns true if either is correct. Sets <ownerPasswordOk> if
50 // the owner password was correct. Either or both of the passwords
51 // may be NULL, which is treated as an empty string.
52 static GBool makeFileKey(int encVersion, int encRevision, int keyLength,
53 GooString *ownerKey, GooString *userKey,
54 GooString *ownerEnc, GooString *userEnc,
55 int permissions, GooString *fileID,
56 GooString *ownerPassword, GooString *userPassword,
57 Guchar *fileKey, GBool encryptMetadata,
58 GBool *ownerPasswordOk);
60 private:
62 static GBool makeFileKey2(int encVersion, int encRevision, int keyLength,
63 GooString *ownerKey, GooString *userKey,
64 int permissions, GooString *fileID,
65 GooString *userPassword, Guchar *fileKey,
66 GBool encryptMetadata);
69 //------------------------------------------------------------------------
70 // Helper classes
71 //------------------------------------------------------------------------
73 /* DecryptRC4State, DecryptAESState, DecryptAES256State are named like this for
74 * historical reasons, but they're used for encryption too.
75 * In case of decryption, the cbc field in AES and AES-256 contains the previous
76 * input block or the CBC initialization vector (IV) if the stream has just been
77 * reset). In case of encryption, it always contains the IV, whereas the
78 * previous output is kept in buf. The paddingReached field is only used in
79 * case of encryption. */
80 struct DecryptRC4State {
81 Guchar state[256];
82 Guchar x, y;
85 struct DecryptAESState {
86 Guint w[44];
87 Guchar state[16];
88 Guchar cbc[16];
89 Guchar buf[16];
90 GBool paddingReached; // encryption only
91 int bufIdx;
94 struct DecryptAES256State {
95 Guint w[60];
96 Guchar state[16];
97 Guchar cbc[16];
98 Guchar buf[16];
99 GBool paddingReached; // encryption only
100 int bufIdx;
103 class BaseCryptStream : public FilterStream {
104 public:
106 BaseCryptStream(Stream *strA, Guchar *fileKey, CryptAlgorithm algoA,
107 int keyLength, int objNum, int objGen);
108 virtual ~BaseCryptStream();
109 virtual StreamKind getKind() { return strCrypt; }
110 virtual void reset();
111 virtual int getChar();
112 virtual int lookChar() = 0;
113 virtual Goffset getPos();
114 virtual GBool isBinary(GBool last);
115 virtual Stream *getUndecodedStream() { return this; }
116 void setAutoDelete(GBool val);
118 protected:
119 CryptAlgorithm algo;
120 int objKeyLength;
121 Guchar objKey[32];
122 Goffset charactersRead; // so that getPos() can be correct
123 int nextCharBuff; // EOF means not read yet
124 GBool autoDelete;
126 union {
127 DecryptRC4State rc4;
128 DecryptAESState aes;
129 DecryptAES256State aes256;
130 } state;
133 //------------------------------------------------------------------------
134 // EncryptStream / DecryptStream
135 //------------------------------------------------------------------------
137 class EncryptStream : public BaseCryptStream {
138 public:
140 EncryptStream(Stream *strA, Guchar *fileKey, CryptAlgorithm algoA,
141 int keyLength, int objNum, int objGen);
142 ~EncryptStream();
143 virtual void reset();
144 virtual int lookChar();
147 class DecryptStream : public BaseCryptStream {
148 public:
150 DecryptStream(Stream *strA, Guchar *fileKey, CryptAlgorithm algoA,
151 int keyLength, int objNum, int objGen);
152 ~DecryptStream();
153 virtual void reset();
154 virtual int lookChar();
157 //------------------------------------------------------------------------
159 extern void md5(Guchar *msg, int msgLen, Guchar *digest);
161 #endif