[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Move all util functions that need openssl into crypto.c; ma...



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv5560/src/common

Modified Files:
	util.c crypto.c 
Log Message:
Move all util functions that need openssl into crypto.c; make non-openssl functions that util needs into util.  Now openssl can be separated.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -d -r1.158 -r1.159
--- util.c	27 Oct 2004 18:14:38 -0000	1.158
+++ util.c	30 Oct 2004 19:26:31 -0000	1.159
@@ -476,14 +476,6 @@
     smartlist_remove(sl1, sl2->list[i]);
 }
 
-/** Return a randomly chosen element of sl; or NULL if sl is empty.
- */
-void *smartlist_choose(const smartlist_t *sl) {
-  if(sl->num_used)
-    return sl->list[crypto_pseudo_rand_int(sl->num_used)];
-  return NULL; /* no elements to choose from */
-}
-
 /** Return the <b>idx</b>th element of sl.
  */
 void *smartlist_get(const smartlist_t *sl, int idx)
@@ -2402,6 +2394,60 @@
 
 #endif
 
+void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
+{
+  const char *end;
+  char *cp;
+
+  tor_assert(destlen >= srclen*2+1);
+
+  cp = dest;
+  end = src+srclen;
+  while (src<end) {
+    sprintf(cp,"%02X",*(const uint8_t*)src);
+    ++src;
+    cp += 2;
+  }
+  *cp = '\0';
+}
+
+static const char HEX_DIGITS[] = "0123456789ABCDEFabcdef";
+
+static INLINE int hex_decode_digit(char c)
+{
+  const char *cp;
+  int n;
+  cp = strchr(HEX_DIGITS, c);
+  if (!cp)
+    return -1;
+  n = cp-HEX_DIGITS;
+  if (n<=15)
+    return n; /* digit or uppercase */
+  else
+    return n-6; /* lowercase */
+}
+
+int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
+{
+  const char *end;
+  int v1,v2;
+  if ((srclen % 2) != 0)
+    return -1;
+  if (destlen < srclen/2)
+    return -1;
+  end = src+srclen;
+  while (src<end) {
+    v1 = hex_decode_digit(*src);
+    v2 = hex_decode_digit(*(src+1));
+    if(v1<0||v2<0)
+      return -1;
+    *(uint8_t*)dest = (v1<<4)|v2;
+    ++dest;
+    src+=2;
+  }
+  return 0;
+}
+
 /*
   Local Variables:
   mode:c

Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- crypto.c	27 Oct 2004 21:14:10 -0000	1.116
+++ crypto.c	30 Oct 2004 19:26:31 -0000	1.117
@@ -1470,6 +1470,16 @@
   }
 }
 
+/** Return a randomly chosen element of sl; or NULL if sl is empty.
+ */
+void *smartlist_choose(const smartlist_t *sl) {
+  size_t len;
+  len = smartlist_len(sl);
+  if(len)
+    return smartlist_get(sl,crypto_pseudo_rand_int(len));
+  return NULL; /* no elements to choose from */
+}
+
 /** Base-64 encode <b>srclen</b> bytes of data from <b>src</b>.  Write
  * the result into <b>dest</b>, if it will fit within <b>destlen</b>
  * bytes.  Return the number of bytes written on success; -1 if
@@ -1540,59 +1550,6 @@
   dest[i] = '\0';
 }
 
-void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
-{
-  const char *end;
-  char *cp;
-
-  tor_assert(destlen >= srclen*2+1);
-
-  cp = dest;
-  end = src+srclen;
-  while (src<end) {
-    sprintf(cp,"%02X",*(const uint8_t*)src);
-    ++src;
-    cp += 2;
-  }
-  *cp = '\0';
-}
-
-static const char HEX_DIGITS[] = "0123456789ABCDEFabcdef";
-
-static INLINE int hex_decode_digit(char c)
-{
-  const char *cp;
-  int n;
-  cp = strchr(HEX_DIGITS, c);
-  if (!cp)
-    return -1;
-  n = cp-HEX_DIGITS;
-  if (n<=15)
-    return n; /* digit or uppercase */
-  else
-    return n-6; /* lowercase */
-}
-
-int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
-{
-  const char *end;
-  int v1,v2;
-  if ((srclen % 2) != 0)
-    return -1;
-  if (destlen < srclen/2)
-    return -1;
-  end = src+srclen;
-  while (src<end) {
-    v1 = hex_decode_digit(*src);
-    v2 = hex_decode_digit(*(src+1));
-    if(v1<0||v2<0)
-      return -1;
-    *(uint8_t*)dest = (v1<<4)|v2;
-    ++dest;
-    src+=2;
-  }
-  return 0;
-}
 
 /*
   Local Variables: