summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-09-25 15:49:18 +0100
committerRobin Watts <robin.watts@artifex.com>2015-09-28 13:28:44 +0100
commit825ea24206936d37681921a624a25be8628b05a9 (patch)
tree4a00ac8054b30dd46d9f181346dc4d6250367c04 /source
parent78908c40963252284488b5ef10238d361ca543fa (diff)
downloadmupdf-825ea24206936d37681921a624a25be8628b05a9.tar.xz
Bug 696182: Fix Revision 6 PDF encryption.
Take on 2 patches from Zeniko to solve problems with the latest version of PDF encryption. Many thanks.
Diffstat (limited to 'source')
-rw-r--r--source/pdf/pdf-crypt.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/source/pdf/pdf-crypt.c b/source/pdf/pdf-crypt.c
index 17419581..56142d3b 100644
--- a/source/pdf/pdf-crypt.c
+++ b/source/pdf/pdf-crypt.c
@@ -448,10 +448,16 @@ pdf_compute_encryption_key_r5(fz_context *ctx, pdf_crypt *crypt, unsigned char *
/* Step 3.5/4.5 - compute file encryption key from OE/UE */
- memcpy(buffer + pwlen, crypt->u + 40, 8);
+ if (ownerkey)
+ {
+ memcpy(buffer + pwlen, crypt->o + 40, 8);
+ memcpy(buffer + pwlen + 8, crypt->u, 48);
+ }
+ else
+ memcpy(buffer + pwlen, crypt->u + 40, 8);
fz_sha256_init(&sha256);
- fz_sha256_update(&sha256, buffer, pwlen + 8);
+ fz_sha256_update(&sha256, buffer, pwlen + 8 + (ownerkey ? 48 : 0));
fz_sha256_final(&sha256, buffer);
/* clear password buffer and use it as iv */
@@ -550,7 +556,9 @@ pdf_compute_encryption_key_r6(fz_context *ctx, pdf_crypt *crypt, unsigned char *
(ownerkey ? crypt->o : crypt->u) + 32,
ownerkey ? crypt->u : NULL, validationkey);
pdf_compute_hardened_hash_r6(ctx, password, pwlen,
- crypt->u + 40, NULL, hash);
+ (ownerkey ? crypt->o : crypt->u) + 40,
+ (ownerkey ? crypt->u : NULL),
+ hash);
memset(iv, 0, sizeof(iv));
if (aes_setkey_dec(&aes, hash, 256))