1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
23 //------------------------------------------------------------------------
25 //------------------------------------------------------------------------
30 // Generate a file key. The <fileKey> buffer must have space for at
31 // least 16 bytes. Checks <ownerPassword> and then <userPassword>
32 // and returns true if either is correct. Sets <ownerPasswordOk> if
33 // the owner password was correct. Either or both of the passwords
34 // may be NULL, which is treated as an empty string.
35 static GBool
makeFileKey(int encVersion
, int encRevision
, int keyLength
,
36 GString
*ownerKey
, GString
*userKey
,
37 int permissions
, GString
*fileID
,
38 GString
*ownerPassword
, GString
*userPassword
,
39 Guchar
*fileKey
, GBool encryptMetadata
,
40 GBool
*ownerPasswordOk
);
44 static GBool
makeFileKey2(int encVersion
, int encRevision
, int keyLength
,
45 GString
*ownerKey
, GString
*userKey
,
46 int permissions
, GString
*fileID
,
47 GString
*userPassword
, Guchar
*fileKey
,
48 GBool encryptMetadata
);
51 //------------------------------------------------------------------------
53 //------------------------------------------------------------------------
55 struct DecryptRC4State
{
61 struct DecryptAESState
{
69 class DecryptStream
: public FilterStream
{
72 DecryptStream(Stream
*strA
, Guchar
*fileKey
,
73 CryptAlgorithm algoA
, int keyLength
,
74 int objNum
, int objGen
);
75 virtual ~DecryptStream();
76 virtual StreamKind
getKind() { return strWeird
; }
78 virtual int getChar();
79 virtual int lookChar();
80 virtual GBool
isBinary(GBool last
);
81 virtual Stream
*getUndecodedStream() { return this; }
87 Guchar objKey
[16 + 9];