aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/RC4_native.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf/RC4_native.cc')
-rw-r--r--libqpdf/RC4_native.cc24
1 files changed, 10 insertions, 14 deletions
diff --git a/libqpdf/RC4_native.cc b/libqpdf/RC4_native.cc
index bb0b9013..e2d36554 100644
--- a/libqpdf/RC4_native.cc
+++ b/libqpdf/RC4_native.cc
@@ -4,7 +4,8 @@
#include <string.h>
-static void swap_byte(unsigned char &a, unsigned char &b)
+static void
+swap_byte(unsigned char& a, unsigned char& b)
{
unsigned char t;
@@ -15,14 +16,12 @@ static void swap_byte(unsigned char &a, unsigned char &b)
RC4_native::RC4_native(unsigned char const* key_data, int key_len)
{
- if (key_len == -1)
- {
- key_len = QIntC::to_int(
- strlen(reinterpret_cast<char const*>(key_data)));
+ if (key_len == -1) {
+ key_len =
+ QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data)));
}
- for (int i = 0; i < 256; ++i)
- {
+ for (int i = 0; i < 256; ++i) {
key.state[i] = static_cast<unsigned char>(i);
}
key.x = 0;
@@ -30,8 +29,7 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len)
int i1 = 0;
int i2 = 0;
- for (int i = 0; i < 256; ++i)
- {
+ for (int i = 0; i < 256; ++i) {
i2 = (key_data[i1] + key.state[i] + i2) % 256;
swap_byte(key.state[i], key.state[i2]);
i1 = (i1 + 1) % key_len;
@@ -39,16 +37,14 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len)
}
void
-RC4_native::process(unsigned char *in_data, size_t len, unsigned char* out_data)
+RC4_native::process(unsigned char* in_data, size_t len, unsigned char* out_data)
{
- if (out_data == 0)
- {
+ if (out_data == 0) {
// Convert in place
out_data = in_data;
}
- for (size_t i = 0; i < len; ++i)
- {
+ for (size_t i = 0; i < len; ++i) {
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]);