From: Nick Mathewson Date: Sat, 30 Oct 2004 19:26:31 +0000 (+0000) Subject: Move all util functions that need openssl into crypto.c; make non-openssl functions... X-Git-Tag: debian-version-0.0.8+0.0.9pre5-1~153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bc0dba9338c6722f6833351b1401571533eb63d;p=thirdparty%2Ftor.git 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 --- diff --git a/src/common/crypto.c b/src/common/crypto.c index 4fe2ae0e85..e63a92c99b 100644 --- a/src/common/crypto.c +++ b/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