Commit 6364c50f authored by Albert Astals Cid's avatar Albert Astals Cid

xpdf303: Support for aes256 et all in Decrypt/SecurityHandler

parent 39ce4575
This diff is collapsed.
......@@ -39,7 +39,6 @@
class Decrypt {
static void md5(Guchar *msg, int msgLen, Guchar *digest);
// Generate a file key. The <fileKey> buffer must have space for at
// least 16 bytes. Checks <ownerPassword> and then <userPassword>
......@@ -48,6 +47,7 @@ public:
// may be NULL, which is treated as an empty string.
static GBool makeFileKey(int encVersion, int encRevision, int keyLength,
GooString *ownerKey, GooString *userKey,
GooString *ownerEnc, GooString *userEnc,
int permissions, GooString *fileID,
GooString *ownerPassword, GooString *userPassword,
Guchar *fileKey, GBool encryptMetadata,
......@@ -80,6 +80,14 @@ struct DecryptAESState {
int bufIdx;
struct DecryptAES256State {
Guint w[60];
Guchar state[16];
Guchar cbc[16];
Guchar buf[16];
int bufIdx;
class DecryptStream: public FilterStream {
......@@ -99,13 +107,20 @@ private:
CryptAlgorithm algo;
int objKeyLength;
Guchar objKey[16 + 9];
Guchar objKey[32];
int charactersRead; // so that getPos() can be correct
union {
DecryptRC4State rc4;
DecryptAESState aes;
DecryptAES256State aes256;
} state;
extern void rc4InitKey(Guchar *key, int keyLen, Guchar *state);
extern Guchar rc4DecryptByte(Guchar *state, Guchar *x, Guchar *y, Guchar c);
extern void md5(Guchar *msg, int msgLen, Guchar *digest);
......@@ -1095,7 +1095,7 @@ void PDFDoc::writeTrailer(Guint uxrefOffset, int uxrefSize,
//calculate md5 digest
Guchar digest[16];
Decrypt::md5((Guchar*)message.getCString(), message.getLength(), digest);
md5((Guchar*)message.getCString(), message.getLength(), digest);
obj1.initString(new GooString((const char*)digest, 16));
//create ID array
This diff is collapsed.
......@@ -34,6 +34,9 @@ public:
SecurityHandler(PDFDoc *docA);
virtual ~SecurityHandler();
// Returns true if the file is actually unencrypted.
virtual GBool isUnencrypted() { return gFalse; }
// Check the document's encryption. If the document is encrypted,
// this will first try <ownerPassword> and <userPassword> (in
// "batch" mode), and if those fail, it will attempt to request a
......@@ -92,6 +95,7 @@ public:
StandardSecurityHandler(PDFDoc *docA, Object *encryptDictA);
virtual ~StandardSecurityHandler();
virtual GBool isUnencrypted();
virtual void *makeAuthData(GooString *ownerPassword,
GooString *userPassword);
virtual void *getAuthData();
......@@ -109,7 +113,7 @@ private:
int permFlags;
GBool ownerPasswordOk;
Guchar fileKey[16];
Guchar fileKey[32];
int fileKeyLength;
int encVersion;
int encRevision;
......@@ -117,6 +121,7 @@ private:
CryptAlgorithm encAlgorithm;
GooString *ownerKey, *userKey;
GooString *ownerEnc, *userEnc;
GooString *fileID;
GBool ok;
......@@ -71,7 +71,8 @@ enum StreamColorSpaceMode {
// include file dependency loops.
enum CryptAlgorithm {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment