mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-08 08:58:00 +00:00
Add utility function 'memxor'.
This commit is contained in:
parent
09fa3f0e80
commit
609502b04b
9
misc.h
9
misc.h
@ -430,4 +430,13 @@ LoadFileStatus lf_load(LoadedFile *lf, const Filename *filename);
|
||||
static inline ptrlen ptrlen_from_lf(LoadedFile *lf)
|
||||
{ return make_ptrlen(lf->data, lf->len); }
|
||||
|
||||
/* Set the memory block of 'size' bytes at 'out' to the bitwise XOR of
|
||||
* the two blocks of the same size at 'in1' and 'in2'.
|
||||
*
|
||||
* 'out' may point to exactly the same address as one of the inputs,
|
||||
* but if the input and output blocks overlap in any other way, the
|
||||
* result of this function is not guaranteed. No memmove-style effort
|
||||
* is made to handle difficult overlap cases. */
|
||||
void memxor(uint8_t *out, const uint8_t *in1, const uint8_t *in2, size_t size);
|
||||
|
||||
#endif
|
||||
|
26
utils.c
26
utils.c
@ -1073,3 +1073,29 @@ void write_c_string_literal(FILE *fp, ptrlen str)
|
||||
fprintf(fp, "\\%03o", (unsigned char)c);
|
||||
}
|
||||
}
|
||||
|
||||
void memxor(uint8_t *out, const uint8_t *in1, const uint8_t *in2, size_t size)
|
||||
{
|
||||
switch (size & 15) {
|
||||
case 0:
|
||||
while (size >= 16) {
|
||||
*out++ = *in1++ ^ *in2++;
|
||||
case 15: *out++ = *in1++ ^ *in2++;
|
||||
case 14: *out++ = *in1++ ^ *in2++;
|
||||
case 13: *out++ = *in1++ ^ *in2++;
|
||||
case 12: *out++ = *in1++ ^ *in2++;
|
||||
case 11: *out++ = *in1++ ^ *in2++;
|
||||
case 10: *out++ = *in1++ ^ *in2++;
|
||||
case 9: *out++ = *in1++ ^ *in2++;
|
||||
case 8: *out++ = *in1++ ^ *in2++;
|
||||
case 7: *out++ = *in1++ ^ *in2++;
|
||||
case 6: *out++ = *in1++ ^ *in2++;
|
||||
case 5: *out++ = *in1++ ^ *in2++;
|
||||
case 4: *out++ = *in1++ ^ *in2++;
|
||||
case 3: *out++ = *in1++ ^ *in2++;
|
||||
case 2: *out++ = *in1++ ^ *in2++;
|
||||
case 1: *out++ = *in1++ ^ *in2++;
|
||||
size -= 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user