From e1cb54b8bd682308acde332a0e0936df3aa564bf Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 30 Oct 2004 19:26:31 +0000 Subject: [PATCH] Move all util functions that need openssl into crypto.c; make non-openssl functions that util needs into util. Now openssl can be separated. svn:r2628 --- trunk/src/common/crypto.c | 63 +++++++-------------------------------- trunk/src/common/util.c | 62 +++++++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 61 deletions(-) diff --git a/trunk/src/common/crypto.c b/trunk/src/common/crypto.c index 4fe2ae0e85..e63a92c99b 100644 --- a/trunk/src/common/crypto.c +++ b/trunk/src/common/crypto.c @@ -1470,6 +1470,16 @@ int crypto_pseudo_rand_int(unsigned int max) { } } +/** 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 srclen bytes of data from src. Write * the result into dest, if it will fit within destlen * bytes. Return the number of bytes written on success; -1 if @@ -1540,59 +1550,6 @@ base32_encode(char *dest, size_t destlen, const char *src, size_t srclen) 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 (srclist[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 idxth element of sl. */ void *smartlist_get(const smartlist_t *sl, int idx) @@ -2402,6 +2394,60 @@ void tor_mutex_release(tor_mutex_t *m) #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