Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <time.h> | 7 #include <time.h> |
| 8 #include "../../../include/fpdfapi/fpdf_parser.h" | 8 #include "../../../include/fpdfapi/fpdf_parser.h" |
| 9 #include "../../../include/fdrm/fx_crypt.h" | 9 #include "../../../include/fdrm/fx_crypt.h" |
| 10 const FX_BYTE defpasscode[32] = { | 10 const FX_BYTE defpasscode[32] = { |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 if (m_Revision == 2) { | 399 if (m_Revision == 2) { |
| 400 FXSYS_memcpy32(ukeybuf, defpasscode, 32); | 400 FXSYS_memcpy32(ukeybuf, defpasscode, 32); |
| 401 CRYPT_ArcFourCryptBlock(ukeybuf, 32, key, key_len); | 401 CRYPT_ArcFourCryptBlock(ukeybuf, 32, key, key_len); |
| 402 } else { | 402 } else { |
| 403 FX_BYTE test[32], tmpkey[32]; | 403 FX_BYTE test[32], tmpkey[32]; |
| 404 FX_DWORD copy_len = sizeof(test); | 404 FX_DWORD copy_len = sizeof(test); |
| 405 if (copy_len > (FX_DWORD)ukey.GetLength()) { | 405 if (copy_len > (FX_DWORD)ukey.GetLength()) { |
| 406 copy_len = ukey.GetLength(); | 406 copy_len = ukey.GetLength(); |
| 407 } | 407 } |
| 408 FXSYS_memset32(test, 0, sizeof(test)); | 408 FXSYS_memset32(test, 0, sizeof(test)); |
| 409 FXSYS_memset32(tmpkey, 0, sizeof(tmpkey)); | |
| 409 FXSYS_memcpy32(test, (FX_LPCSTR)ukey, copy_len); | 410 FXSYS_memcpy32(test, (FX_LPCSTR)ukey, copy_len); |
| 410 for (int i = 19; i >= 0; i --) { | 411 for (int i = 19; i >= 0; i --) { |
| 411 for (int j = 0; j < key_len; j ++) { | 412 for (int j = 0; j < key_len; j ++) { |
| 412 tmpkey[j] = key[j] ^ i; | 413 tmpkey[j] = key[j] ^ i; |
| 413 } | 414 } |
| 414 CRYPT_ArcFourCryptBlock(test, 32, tmpkey, key_len); | 415 CRYPT_ArcFourCryptBlock(test, 32, tmpkey, key_len); |
| 415 } | 416 } |
| 416 FX_BYTE md5[100]; | 417 FX_BYTE md5[100]; |
| 417 CRYPT_MD5Start(md5); | 418 CRYPT_MD5Start(md5); |
| 418 CRYPT_MD5Update(md5, defpasscode, 32); | 419 CRYPT_MD5Update(md5, defpasscode, 32); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 if (okeylen > 32) { | 460 if (okeylen > 32) { |
| 460 okeylen = 32; | 461 okeylen = 32; |
| 461 } | 462 } |
| 462 FX_BYTE okeybuf[64]; | 463 FX_BYTE okeybuf[64]; |
| 463 FXSYS_memcpy32(okeybuf, (FX_LPCSTR)okey, okeylen); | 464 FXSYS_memcpy32(okeybuf, (FX_LPCSTR)okey, okeylen); |
| 464 if (m_Revision == 2) { | 465 if (m_Revision == 2) { |
| 465 CRYPT_ArcFourCryptBlock(okeybuf, okeylen, enckey, key_len); | 466 CRYPT_ArcFourCryptBlock(okeybuf, okeylen, enckey, key_len); |
| 466 } else { | 467 } else { |
| 467 for (int i = 19; i >= 0; i --) { | 468 for (int i = 19; i >= 0; i --) { |
| 468 FX_BYTE tempkey[32]; | 469 FX_BYTE tempkey[32]; |
| 470 FXSYS_memset32(tempkey, 0, 32); | |
|
palmer
2014/07/10 18:27:32
Use sizeof(tempkey) as above.
Bo Xu
2014/07/10 18:46:42
Done
| |
| 469 for (int j = 0; j < m_KeyLen; j ++) { | 471 for (int j = 0; j < m_KeyLen; j ++) { |
| 470 tempkey[j] = enckey[j] ^ i; | 472 tempkey[j] = enckey[j] ^ i; |
| 471 } | 473 } |
| 472 CRYPT_ArcFourCryptBlock(okeybuf, okeylen, tempkey, key_len); | 474 CRYPT_ArcFourCryptBlock(okeybuf, okeylen, tempkey, key_len); |
| 473 } | 475 } |
| 474 } | 476 } |
| 475 int len = 32; | 477 int len = 32; |
| 476 while (len && defpasscode[len - 1] == okeybuf[len - 1]) { | 478 while (len && defpasscode[len - 1] == okeybuf[len - 1]) { |
| 477 len --; | 479 len --; |
| 478 } | 480 } |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 948 m_pAESContext = NULL; | 950 m_pAESContext = NULL; |
| 949 m_Cipher = FXCIPHER_NONE; | 951 m_Cipher = FXCIPHER_NONE; |
| 950 m_KeyLen = 0; | 952 m_KeyLen = 0; |
| 951 } | 953 } |
| 952 CPDF_StandardCryptoHandler::~CPDF_StandardCryptoHandler() | 954 CPDF_StandardCryptoHandler::~CPDF_StandardCryptoHandler() |
| 953 { | 955 { |
| 954 if (m_pAESContext) { | 956 if (m_pAESContext) { |
| 955 FX_Free(m_pAESContext); | 957 FX_Free(m_pAESContext); |
| 956 } | 958 } |
| 957 } | 959 } |
| OLD | NEW |