From 36c4e419e899f650d32712594fc947f9f7960992 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 23 Nov 2008 18:13:40 +0000 Subject: Move xor_into_buf to xor_buf.cpp. Also add a new template wrapper for xoring integer values in. --- src/utils/info.txt | 1 + src/utils/xor_buf.cpp | 27 +++++++++++++++++++++++++++ src/utils/xor_buf.h | 21 +++++++++++---------- 3 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 src/utils/xor_buf.cpp (limited to 'src') diff --git a/src/utils/info.txt b/src/utils/info.txt index ffc19c852..915ce50b0 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -42,5 +42,6 @@ util.cpp util.h version.cpp version.h +xor_buf.cpp xor_buf.h diff --git a/src/utils/xor_buf.cpp b/src/utils/xor_buf.cpp new file mode 100644 index 000000000..df4e62db9 --- /dev/null +++ b/src/utils/xor_buf.cpp @@ -0,0 +1,27 @@ +/** +* XOR operations +* (C) 1999-2008 Jack Lloyd +*/ + +#include +#include + +namespace Botan { + +/** +* Xor values into buffer +*/ +u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length, + const void* in_void, u32bit in_len) + { + const byte* in = static_cast(in_void); + + for(u32bit i = 0; i != in_len; ++i) + { + buf[buf_i] ^= in[i]; + buf_i = (buf_i + 1) % length; + } + return buf_i; + } + +} diff --git a/src/utils/xor_buf.h b/src/utils/xor_buf.h index 975ad0af6..bbc6d3eec 100644 --- a/src/utils/xor_buf.h +++ b/src/utils/xor_buf.h @@ -68,18 +68,19 @@ inline void xor_buf(byte out[], } /** -* Xor values into buffer +* XOR values into buffer. Might do RLE on input */ -inline u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length, - const void* in_void, u32bit in_len) +u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length, + const void* in_void, u32bit in_len); + +/** +* XOR integer value (or something else, I guess) into buffer +*/ +template +u32bit xor_into_buf(byte buf[], u32bit buf_i, + u32bit length, T in) { - const byte* in = static_cast(in_void); - for(u32bit i = 0; i != in_len; ++i) - { - buf[buf_i] ^= in[i]; - buf_i = (buf_i + 1) % length; - } - return buf_i; + return xor_into_buf(buf, buf_i, length, &in, sizeof(in)); } } -- cgit v1.2.3