Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_encrypt.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/include/fpdfapi/fpdf_parser.h" 7 #include "core/include/fpdfapi/fpdf_parser.h"
8 8
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 108 }
109 static FX_BOOL _LoadCryptInfo(CPDF_Dictionary* pEncryptDict, 109 static FX_BOOL _LoadCryptInfo(CPDF_Dictionary* pEncryptDict,
110 const CFX_ByteStringC& name, 110 const CFX_ByteStringC& name,
111 int& cipher, 111 int& cipher,
112 int& keylen) { 112 int& keylen) {
113 int Version = pEncryptDict->GetInteger("V"); 113 int Version = pEncryptDict->GetInteger("V");
114 cipher = FXCIPHER_RC4; 114 cipher = FXCIPHER_RC4;
115 keylen = 0; 115 keylen = 0;
116 if (Version >= 4) { 116 if (Version >= 4) {
117 CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDict("CF"); 117 CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDict("CF");
118 if (pCryptFilters == NULL) { 118 if (!pCryptFilters) {
119 return FALSE; 119 return FALSE;
120 } 120 }
121 if (name == "Identity") { 121 if (name == "Identity") {
122 cipher = FXCIPHER_NONE; 122 cipher = FXCIPHER_NONE;
123 } else { 123 } else {
124 CPDF_Dictionary* pDefFilter = pCryptFilters->GetDict(name); 124 CPDF_Dictionary* pDefFilter = pCryptFilters->GetDict(name);
125 if (pDefFilter == NULL) { 125 if (!pDefFilter) {
126 return FALSE; 126 return FALSE;
127 } 127 }
128 int nKeyBits = 0; 128 int nKeyBits = 0;
129 if (Version == 4) { 129 if (Version == 4) {
130 nKeyBits = pDefFilter->GetInteger("Length", 0); 130 nKeyBits = pDefFilter->GetInteger("Length", 0);
131 if (nKeyBits == 0) { 131 if (nKeyBits == 0) {
132 nKeyBits = pEncryptDict->GetInteger("Length", 128); 132 nKeyBits = pEncryptDict->GetInteger("Length", 128);
133 } 133 }
134 } else { 134 } else {
135 nKeyBits = pEncryptDict->GetInteger("Length", 256); 135 nKeyBits = pEncryptDict->GetInteger("Length", 256);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 CRYPT_SHA256Update(sha, password, size); 322 CRYPT_SHA256Update(sha, password, size);
323 CRYPT_SHA256Update(sha, pkey + 32, 8); 323 CRYPT_SHA256Update(sha, pkey + 32, 8);
324 if (bOwner) { 324 if (bOwner) {
325 CRYPT_SHA256Update(sha, ukey, 48); 325 CRYPT_SHA256Update(sha, ukey, 48);
326 } 326 }
327 CRYPT_SHA256Finish(sha, digest); 327 CRYPT_SHA256Finish(sha, digest);
328 } 328 }
329 if (FXSYS_memcmp(digest, pkey, 32) != 0) { 329 if (FXSYS_memcmp(digest, pkey, 32) != 0) {
330 return FALSE; 330 return FALSE;
331 } 331 }
332 if (key == NULL) { 332 if (!key) {
333 return TRUE; 333 return TRUE;
334 } 334 }
335 if (m_Revision >= 6) { 335 if (m_Revision >= 6) {
336 Revision6_Hash(password, size, (const uint8_t*)pkey + 40, 336 Revision6_Hash(password, size, (const uint8_t*)pkey + 40,
337 (bOwner ? (const uint8_t*)ukey : NULL), digest); 337 (bOwner ? (const uint8_t*)ukey : NULL), digest);
338 } else { 338 } else {
339 CRYPT_SHA256Start(sha); 339 CRYPT_SHA256Start(sha);
340 CRYPT_SHA256Update(sha, password, size); 340 CRYPT_SHA256Update(sha, password, size);
341 CRYPT_SHA256Update(sha, pkey + 40, 8); 341 CRYPT_SHA256Update(sha, pkey + 40, 8);
342 if (bOwner) { 342 if (bOwner) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 392 }
393 int CPDF_StandardSecurityHandler::CheckPassword(const uint8_t* password, 393 int CPDF_StandardSecurityHandler::CheckPassword(const uint8_t* password,
394 FX_DWORD size, 394 FX_DWORD size,
395 FX_BOOL bOwner, 395 FX_BOOL bOwner,
396 uint8_t* key, 396 uint8_t* key,
397 int32_t key_len) { 397 int32_t key_len) {
398 if (m_Revision >= 5) { 398 if (m_Revision >= 5) {
399 return AES256_CheckPassword(password, size, bOwner, key); 399 return AES256_CheckPassword(password, size, bOwner, key);
400 } 400 }
401 uint8_t keybuf[32]; 401 uint8_t keybuf[32];
402 if (key == NULL) { 402 if (!key) {
403 key = keybuf; 403 key = keybuf;
404 } 404 }
405 if (bOwner) { 405 if (bOwner) {
406 return CheckOwnerPassword(password, size, key, key_len); 406 return CheckOwnerPassword(password, size, key, key_len);
407 } 407 }
408 return CheckUserPassword(password, size, FALSE, key, key_len) || 408 return CheckUserPassword(password, size, FALSE, key, key_len) ||
409 CheckUserPassword(password, size, TRUE, key, key_len); 409 CheckUserPassword(password, size, TRUE, key, key_len);
410 } 410 }
411 FX_BOOL CPDF_StandardSecurityHandler::CheckUserPassword( 411 FX_BOOL CPDF_StandardSecurityHandler::CheckUserPassword(
412 const uint8_t* password, 412 const uint8_t* password,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 const uint8_t* user_pass, 534 const uint8_t* user_pass,
535 FX_DWORD user_size, 535 FX_DWORD user_size,
536 const uint8_t* owner_pass, 536 const uint8_t* owner_pass,
537 FX_DWORD owner_size, 537 FX_DWORD owner_size,
538 FX_BOOL bDefault, 538 FX_BOOL bDefault,
539 FX_DWORD type) { 539 FX_DWORD type) {
540 int cipher = 0, key_len = 0; 540 int cipher = 0, key_len = 0;
541 if (!LoadDict(pEncryptDict, type, cipher, key_len)) { 541 if (!LoadDict(pEncryptDict, type, cipher, key_len)) {
542 return; 542 return;
543 } 543 }
544 if (bDefault && (owner_pass == NULL || owner_size == 0)) { 544 if (bDefault && (!owner_pass || owner_size == 0)) {
545 owner_pass = user_pass; 545 owner_pass = user_pass;
546 owner_size = user_size; 546 owner_size = user_size;
547 } 547 }
548 if (m_Revision >= 5) { 548 if (m_Revision >= 5) {
549 int t = (int)time(NULL); 549 int t = (int)time(NULL);
550 uint8_t sha[128]; 550 uint8_t sha[128];
551 CRYPT_SHA256Start(sha); 551 CRYPT_SHA256Start(sha);
552 CRYPT_SHA256Update(sha, (uint8_t*)&t, sizeof t); 552 CRYPT_SHA256Update(sha, (uint8_t*)&t, sizeof t);
553 CRYPT_SHA256Update(sha, m_EncryptKey, 32); 553 CRYPT_SHA256Update(sha, m_EncryptKey, 32);
554 CRYPT_SHA256Update(sha, (uint8_t*)"there", 5); 554 CRYPT_SHA256Update(sha, (uint8_t*)"there", 5);
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 str = dest_buf; 1029 str = dest_buf;
1030 } 1030 }
1031 CPDF_StandardCryptoHandler::CPDF_StandardCryptoHandler() { 1031 CPDF_StandardCryptoHandler::CPDF_StandardCryptoHandler() {
1032 m_pAESContext = NULL; 1032 m_pAESContext = NULL;
1033 m_Cipher = FXCIPHER_NONE; 1033 m_Cipher = FXCIPHER_NONE;
1034 m_KeyLen = 0; 1034 m_KeyLen = 0;
1035 } 1035 }
1036 CPDF_StandardCryptoHandler::~CPDF_StandardCryptoHandler() { 1036 CPDF_StandardCryptoHandler::~CPDF_StandardCryptoHandler() {
1037 FX_Free(m_pAESContext); 1037 FX_Free(m_pAESContext);
1038 } 1038 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698