X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fxpdf%2FDecrypt.cc;h=dab075093c3b7ab5a16516a9026fb8d2952de89b;hb=1f7e03f2861f4b8d2bb75bd220754b7a89b7847e;hp=b58a6c55c4b1581e28aa940de66bc0f9375c1ece;hpb=8032fd96d450ac015c0153f1fa57e974d67b4993;p=evince.git diff --git a/pdf/xpdf/Decrypt.cc b/pdf/xpdf/Decrypt.cc index b58a6c55..dab07509 100644 --- a/pdf/xpdf/Decrypt.cc +++ b/pdf/xpdf/Decrypt.cc @@ -2,7 +2,7 @@ // // Decrypt.cc // -// Copyright 1996-2002 Glyph & Cog, LLC +// Copyright 1996-2003 Glyph & Cog, LLC // //======================================================================== @@ -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,