diff options
author | Lei Zhang <thestig@chromium.org> | 2017-05-03 16:37:39 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-03 23:58:36 +0000 |
commit | 28b44b03c133055ba82dc54bbde49b9627f9c3d9 (patch) | |
tree | 3967ec11904bbcd07b696428cda6e934ce2e7df3 /core/fdrm/crypto/fx_crypt.cpp | |
parent | 0acfff302c0377c4b276859e92d08f65caaeb982 (diff) | |
download | pdfium-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.cpp | 22 |
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, |