diff options
author | Martin Kretzschmar <mkretzschmar@src.gnome.org> | 2003-03-31 16:45:09 (GMT) |
---|---|---|
committer | Martin Kretzschmar <mkretzschmar@src.gnome.org> | 2003-03-31 16:45:09 (GMT) |
commit | 28c37dbcf87665a4ccec58bef9ef8ff0697022dd (patch) | |
tree | 4fd39a6f8e50717677d56ad0bbb520baa77589f0 /pdf/xpdf/Decrypt.cc | |
parent | 6112dfe4b45b0305c7a6f61bd8a847f69f892cbb (diff) |
Import of Xpdf 2.00 for merge
Diffstat (limited to 'pdf/xpdf/Decrypt.cc')
-rw-r--r-- | pdf/xpdf/Decrypt.cc | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/pdf/xpdf/Decrypt.cc b/pdf/xpdf/Decrypt.cc index 8de4091..bb3e3f1 100644 --- a/pdf/xpdf/Decrypt.cc +++ b/pdf/xpdf/Decrypt.cc @@ -6,11 +6,12 @@ // //======================================================================== -#ifdef __GNUC__ +#include <aconf.h> + +#ifdef USE_GCC_PRAGMAS #pragma implementation #endif -#include <aconf.h> #include "gmem.h" #include "Decrypt.h" @@ -65,11 +66,12 @@ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength, int permissions, GString *fileID, GString *ownerPassword, GString *userPassword, Guchar *fileKey, GBool *ownerPasswordOk) { - Guchar test[32]; + Guchar test[32], test2[32]; GString *userPassword2; Guchar fState[256]; + Guchar tmpKey[16]; Guchar fx, fy; - int len, i; + int len, i, j; // try using the supplied owner password to generate the user password if (ownerPassword) { @@ -89,12 +91,26 @@ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength, md5(test, 16, test); } } - rc4InitKey(test, keyLength, fState); - fx = fy = 0; - for (i = 0; i < 32; ++i) { - test[i] = rc4DecryptByte(fState, &fx, &fy, ownerKey->getChar(i)); + if (encRevision == 2) { + rc4InitKey(test, keyLength, fState); + fx = fy = 0; + for (i = 0; i < 32; ++i) { + test2[i] = rc4DecryptByte(fState, &fx, &fy, ownerKey->getChar(i)); + } + } else { + memcpy(test2, ownerKey->getCString(), 32); + for (i = 19; i >= 0; --i) { + for (j = 0; j < keyLength; ++j) { + tmpKey[j] = test[j] ^ i; + } + rc4InitKey(tmpKey, keyLength, fState); + fx = fy = 0; + for (j = 0; j < 32; ++j) { + test2[j] = rc4DecryptByte(fState, &fx, &fy, test2[j]); + } + } } - userPassword2 = new GString((char *)test, 32); + userPassword2 = new GString((char *)test2, 32); if (makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey, permissions, fileID, userPassword2, fileKey)) { *ownerPasswordOk = gTrue; @@ -143,7 +159,7 @@ GBool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength, md5(buf, 68 + fileID->getLength(), fileKey); if (encRevision == 3) { for (i = 0; i < 50; ++i) { - md5(fileKey, 16, fileKey); + md5(fileKey, keyLength, fileKey); } } |