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 45 46 47 48 49 50 51 52 53 54 55 56
|
/***********************************************************************/
/* */
/* The Cryptokit library */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 2002 Institut National de Recherche en Informatique et */
/* en Automatique. All rights reserved. This file is distributed */
/* under the terms of the GNU Library General Public License, with */
/* the special exception on linking described in file LICENSE. */
/* */
/***********************************************************************/
#include <string.h>
#include <caml/mlvalues.h>
#define ALIGNMENT_OF(x) ((uintnat)(x) & (sizeof(uintnat) - 1))
CAMLprim value caml_xor_string(value src, value src_ofs,
value dst, value dst_ofs,
value len)
{
char * s = &Byte(src, Long_val(src_ofs));
char * d = &Byte(dst, Long_val(dst_ofs));
long l = Long_val(len);
if (l >= 64 && ALIGNMENT_OF(s) == ALIGNMENT_OF(d)) {
while (ALIGNMENT_OF(s) != 0 && l > 0) {
*d ^= *s;
s += 1;
d += 1;
l -= 1;
}
while (l >= sizeof(uintnat)) {
*((uintnat *) d) ^= *((uintnat *) s);
s += sizeof(uintnat);
d += sizeof(uintnat);
l -= sizeof(uintnat);
}
}
while (l > 0) {
*d ^= *s;
s += 1;
d += 1;
l -= 1;
}
return Val_unit;
}
CAMLprim value caml_wipe_z(value v)
{
if (Is_block(v) && Tag_val(v) == Custom_tag) {
memset(Data_custom_val(v), 0, (Wosize_val(v) - 1) * sizeof(value));
}
return Val_unit;
}
|