diff options
-rw-r--r-- | source/pdf/pdf-crypt.c | 14 |
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)) |