blob: 779be81c32478ebcc732f722a376c912cfdff229 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/**
* XOR operations
* (C) 1999-2008 Jack Lloyd
*/
#include <botan/xor_buf.h>
#include <botan/loadstor.h>
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<const byte*>(in_void);
byte last = 0;
byte count = 0;
for(u32bit i = 0; i != in_len; ++i)
{
if(in[i] != last)
{
buf[buf_i] ^= last;
buf_i = (buf_i + 1) % length;
buf[buf_i] ^= count;
buf_i = (buf_i + 1) % length;
last = in[i];
count = 1;
}
else
++count;
}
// final values of last, count are thrown away
return buf_i;
}
}
|