Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf/xpdf/Decrypt.cc
diff options
context:
space:
mode:
Diffstat (limited to 'pdf/xpdf/Decrypt.cc')
-rw-r--r--pdf/xpdf/Decrypt.cc60
1 files changed, 29 insertions, 31 deletions
diff --git a/pdf/xpdf/Decrypt.cc b/pdf/xpdf/Decrypt.cc
index dca3762..dab0750 100644
--- a/pdf/xpdf/Decrypt.cc
+++ b/pdf/xpdf/Decrypt.cc
@@ -74,6 +74,7 @@ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength,
int len, i, j;
// try using the supplied owner password to generate the user password
+ *ownerPasswordOk = gFalse;
if (ownerPassword) {
len = ownerPassword->getLength();
if (len < 32) {
@@ -82,43 +83,40 @@ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength,
} else {
memcpy(test, ownerPassword->getCString(), 32);
}
- } else {
- memcpy(test, passwordPad, 32);
- }
- md5(test, 32, test);
- if (encRevision == 3) {
- for (i = 0; i < 50; ++i) {
- md5(test, 16, test);
- }
- }
- 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;
+ md5(test, 32, test);
+ if (encRevision == 3) {
+ for (i = 0; i < 50; ++i) {
+ md5(test, 16, test);
}
- rc4InitKey(tmpKey, keyLength, fState);
+ }
+ if (encRevision == 2) {
+ rc4InitKey(test, keyLength, fState);
fx = fy = 0;
- for (j = 0; j < 32; ++j) {
- test2[j] = rc4DecryptByte(fState, &fx, &fy, test2[j]);
+ 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 *)test2, 32);
- if (makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey,
- permissions, fileID, userPassword2, fileKey)) {
- *ownerPasswordOk = gTrue;
+ userPassword2 = new GString((char *)test2, 32);
+ if (makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey,
+ permissions, fileID, userPassword2, fileKey)) {
+ *ownerPasswordOk = gTrue;
+ delete userPassword2;
+ return gTrue;
+ }
delete userPassword2;
- return gTrue;
}
- *ownerPasswordOk = gFalse;
- delete userPassword2;
// try using the supplied user password
return makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey,