]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/Decrypt.cc
sssshhh
[evince.git] / pdf / xpdf / Decrypt.cc
index dca3762c1b37c96458fca0c47f05bfc2d67a7f34..dab075093c3b7ab5a16516a9026fb8d2952de89b 100644 (file)
@@ -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,