summaryrefslogtreecommitdiff
path: root/core/fdrm/crypto/fx_crypt.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-05-03 16:37:39 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-03 23:58:36 +0000
commit28b44b03c133055ba82dc54bbde49b9627f9c3d9 (patch)
tree3967ec11904bbcd07b696428cda6e934ce2e7df3 /core/fdrm/crypto/fx_crypt.cpp
parent0acfff302c0377c4b276859e92d08f65caaeb982 (diff)
downloadpdfium-28b44b03c133055ba82dc54bbde49b9627f9c3d9.tar.xz
Clean up CRYPT_ArcFourCrypt().
Add a unit test too. Change-Id: I33bf1aea85aff3de50021462095b76edd4017f97 Reviewed-on: https://pdfium-review.googlesource.com/4870 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fdrm/crypto/fx_crypt.cpp')
-rw-r--r--core/fdrm/crypto/fx_crypt.cpp22
1 files changed, 6 insertions, 16 deletions
diff --git a/core/fdrm/crypto/fx_crypt.cpp b/core/fdrm/crypto/fx_crypt.cpp
index f5ebdf09d2..d53fa6ba7a 100644
--- a/core/fdrm/crypto/fx_crypt.cpp
+++ b/core/fdrm/crypto/fx_crypt.cpp
@@ -153,23 +153,13 @@ void CRYPT_ArcFourSetup(CRYPT_rc4_context* s,
}
}
-void CRYPT_ArcFourCrypt(CRYPT_rc4_context* s,
- unsigned char* data,
- uint32_t length) {
- int i, x, y, *m, a, b;
- x = s->x;
- y = s->y;
- m = s->m;
- for (i = 0; i < (int)length; i++) {
- x = (x + 1) & 0xFF;
- a = m[x];
- y = (y + a) & 0xFF;
- m[x] = b = m[y];
- m[y] = a;
- data[i] ^= m[(a + b) & 0xFF];
+void CRYPT_ArcFourCrypt(CRYPT_rc4_context* s, uint8_t* data, uint32_t length) {
+ for (uint32_t i = 0; i < length; ++i) {
+ s->x = (s->x + 1) & 0xFF;
+ s->y = (s->y + s->m[s->x]) & 0xFF;
+ std::swap(s->m[s->x], s->m[s->y]);
+ data[i] ^= s->m[(s->m[s->x] + s->m[s->y]) & 0xFF];
}
- s->x = x;
- s->y = y;
}
void CRYPT_ArcFourCryptBlock(uint8_t* pData,