chiark / gitweb /
hbytes xor
authorian <ian>
Tue, 1 Oct 2002 23:22:02 +0000 (23:22 +0000)
committerian <ian>
Tue, 1 Oct 2002 23:22:02 +0000 (23:22 +0000)
base/chiark-tcl.h
base/hook.c
base/tables-examples.tct
hbytes/hbytes.h
hbytes/hook.c

index ff5220b886912f98ba0789969a1ee8f854cf1de4..f8f59fdd6ed89ab4dea8454f72e73d31a8f10c98 100644 (file)
@@ -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
index 937295842b8045c3b765e45084f7a32c2d0ac058..a9d0316f0c90089cce1f1383caa5030b30dfc8f0 100644 (file)
@@ -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;
index 7cbf3128cc79415e3273558534b0eb59f47bf7ff..2e1e573d62ec546b69081dad820feed1c25c8279 100644 (file)
@@ -128,6 +128,9 @@ Table hbytes HBytes_SubCommand
                v       hb
                count   int
                =>      hb
+       xor
+               v       hbv
+               d       hb
        random
                length  int
                =>      hb
index ff5220b886912f98ba0789969a1ee8f854cf1de4..f8f59fdd6ed89ab4dea8454f72e73d31a8f10c98 100644 (file)
@@ -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
index 937295842b8045c3b765e45084f7a32c2d0ac058..a9d0316f0c90089cce1f1383caa5030b30dfc8f0 100644 (file)
@@ -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;