From eddc638bb3b8e716879edf149b2a6e37c8bc9e8d Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 1 Oct 2002 23:22:02 +0000 Subject: [PATCH 1/1] hbytes xor --- base/chiark-tcl.h | 1 + base/hook.c | 16 ++++++++++++++++ base/tables-examples.tct | 3 +++ hbytes/hbytes.h | 1 + hbytes/hook.c | 16 ++++++++++++++++ 5 files changed, 37 insertions(+) diff --git a/base/chiark-tcl.h b/base/chiark-tcl.h index ff5220b..f8f59fd 100644 --- a/base/chiark-tcl.h +++ b/base/chiark-tcl.h @@ -72,6 +72,7 @@ * HBYTES LENGTH OVERRUN block too long * HBYTES LENGTH RANGE input length or offset is -ve or silly * HBYTES LENGTH UNDERRUN block too short (or offset too big) + * HBYTES LENGTH MISMATCH when blocks must be exactly same length * HBYTES SYNTAX supposed hex block had wrong syntax * HBYTES VALUE OVERFLOW value to be conv'd to hex too big/long * SOCKADDR AFUNIX LENGTH path for AF_UNIX socket too long diff --git a/base/hook.c b/base/hook.c index 9372958..a9d0316 100644 --- a/base/hook.c +++ b/base/hook.c @@ -255,6 +255,22 @@ int do_hbytes_repeat(ClientData cd, Tcl_Interp *ip, return TCL_OK; } +int do_hbytes_xor(ClientData cd, Tcl_Interp *ip, + HBytes_Var v, HBytes_Value d) { + int l; + Byte *dest; + const Byte *source; + + l= hbytes_len(v.hb); + if (hbytes_len(&d) != l) return + staticerr(ip, "hbytes xor lengths do not match", "HBYTES LENGTH MISMATCH"); + + dest= hbytes_data(v.hb); + source= hbytes_data(&d); + memxor(dest,source,l); + return TCL_OK; +} + int do_hbytes_zeroes(ClientData cd, Tcl_Interp *ip, int length, HBytes_Value *result) { Byte *space; diff --git a/base/tables-examples.tct b/base/tables-examples.tct index 7cbf312..2e1e573 100644 --- a/base/tables-examples.tct +++ b/base/tables-examples.tct @@ -128,6 +128,9 @@ Table hbytes HBytes_SubCommand v hb count int => hb + xor + v hbv + d hb random length int => hb diff --git a/hbytes/hbytes.h b/hbytes/hbytes.h index ff5220b..f8f59fd 100644 --- a/hbytes/hbytes.h +++ b/hbytes/hbytes.h @@ -72,6 +72,7 @@ * HBYTES LENGTH OVERRUN block too long * HBYTES LENGTH RANGE input length or offset is -ve or silly * HBYTES LENGTH UNDERRUN block too short (or offset too big) + * HBYTES LENGTH MISMATCH when blocks must be exactly same length * HBYTES SYNTAX supposed hex block had wrong syntax * HBYTES VALUE OVERFLOW value to be conv'd to hex too big/long * SOCKADDR AFUNIX LENGTH path for AF_UNIX socket too long diff --git a/hbytes/hook.c b/hbytes/hook.c index 9372958..a9d0316 100644 --- a/hbytes/hook.c +++ b/hbytes/hook.c @@ -255,6 +255,22 @@ int do_hbytes_repeat(ClientData cd, Tcl_Interp *ip, return TCL_OK; } +int do_hbytes_xor(ClientData cd, Tcl_Interp *ip, + HBytes_Var v, HBytes_Value d) { + int l; + Byte *dest; + const Byte *source; + + l= hbytes_len(v.hb); + if (hbytes_len(&d) != l) return + staticerr(ip, "hbytes xor lengths do not match", "HBYTES LENGTH MISMATCH"); + + dest= hbytes_data(v.hb); + source= hbytes_data(&d); + memxor(dest,source,l); + return TCL_OK; +} + int do_hbytes_zeroes(ClientData cd, Tcl_Interp *ip, int length, HBytes_Value *result) { Byte *space; -- 2.30.2