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

Unified Diff: core/fpdfapi/fpdf_parser/cpdf_crypto_handler.cpp

Issue 2190123002: Fixup crypto key generation. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Out param last Created 4 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_crypto_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_parser/cpdf_crypto_handler.cpp
diff --git a/core/fpdfapi/fpdf_parser/cpdf_crypto_handler.cpp b/core/fpdfapi/fpdf_parser/cpdf_crypto_handler.cpp
index 3cd973c277b05ef964fd0fa927207a9d95cdf9be..6dfe918761e43a6bed92b15628aa5c57b9ce7640 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_crypto_handler.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_crypto_handler.cpp
@@ -28,14 +28,8 @@ void CPDF_CryptoHandler::CryptBlock(FX_BOOL bEncrypt,
int realkeylen = 16;
if (m_Cipher != FXCIPHER_AES || m_KeyLen != 32) {
uint8_t key1[32];
- FXSYS_memcpy(key1, m_EncryptKey, m_KeyLen);
- key1[m_KeyLen + 0] = (uint8_t)objnum;
- key1[m_KeyLen + 1] = (uint8_t)(objnum >> 8);
- key1[m_KeyLen + 2] = (uint8_t)(objnum >> 16);
- key1[m_KeyLen + 3] = (uint8_t)gennum;
- key1[m_KeyLen + 4] = (uint8_t)(gennum >> 8);
- FXSYS_memcpy(key1 + m_KeyLen, &objnum, 3);
- FXSYS_memcpy(key1 + m_KeyLen + 3, &gennum, 2);
+ PopulateKey(objnum, gennum, key1);
+
if (m_Cipher == FXCIPHER_AES) {
FXSYS_memcpy(key1 + m_KeyLen + 5, "sAlT", 4);
}
@@ -107,9 +101,8 @@ void* CPDF_CryptoHandler::CryptStart(uint32_t objnum,
return pContext;
}
uint8_t key1[48];
- FXSYS_memcpy(key1, m_EncryptKey, m_KeyLen);
- FXSYS_memcpy(key1 + m_KeyLen, &objnum, 3);
- FXSYS_memcpy(key1 + m_KeyLen + 3, &gennum, 2);
+ PopulateKey(objnum, gennum, key1);
+
if (m_Cipher == FXCIPHER_AES) {
FXSYS_memcpy(key1 + m_KeyLen + 5, "sAlT", 4);
}
@@ -137,6 +130,7 @@ void* CPDF_CryptoHandler::CryptStart(uint32_t objnum,
CRYPT_ArcFourSetup(pContext, realkey, realkeylen);
return pContext;
}
+
FX_BOOL CPDF_CryptoHandler::CryptStream(void* context,
const uint8_t* src_buf,
uint32_t src_size,
@@ -335,3 +329,14 @@ CPDF_CryptoHandler::CPDF_CryptoHandler() {
CPDF_CryptoHandler::~CPDF_CryptoHandler() {
FX_Free(m_pAESContext);
}
+
+void CPDF_CryptoHandler::PopulateKey(uint32_t objnum,
+ uint32_t gennum,
+ uint8_t* key) {
+ FXSYS_memcpy(key, m_EncryptKey, m_KeyLen);
+ key[m_KeyLen + 0] = (uint8_t)objnum;
+ key[m_KeyLen + 1] = (uint8_t)(objnum >> 8);
+ key[m_KeyLen + 2] = (uint8_t)(objnum >> 16);
+ key[m_KeyLen + 3] = (uint8_t)gennum;
+ key[m_KeyLen + 4] = (uint8_t)(gennum >> 8);
+}
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_crypto_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698