]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix compilation with --disable-curve25519 option
authorNick Mathewson <nickm@torproject.org>
Mon, 4 Feb 2013 16:32:55 +0000 (11:32 -0500)
committerNick Mathewson <nickm@torproject.org>
Mon, 4 Feb 2013 16:32:55 +0000 (11:32 -0500)
The fix is to move the two functions to format/parse base64
curve25519 public keys into a new "crypto_format.c" file.  I could
have put them in crypto.c, but that's a big file worth splitting
anyway.

Fixes bug 8153; bugfix on 0.2.4.8-alpha where I did the fix for 7869.

changes/bug8153 [new file with mode: 0644]
src/common/crypto_curve25519.c
src/common/crypto_curve25519.h
src/common/crypto_format.c [new file with mode: 0644]
src/common/include.am

diff --git a/changes/bug8153 b/changes/bug8153
new file mode 100644 (file)
index 0000000..9178f25
--- /dev/null
@@ -0,0 +1,3 @@
+  o Minor bugfixes:
+    - Compile correctly with the --disable-curve25519 option. Fix for
+      bug 8153; bugfix on 0.2.4.8-alpha.
index 62398f62e60cda81fe9d9ac04b2283bcc66e6562..425a1a078c1f1c43a84408a3b887dab27e8abab3 100644 (file)
@@ -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;
-  }
-}
-
index 5524415492892e84fc6a11925f2f3fd9ade3a2f3..652f1883c6b89e66f10370adb454bbd790030afc 100644 (file)
@@ -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 (file)
index 0000000..93932f8
--- /dev/null
@@ -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;
+  }
+}
+
index 808238dd1fb25c4bc703c749f3b0f5f2f1824240..b796ebfae8711111060faf9c81c2d1f8313691c9 100644 (file)
@@ -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)