]> www.vanbest.org Git - sasc-ng.git/commitdiff
made RotateBytes robust against bad input
authorleslie <unknown>
Thu, 3 Jan 2008 16:08:06 +0000 (17:08 +0100)
committerleslie <unknown>
Thu, 3 Jan 2008 16:08:06 +0000 (17:08 +0100)
crypto.c

index c1e64cc267233807862969b1eaa117a794e0def4..a6c5bb4028a162dc9d26436b7e10dc180461604c 100644 (file)
--- a/crypto.c
+++ b/crypto.c
 
 void RotateBytes(unsigned char *out, const unsigned char *in, int n)
 {
-  // loop is executed atleast once, so it's not a good idea to
-  // call with n=0 !!
-  out+=n;
-  do { *(--out)=*(in++); } while(--n);
+  if(n>0) {
+    out+=n;
+    do { *(--out)=*(in++); } while(--n);
+    }
 }
 
 void RotateBytes(unsigned char *in, int n)
 {
-  // loop is executed atleast once, so it's not a good idea to
-  // call with n=0 !!
-  unsigned char *e=in+n-1;
-  do {
-    unsigned char temp=*in;
-    *in++=*e;
-    *e-- =temp;
-    } while(in<e);
+  if(n>1) {
+    unsigned char *e=in+n-1;
+    do {
+      unsigned char temp=*in;
+      *in++=*e;
+      *e-- =temp;
+      } while(in<e);
+    }
 }
 
 // -- cBN ----------------------------------------------------------------------