]> granicus.if.org Git - transmission/commitdiff
Improve support for wolfssl (formely cyassl)
authorMike Gelfand <mikedld@mikedld.com>
Wed, 26 Oct 2016 19:12:51 +0000 (22:12 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Wed, 26 Oct 2016 19:27:20 +0000 (22:27 +0300)
configure.ac
libtransmission/CMakeLists.txt
libtransmission/Makefile.am
libtransmission/crypto-utils-cyassl.c

index 01772232223d2d6bbd8052650b495c87b12660c5..f8c129e08bd71e8bd9ffd799dc2dcfcaaa38151e 100644 (file)
@@ -139,7 +139,7 @@ AS_IF([test "x$want_crypto" = "xauto" -o "x$want_crypto" = "xopenssl"], [
 ])
 AS_IF([test "x$want_crypto" = "xauto" -o "x$want_crypto" = "xcyassl"], [
     PKG_CHECK_MODULES(WOLFSSL, [wolfssl >= $CYASSL_MINIMUM],
-        [want_crypto="cyassl"; CRYPTO_PKG="cyassl"; CRYPTO_CFLAGS="$WOLFSSL_CFLAGS"; CRYPTO_LIBS="$WOLFSSL_LIBS"],
+        [want_crypto="cyassl"; CRYPTO_PKG="cyassl"; CRYPTO_CFLAGS="$WOLFSSL_CFLAGS"; CRYPTO_LIBS="$WOLFSSL_LIBS"; CYASSL_IS_WOLFSSL=yes],
         [PKG_CHECK_MODULES(CYASSL, [cyassl >= $CYASSL_MINIMUM],
             [want_crypto="cyassl"; CRYPTO_PKG="cyassl"; CRYPTO_CFLAGS="$CYASSL_CFLAGS"; CRYPTO_LIBS="$CYASSL_LIBS"],
             [AS_IF([test "x$want_crypto" = "xcyassl"],
@@ -182,6 +182,7 @@ AS_IF([test "x$CRYPTO_PKG" = "x"], [
 
 AM_CONDITIONAL([CRYPTO_USE_OPENSSL],[test "x$CRYPTO_PKG" = "xopenssl"])
 AM_CONDITIONAL([CRYPTO_USE_CYASSL],[test "x$CRYPTO_PKG" = "xcyassl"])
+AM_CONDITIONAL([CYASSL_IS_WOLFSSL],[test "x$CYASSL_IS_WOLFSSL" = "xyes"])
 AM_CONDITIONAL([CRYPTO_USE_POLARSSL],[test "x$CRYPTO_PKG" = "xpolarssl"])
 AM_CONDITIONAL([POLARSSL_IS_MBEDTLS],[test "x$POLARSSL_IS_MBEDTLS" = "xyes"])
 AC_SUBST(CRYPTO_PKG)
index c7d096e401e08114dc3c7d62afb4b8d826d989e0..4ff920d85f45347e09a6cc1bede108bfe4c2eb9a 100644 (file)
@@ -196,6 +196,10 @@ if(USE_SYSTEM_B64)
     add_definitions(-DUSE_SYSTEM_B64)
 endif()
 
+if(CYASSL_IS_WOLFSSL)
+    add_definitions(-DCYASSL_IS_WOLFSSL)
+endif()
+
 if(POLARSSL_IS_MBEDTLS)
     add_definitions(-DPOLARSSL_IS_MBEDTLS)
 endif()
index 24b1a7a72a09fe0e8aaacb54d9c9473fb6e7f6a3..ba4696104d789039c410301afd1f893925f3a7ab 100644 (file)
@@ -100,6 +100,9 @@ libtransmission_a_SOURCES += crypto-utils-openssl.c
 endif
 if CRYPTO_USE_CYASSL
 libtransmission_a_SOURCES += crypto-utils-cyassl.c
+if CYASSL_IS_WOLFSSL
+AM_CPPFLAGS += -DCYASSL_IS_WOLFSSL
+endif
 endif
 if CRYPTO_USE_POLARSSL
 libtransmission_a_SOURCES += crypto-utils-polarssl.c
index 851633f13cf7266dc1c1a104a97b45c9f8e89ce0..e22f63951641be6bf25c28e4c32b7812ae969118 100644 (file)
@@ -6,14 +6,26 @@
  *
  */
 
+#if defined (CYASSL_IS_WOLFSSL)
+ #define API_HEADER(x) <wolfssl/x>
+ #define API_HEADER_CRYPT(x) API_HEADER (wolfcrypt/x)
+ #define API(x) wc_##x
+ #define API_VERSION_HEX LIBWOLFSSL_VERSION_HEX
+#else
+ #define API_HEADER(x) <cyassl/x>
+ #define API_HEADER_CRYPT(x) API_HEADER (ctaocrypt/x)
+ #define API(x) x
+ #define API_VERSION_HEX LIBCYASSL_VERSION_HEX
+#endif
+
 #include <assert.h>
 
-#include <cyassl/ctaocrypt/arc4.h>
-#include <cyassl/ctaocrypt/dh.h>
-#include <cyassl/ctaocrypt/error-crypt.h>
-#include <cyassl/ctaocrypt/random.h>
-#include <cyassl/ctaocrypt/sha.h>
-#include <cyassl/version.h>
+#include API_HEADER_CRYPT (arc4.h)
+#include API_HEADER_CRYPT (dh.h)
+#include API_HEADER_CRYPT (error-crypt.h)
+#include API_HEADER_CRYPT (random.h)
+#include API_HEADER_CRYPT (sha.h)
+#include API_HEADER (version.h)
 
 #include "transmission.h"
 #include "crypto-utils.h"
@@ -45,7 +57,9 @@ log_cyassl_error (int          error_code,
 {
   if (tr_logLevelIsActive (TR_LOG_ERROR))
     {
-#if LIBCYASSL_VERSION_HEX >= 0x03000002
+#if API_VERSION_HEX >= 0x03004000
+      const char * error_message = API (GetErrorString) (error_code);
+#elif API_VERSION_HEX >= 0x03000002
       const char * error_message = CTaoCryptGetErrorString (error_code);
 #else
       char error_message[CYASSL_MAX_ERROR_SZ];
@@ -81,7 +95,7 @@ get_rng (void)
 
   if (!rng_initialized)
     {
-      if (!check_result (InitRng (&rng)))
+      if (!check_result (API (InitRng) (&rng)))
         return NULL;
       rng_initialized = true;
     }
@@ -109,7 +123,7 @@ tr_sha1_init (void)
 {
   Sha * handle = tr_new (Sha, 1);
 
-  if (check_result (InitSha (handle)))
+  if (check_result (API (InitSha) (handle)))
     return handle;
 
   tr_free (handle);
@@ -128,7 +142,7 @@ tr_sha1_update (tr_sha1_ctx_t   handle,
 
   assert (data != NULL);
 
-  return check_result (ShaUpdate (handle, data, data_length));
+  return check_result (API (ShaUpdate) (handle, data, data_length));
 }
 
 bool
@@ -141,7 +155,7 @@ tr_sha1_final (tr_sha1_ctx_t   handle,
     {
       assert (handle != NULL);
 
-      ret = check_result (ShaFinal (handle, hash));
+      ret = check_result (API (ShaFinal) (handle, hash));
     }
 
   tr_free (handle);
@@ -172,7 +186,7 @@ tr_rc4_set_key (tr_rc4_ctx_t    handle,
   assert (handle != NULL);
   assert (key != NULL);
 
-  Arc4SetKey (handle, key, key_length);
+  API (Arc4SetKey) (handle, key, key_length);
 }
 
 void
@@ -189,7 +203,7 @@ tr_rc4_process (tr_rc4_ctx_t   handle,
   assert (input != NULL);
   assert (output != NULL);
 
-  Arc4Process (handle, output, input, length);
+  API (Arc4Process) (handle, output, input, length);
 }
 
 /***
@@ -207,10 +221,10 @@ tr_dh_new (const uint8_t * prime_num,
   assert (prime_num != NULL);
   assert (generator_num != NULL);
 
-  InitDhKey (&handle->dh);
-  if (!check_result (DhSetKey (&handle->dh,
-                               prime_num, prime_num_length,
-                               generator_num, generator_num_length)))
+  API (InitDhKey) (&handle->dh);
+  if (!check_result (API (DhSetKey) (&handle->dh,
+                                     prime_num, prime_num_length,
+                                     generator_num, generator_num_length)))
     {
       tr_free (handle);
       return NULL;
@@ -229,7 +243,7 @@ tr_dh_free (tr_dh_ctx_t raw_handle)
   if (handle == NULL)
     return;
 
-  FreeDhKey (&handle->dh);
+  API (FreeDhKey) (&handle->dh);
   tr_free (handle->private_key);
   tr_free (handle);
 }
@@ -252,9 +266,9 @@ tr_dh_make_key (tr_dh_ctx_t   raw_handle,
 
   tr_lockLock (rng_lock);
 
-  if (!check_result (DhGenerateKeyPair (&handle->dh, get_rng (),
-                                        handle->private_key, &my_private_key_length,
-                                        public_key, &my_public_key_length)))
+  if (!check_result (API (DhGenerateKeyPair) (&handle->dh, get_rng (),
+                                              handle->private_key, &my_private_key_length,
+                                              public_key, &my_public_key_length)))
     {
       tr_lockUnlock (rng_lock);
       return false;
@@ -286,10 +300,10 @@ tr_dh_agree (tr_dh_ctx_t     raw_handle,
 
   ret = tr_dh_secret_new (handle->key_length);
 
-  if (check_result (DhAgree (&handle->dh,
-                             ret->key, &my_secret_key_length,
-                             handle->private_key, handle->private_key_length,
-                             other_public_key, other_public_key_length)))
+  if (check_result (API (DhAgree) (&handle->dh,
+                                   ret->key, &my_secret_key_length,
+                                   handle->private_key, handle->private_key_length,
+                                   other_public_key, other_public_key_length)))
     {
       tr_dh_secret_align (ret, my_secret_key_length);
     }
@@ -316,7 +330,7 @@ tr_rand_buffer (void   * buffer,
   assert (buffer != NULL);
 
   tr_lockLock (rng_lock);
-  ret = check_result (RNG_GenerateBlock (get_rng (), buffer, length));
+  ret = check_result (API (RNG_GenerateBlock) (get_rng (), buffer, length));
   tr_lockUnlock (rng_lock);
 
   return ret;