#pragma implementation
#endif
+#include <string.h>
#include "gmem.h"
#include "Decrypt.h"
GString *ownerKey, GString *userKey,
int permissions, GString *fileID,
GString *ownerPassword, GString *userPassword,
- Guchar *fileKey, GBool *ownerPasswordOk) {
+ Guchar *fileKey, GBool encryptMetadata,
+ GBool *ownerPasswordOk) {
Guchar test[32], test2[32];
GString *userPassword2;
Guchar fState[256];
}
userPassword2 = new GString((char *)test2, 32);
if (makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey,
- permissions, fileID, userPassword2, fileKey)) {
+ permissions, fileID, userPassword2, fileKey,
+ encryptMetadata)) {
*ownerPasswordOk = gTrue;
delete userPassword2;
return gTrue;
// try using the supplied user password
return makeFileKey2(encVersion, encRevision, keyLength, ownerKey, userKey,
- permissions, fileID, userPassword, fileKey);
+ permissions, fileID, userPassword, fileKey,
+ encryptMetadata);
}
GBool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength,
GString *ownerKey, GString *userKey,
int permissions, GString *fileID,
- GString *userPassword, Guchar *fileKey) {
+ GString *userPassword, Guchar *fileKey,
+ GBool encryptMetadata) {
Guchar *buf;
Guchar test[32];
Guchar fState[256];
GBool ok;
// generate file key
- buf = (Guchar *)gmalloc(68 + fileID->getLength());
+ buf = (Guchar *)gmalloc(72 + fileID->getLength());
if (userPassword) {
len = userPassword->getLength();
if (len < 32) {
buf[66] = (permissions >> 16) & 0xff;
buf[67] = (permissions >> 24) & 0xff;
memcpy(buf + 68, fileID->getCString(), fileID->getLength());
- md5(buf, 68 + fileID->getLength(), fileKey);
+ len = 68 + fileID->getLength();
+ if (!encryptMetadata) {
+ buf[len++] = 0xff;
+ buf[len++] = 0xff;
+ buf[len++] = 0xff;
+ buf[len++] = 0xff;
+ }
+ md5(buf, len, fileKey);
if (encRevision == 3) {
for (i = 0; i < 50; ++i) {
md5(fileKey, keyLength, fileKey);