1
//========================================================================
5
// Copyright 1996-2003 Glyph & Cog, LLC
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>
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
22
//========================================================================
27
#ifdef USE_GCC_PRAGMAS
31
#include "goo/gtypes.h"
32
#include "goo/GooString.h"
36
//------------------------------------------------------------------------
38
//------------------------------------------------------------------------
42
static void md5(Guchar *msg, int msgLen, Guchar *digest);
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);
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);
65
//------------------------------------------------------------------------
67
//------------------------------------------------------------------------
69
struct DecryptRC4State {
75
struct DecryptAESState {
83
class DecryptStream: public FilterStream {
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; }
92
virtual int getChar();
93
virtual int lookChar();
95
virtual GBool isBinary(GBool last);
96
virtual Stream *getUndecodedStream() { return this; }
102
Guchar objKey[16 + 9];
103
int charactersRead; // so that getPos() can be correct