diff options
Diffstat (limited to 'libqpdf/RC4.cc')
-rw-r--r-- | libqpdf/RC4.cc | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libqpdf/RC4.cc b/libqpdf/RC4.cc index 7639a364..8ab242a0 100644 --- a/libqpdf/RC4.cc +++ b/libqpdf/RC4.cc @@ -1,4 +1,5 @@ #include <qpdf/RC4.hh> +#include <qpdf/QIntC.hh> #include <string.h> @@ -15,12 +16,13 @@ RC4::RC4(unsigned char const* key_data, int key_len) { if (key_len == -1) { - key_len = strlen(reinterpret_cast<char const*>(key_data)); + key_len = QIntC::to_int( + strlen(reinterpret_cast<char const*>(key_data))); } for (int i = 0; i < 256; ++i) { - key.state[i] = i; + key.state[i] = static_cast<unsigned char>(i); } key.x = 0; key.y = 0; @@ -36,7 +38,7 @@ RC4::RC4(unsigned char const* key_data, int key_len) } void -RC4::process(unsigned char *in_data, int len, unsigned char* out_data) +RC4::process(unsigned char *in_data, size_t len, unsigned char* out_data) { if (out_data == 0) { @@ -44,10 +46,10 @@ RC4::process(unsigned char *in_data, int len, unsigned char* out_data) out_data = in_data; } - for (int i = 0; i < len; ++i) + for (size_t i = 0; i < len; ++i) { - key.x = (key.x + 1) % 256; - key.y = (key.state[key.x] + key.y) % 256; + key.x = static_cast<unsigned char>((key.x + 1) % 256); + key.y = static_cast<unsigned char>((key.state[key.x] + key.y) % 256); swap_byte(key.state[key.x], key.state[key.y]); int xor_index = (key.state[key.x] + key.state[key.y]) % 256; out_data[i] = in_data[i] ^ key.state[xor_index]; |