diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/crypto.c | 16 | ||||
-rw-r--r-- | src/common/crypto.h | 4 | ||||
-rw-r--r-- | src/common/util.c | 1 | ||||
-rw-r--r-- | src/or/rendcommon.c | 3 | ||||
-rw-r--r-- | src/or/rendmid.c | 9 | ||||
-rw-r--r-- | src/or/rendservice.c | 29 | ||||
-rw-r--r-- | src/or/test.c | 8 |
7 files changed, 23 insertions, 47 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 3dfe891932..7f0bd899e3 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1406,20 +1406,16 @@ base64_decode(char *dest, int destlen, const char *src, int srclen) } /** Implements base32 encoding as in rfc3548. Limitation: Requires - * that srclen is a multiple of 5. + * that srclen*8 is a multiple of 5. */ -int +void base32_encode(char *dest, int destlen, const char *src, int srclen) { int nbits, i, bit, v, u; nbits = srclen * 8; - if ((nbits%5) != 0) - /* We need an even multiple of 5 bits. */ - return -1; - if ((nbits/5)+1 > destlen) - /* Not enough space. */ - return -1; + tor_assert((nbits%5) == 0); /* We need an even multiple of 5 bits. */ + tor_assert((nbits/5)+1 <= destlen); /* We need enough space. */ for (i=0,bit=0; bit < nbits; ++i, bit+=5) { /* set v to the 16-bit value starting at src[bits/8], 0-padded. */ @@ -1430,10 +1426,9 @@ base32_encode(char *dest, int destlen, const char *src, int srclen) dest[i] = BASE32_CHARS[u]; } dest[i] = '\0'; - return 0; } -int base16_encode(char *dest, int destlen, const char *src, int srclen) +void base16_encode(char *dest, int destlen, const char *src, int srclen) { const char *end; char *cp; @@ -1448,7 +1443,6 @@ int base16_encode(char *dest, int destlen, const char *src, int srclen) cp += 2; } *cp = '\0'; - return 0; } static const char HEX_DIGITS[] = "0123456789ABCDEFabcdef"; diff --git a/src/common/crypto.h b/src/common/crypto.h index 09bb50f05a..70ad1bc37e 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -92,8 +92,8 @@ int crypto_pk_check_fingerprint_syntax(const char *s); int base64_encode(char *dest, int destlen, const char *src, int srclen); int base64_decode(char *dest, int destlen, const char *src, int srclen); #define BASE32_CHARS "abcdefghijklmnopqrstuvwxyz234567" -int base32_encode(char *dest, int destlen, const char *src, int srclen); -int base16_encode(char *dest, int destlen, const char *src, int srclen); +void base32_encode(char *dest, int destlen, const char *src, int srclen); +void base16_encode(char *dest, int destlen, const char *src, int srclen); int base16_decode(char *dest, int destlen, const char *src, int srclen); /* Key negotiation */ diff --git a/src/common/util.c b/src/common/util.c index 21cb010b32..be4f60028a 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1254,6 +1254,7 @@ int check_private_dir(const char *dirname, int create) { int r; struct stat st; + tor_assert(dirname); if (stat(dirname, &st)) { if (errno != ENOENT) { log(LOG_WARN, "Directory %s cannot be read: %s", dirname, diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c index 38e8d7b013..91caa18e39 100644 --- a/src/or/rendcommon.c +++ b/src/or/rendcommon.c @@ -146,8 +146,7 @@ int rend_get_service_id(crypto_pk_env_t *pk, char *out) tor_assert(pk); if (crypto_pk_get_digest(pk, buf) < 0) return -1; - if (base32_encode(out, REND_SERVICE_ID_LEN+1, buf, 10) < 0) - return -1; + base32_encode(out, REND_SERVICE_ID_LEN+1, buf, 10); return 0; } diff --git a/src/or/rendmid.c b/src/or/rendmid.c index e495870763..6c2b372956 100644 --- a/src/or/rendmid.c +++ b/src/or/rendmid.c @@ -69,10 +69,7 @@ rend_mid_establish_intro(circuit_t *circ, const char *request, int request_len) goto err; } - if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, - pk_digest,10)) { - goto err; - } + base32_encode(serviceid, REND_SERVICE_ID_LEN+1, pk_digest,10); /* Close any other intro circuits with the same pk. */ c = NULL; @@ -133,9 +130,7 @@ rend_mid_introduce(circuit_t *circ, const char *request, int request_len) goto err; } - if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, request,10)) { - goto err; - } + base32_encode(serviceid, REND_SERVICE_ID_LEN+1, request,10); /* The first 20 bytes are all we look at: they have a hash of Bob's PK. */ intro_circ = circuit_get_next_by_pk_and_purpose( diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 4e3323e903..76a725a9f9 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -353,10 +353,8 @@ rend_service_introduce(circuit_t *circuit, const char *request, int request_len) char serviceid[REND_SERVICE_ID_LEN+1]; char hexcookie[9]; - if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, - circuit->rend_pk_digest,10)) { - return -1; - } + base32_encode(serviceid, REND_SERVICE_ID_LEN+1, + circuit->rend_pk_digest,10); log_fn(LOG_INFO, "Received INTRODUCE2 cell for service %s on circ %d", serviceid, circuit->n_circ_id); @@ -382,9 +380,7 @@ rend_service_introduce(circuit_t *circuit, const char *request, int request_len) return -1; } if (memcmp(circuit->rend_pk_digest, request, DIGEST_LEN)) { - if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, request, 10)) { - return -1; - } + base32_encode(serviceid, REND_SERVICE_ID_LEN+1, request, 10); log_fn(LOG_WARN, "Got an INTRODUCE2 cell for the wrong service (%s)", serviceid); return -1; @@ -552,10 +548,8 @@ rend_service_intro_has_opened(circuit_t *circuit) tor_assert(circuit->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO); tor_assert(CIRCUIT_IS_ORIGIN(circuit) && circuit->cpath); - if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, - circuit->rend_pk_digest,10)) { - tor_assert(0); - } + base32_encode(serviceid, REND_SERVICE_ID_LEN+1, + circuit->rend_pk_digest,10); service = rend_service_get_by_pk_digest(circuit->rend_pk_digest); if (!service) { @@ -644,10 +638,8 @@ rend_service_rendezvous_has_opened(circuit_t *circuit) tor_assert(hop); hex_encode(circuit->rend_cookie, 4, hexcookie); - if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, - circuit->rend_pk_digest,10)) { - tor_assert(0); - } + base32_encode(serviceid, REND_SERVICE_ID_LEN+1, + circuit->rend_pk_digest,10); log_fn(LOG_INFO, "Done building circuit %d to rendezvous with cookie %s for service %s", @@ -933,11 +925,8 @@ rend_service_set_connection_addr_port(connection_t *conn, circuit_t *circ) tor_assert(circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED); log_fn(LOG_DEBUG,"beginning to hunt for addr/port"); - if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, - circ->rend_pk_digest,10)) { - log_fn(LOG_WARN,"bug: base32 failed"); - return -1; - } + base32_encode(serviceid, REND_SERVICE_ID_LEN+1, + circ->rend_pk_digest,10); service = rend_service_get_by_pk_digest(circ->rend_pk_digest); if (!service) { log_fn(LOG_WARN, "Couldn't find any service associated with pk %s on rendezvous circuit %d; closing", diff --git a/src/or/test.c b/src/or/test.c index 95556c4452..48e7113c07 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -412,18 +412,16 @@ test_crypto() * [00110101 01100011 01101000 01110010 01110011] * By 5s: [00110 10101 10001 10110 10000 11100 10011 10011] */ - i = base32_encode(data2, 9, data1, 5); + base32_encode(data2, 9, data1, 5); test_streq(data2, "gvrwq4tt"); strcpy(data1, "\xFF\xF5\x6D\x44\xAE\x0D\x5C\xC9\x62\xC4"); - i = base32_encode(data2, 30, data1, 10); - test_eq(i,0); + base32_encode(data2, 30, data1, 10); test_streq(data2, "772w2rfobvomsywe"); /* Base16 tests */ strcpy(data1, "6chrs\xff"); - i = base16_encode(data2, 13, data1, 6); - test_eq(i,0); + base16_encode(data2, 13, data1, 6); test_streq(data2, "3663687273FF"); strcpy(data1, "f0d678affc000100"); |