source: trunk/poppler/mypoppler/poppler/Decrypt.h @ 461

Last change on this file since 461 was 277, checked in by rbri, 12 years ago

PDF plugin: Poppler library updated to version 0.12.3

File size: 3.1 KB
Line 
1//========================================================================
2//
3// Decrypt.h
4//
5// Copyright 1996-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2008 Julien Rebetez <julien@fhtagn.net>
17// Copyright (C) 2009 David Benjamin <davidben@mit.edu>
18//
19// To see a description of the changes please see the Changelog file that
20// came with your tarball or type make ChangeLog if you are building from git
21//
22//========================================================================
23
24#ifndef DECRYPT_H
25#define DECRYPT_H
26
27#ifdef USE_GCC_PRAGMAS
28#pragma interface
29#endif
30
31#include "goo/gtypes.h"
32#include "goo/GooString.h"
33#include "Object.h"
34#include "Stream.h"
35
36//------------------------------------------------------------------------
37// Decrypt
38//------------------------------------------------------------------------
39
40class Decrypt {
41public:
42  static void md5(Guchar *msg, int msgLen, Guchar *digest);
43
44  // Generate a file key.  The <fileKey> buffer must have space for at
45  // least 16 bytes.  Checks <ownerPassword> and then <userPassword>
46  // and returns true if either is correct.  Sets <ownerPasswordOk> if
47  // the owner password was correct.  Either or both of the passwords
48  // may be NULL, which is treated as an empty string.
49  static GBool makeFileKey(int encVersion, int encRevision, int keyLength,
50                           GooString *ownerKey, GooString *userKey,
51                           int permissions, GooString *fileID,
52                           GooString *ownerPassword, GooString *userPassword,
53                           Guchar *fileKey, GBool encryptMetadata,
54                           GBool *ownerPasswordOk);
55
56private:
57
58  static GBool makeFileKey2(int encVersion, int encRevision, int keyLength,
59                            GooString *ownerKey, GooString *userKey,
60                            int permissions, GooString *fileID,
61                            GooString *userPassword, Guchar *fileKey,
62                            GBool encryptMetadata);
63};
64
65//------------------------------------------------------------------------
66// DecryptStream
67//------------------------------------------------------------------------
68
69struct DecryptRC4State {
70  Guchar state[256];
71  Guchar x, y;
72  int buf;
73};
74
75struct DecryptAESState {
76  Guint w[44];
77  Guchar state[16];
78  Guchar cbc[16];
79  Guchar buf[16];
80  int bufIdx;
81};
82
83class DecryptStream: public FilterStream {
84public:
85
86  DecryptStream(Stream *strA, Guchar *fileKey,
87                CryptAlgorithm algoA, int keyLength,
88                int objNum, int objGen);
89  virtual ~DecryptStream();
90  virtual StreamKind getKind() { return strWeird; }
91  virtual void reset();
92  virtual int getChar();
93  virtual int lookChar();
94  virtual int getPos();
95  virtual GBool isBinary(GBool last);
96  virtual Stream *getUndecodedStream() { return this; }
97
98private:
99
100  CryptAlgorithm algo;
101  int objKeyLength;
102  Guchar objKey[16 + 9];
103  int charactersRead; // so that getPos() can be correct
104
105  union {
106    DecryptRC4State rc4;
107    DecryptAESState aes;
108  } state;
109};
110
111#endif
Note: See TracBrowser for help on using the repository browser.