summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/crypto_curve25519.c31
-rw-r--r--src/common/crypto_curve25519.h12
-rw-r--r--src/common/crypto_format.c46
-rw-r--r--src/common/include.am1
-rw-r--r--src/or/circuitbuild.c21
-rw-r--r--src/or/onion.c2
6 files changed, 66 insertions, 47 deletions
diff --git a/src/common/crypto_curve25519.c b/src/common/crypto_curve25519.c
index 62398f62e6..425a1a078c 100644
--- a/src/common/crypto_curve25519.c
+++ b/src/common/crypto_curve25519.c
@@ -182,34 +182,3 @@ curve25519_handshake(uint8_t *output,
curve25519_impl(output, skey->secret_key, pkey->public_key);
}
-int
-curve25519_public_to_base64(char *output,
- const curve25519_public_key_t *pkey)
-{
- char buf[128];
- base64_encode(buf, sizeof(buf),
- (const char*)pkey->public_key, CURVE25519_PUBKEY_LEN);
- buf[CURVE25519_BASE64_PADDED_LEN] = '\0';
- memcpy(output, buf, CURVE25519_BASE64_PADDED_LEN+1);
- return 0;
-}
-
-int
-curve25519_public_from_base64(curve25519_public_key_t *pkey,
- const char *input)
-{
- size_t len = strlen(input);
- if (len == CURVE25519_BASE64_PADDED_LEN - 1) {
- /* not padded */
- return digest256_from_base64((char*)pkey->public_key, input);
- } else if (len == CURVE25519_BASE64_PADDED_LEN) {
- char buf[128];
- if (base64_decode(buf, sizeof(buf), input, len) != CURVE25519_PUBKEY_LEN)
- return -1;
- memcpy(pkey->public_key, buf, CURVE25519_PUBKEY_LEN);
- return 0;
- } else {
- return -1;
- }
-}
-
diff --git a/src/common/crypto_curve25519.h b/src/common/crypto_curve25519.h
index 5524415492..652f1883c6 100644
--- a/src/common/crypto_curve25519.h
+++ b/src/common/crypto_curve25519.h
@@ -51,6 +51,12 @@ int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out,
char **tag_out,
const char *fname);
+#ifdef CRYPTO_CURVE25519_PRIVATE
+int curve25519_impl(uint8_t *output, const uint8_t *secret,
+ const uint8_t *basepoint);
+#endif
+#endif
+
#define CURVE25519_BASE64_PADDED_LEN 44
int curve25519_public_from_base64(curve25519_public_key_t *pkey,
@@ -58,11 +64,5 @@ int curve25519_public_from_base64(curve25519_public_key_t *pkey,
int curve25519_public_to_base64(char *output,
const curve25519_public_key_t *pkey);
-#ifdef CRYPTO_CURVE25519_PRIVATE
-int curve25519_impl(uint8_t *output, const uint8_t *secret,
- const uint8_t *basepoint);
-#endif
-#endif
-
#endif
diff --git a/src/common/crypto_format.c b/src/common/crypto_format.c
new file mode 100644
index 0000000000..93932f839c
--- /dev/null
+++ b/src/common/crypto_format.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2012-2013, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/* Formatting and parsing code for crypto-related data structures. */
+
+#define CRYPTO_CURVE25519_PRIVATE
+#include "orconfig.h"
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#include "crypto.h"
+#include "crypto_curve25519.h"
+#include "util.h"
+#include "torlog.h"
+
+int
+curve25519_public_to_base64(char *output,
+ const curve25519_public_key_t *pkey)
+{
+ char buf[128];
+ base64_encode(buf, sizeof(buf),
+ (const char*)pkey->public_key, CURVE25519_PUBKEY_LEN);
+ buf[CURVE25519_BASE64_PADDED_LEN] = '\0';
+ memcpy(output, buf, CURVE25519_BASE64_PADDED_LEN+1);
+ return 0;
+}
+
+int
+curve25519_public_from_base64(curve25519_public_key_t *pkey,
+ const char *input)
+{
+ size_t len = strlen(input);
+ if (len == CURVE25519_BASE64_PADDED_LEN - 1) {
+ /* not padded */
+ return digest256_from_base64((char*)pkey->public_key, input);
+ } else if (len == CURVE25519_BASE64_PADDED_LEN) {
+ char buf[128];
+ if (base64_decode(buf, sizeof(buf), input, len) != CURVE25519_PUBKEY_LEN)
+ return -1;
+ memcpy(pkey->public_key, buf, CURVE25519_PUBKEY_LEN);
+ return 0;
+ } else {
+ return -1;
+ }
+}
+
diff --git a/src/common/include.am b/src/common/include.am
index 808238dd1f..b796ebfae8 100644
--- a/src/common/include.am
+++ b/src/common/include.am
@@ -52,6 +52,7 @@ src_common_libor_a_SOURCES = \
src_common_libor_crypto_a_SOURCES = \
src/common/aes.c \
src/common/crypto.c \
+ src/common/crypto_format.c \
src/common/torgzip.c \
src/common/tortls.c \
$(libcrypto_extra_source)
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 5a5a3afea7..05f9d76e7c 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2164,11 +2164,11 @@ pathbias_count_circs_in_states(entry_guard_t *guard,
path_state_t from,
path_state_t to)
{
- circuit_t *circ = global_circuitlist;
+ circuit_t *circ;
int open_circuits = 0;
- /* Count currently open circuits. Give them the benefit of the doubt */
- for ( ; circ; circ = circ->next) {
+ /* Count currently open circuits. Give them the benefit of the doubt. */
+ for (circ = global_circuitlist; circ; circ = circ->next) {
origin_circuit_t *ocirc = NULL;
if (!CIRCUIT_IS_ORIGIN(circ) || /* didn't originate here */
circ->marked_for_close) /* already counted */
@@ -2183,8 +2183,8 @@ pathbias_count_circs_in_states(entry_guard_t *guard,
ocirc->path_state <= to &&
pathbias_should_count(ocirc) &&
fast_memeq(guard->identity,
- ocirc->cpath->extend_info->identity_digest,
- DIGEST_LEN)) {
+ ocirc->cpath->extend_info->identity_digest,
+ DIGEST_LEN)) {
log_debug(LD_CIRC, "Found opened circuit %d in path_state %s",
ocirc->global_identifier,
pathbias_state_to_string(ocirc->path_state));
@@ -2252,7 +2252,7 @@ pathbias_measure_use_rate(entry_guard_t *guard)
log_warn(LD_CIRC,
"Your Guard %s=%s is failing to carry an extremely large "
"amount of stream on its circuits. "
- "To avoid potential route manipluation attacks, Tor has "
+ "To avoid potential route manipulation attacks, Tor has "
"disabled use of this guard. "
"Use counts are %ld/%ld. Success counts are %ld/%ld. "
"%ld circuits completed, %ld were unusable, %ld collapsed, "
@@ -2355,7 +2355,7 @@ pathbias_measure_close_rate(entry_guard_t *guard)
log_warn(LD_CIRC,
"Your Guard %s=%s is failing an extremely large "
"amount of circuits. "
- "To avoid potential route manipluation attacks, Tor has "
+ "To avoid potential route manipulation attacks, Tor has "
"disabled use of this guard. "
"Success counts are %ld/%ld. Use counts are %ld/%ld. "
"%ld circuits completed, %ld were unusable, %ld collapsed, "
@@ -2531,9 +2531,10 @@ pathbias_scale_use_rates(entry_guard_t *guard)
}
/** Increment the number of times we successfully extended a circuit to
- * 'guard', first checking if the failure rate is high enough that we should
- * eliminate the guard. Return -1 if the guard looks no good; return 0 if the
- * guard looks fine. */
+ * <b>guard</b>, first checking if the failure rate is high enough that
+ * we should eliminate the guard. Return -1 if the guard looks no good;
+ * return 0 if the guard looks fine.
+ */
static int
entry_guard_inc_circ_attempt_count(entry_guard_t *guard)
{
diff --git a/src/or/onion.c b/src/or/onion.c
index b9f5aa6c7d..d4a65022fc 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -82,6 +82,8 @@ have_room_for_onionskin(uint16_t type)
if (type == ONION_HANDSHAKE_TYPE_TAP &&
tap_usec / 1000 > (uint64_t)options->MaxOnionQueueDelay * 2 / 3)
return 0;
+#else
+ (void) type;
#endif
return 1;