mirror of
https://github.com/transmission/transmission
synced 2025-03-10 14:13:23 +00:00
Merge branch 'crypto-utils-update'
This commit is contained in:
commit
3f8660557a
6 changed files with 164 additions and 96 deletions
|
@ -9,22 +9,37 @@ endif()
|
|||
|
||||
if(UNIX)
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(_MBEDTLS QUIET mbedtls)
|
||||
endif()
|
||||
|
||||
find_path(MBEDTLS_INCLUDE_DIR NAMES mbedtls/version.h HINTS ${_MBEDTLS_INCLUDEDIR})
|
||||
find_library(MBEDTLS_LIBRARY NAMES mbedtls HINTS ${_MBEDTLS_LIBDIR})
|
||||
if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY)
|
||||
set(POLARSSL_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR})
|
||||
set(POLARSSL_LIBRARY ${MBEDTLS_LIBRARY})
|
||||
set(POLARSSL_VERSION ${_MBEDTLS_VERSION})
|
||||
set(POLARSSL_IS_MBEDTLS ON)
|
||||
else()
|
||||
if(UNIX)
|
||||
pkg_check_modules(_POLARSSL QUIET polarssl)
|
||||
endif()
|
||||
|
||||
find_path(POLARSSL_INCLUDE_DIR NAMES polarssl/version.h HINTS ${_POLARSSL_INCLUDEDIR})
|
||||
find_library(POLARSSL_LIBRARY NAMES polarssl HINTS ${_POLARSSL_LIBDIR})
|
||||
|
||||
if(POLARSSL_INCLUDE_DIR)
|
||||
if(_POLARSSL_VERSION)
|
||||
set(POLARSSL_VERSION ${_POLARSSL_VERSION})
|
||||
set(POLARSSL_IS_MBEDTLS OFF)
|
||||
endif()
|
||||
|
||||
if(NOT POLARSSL_VERSION AND POLARSSL_INCLUDE_DIR)
|
||||
if(POLARSSL_IS_MBEDTLS)
|
||||
file(STRINGS "${POLARSSL_INCLUDE_DIR}/mbedtls/version.h" POLARSSL_VERSION_STR REGEX "^#define[\t ]+MBEDTLS_VERSION_STRING[\t ]+\"[^\"]+\"")
|
||||
else()
|
||||
file(STRINGS "${POLARSSL_INCLUDE_DIR}/polarssl/version.h" POLARSSL_VERSION_STR REGEX "^#define[\t ]+POLARSSL_VERSION_STRING[\t ]+\"[^\"]+\"")
|
||||
endif()
|
||||
if(POLARSSL_VERSION_STR MATCHES "\"([^\"]+)\"")
|
||||
set(POLARSSL_VERSION "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(POLARSSL_INCLUDE_DIRS ${POLARSSL_INCLUDE_DIR})
|
||||
set(POLARSSL_LIBRARIES ${POLARSSL_LIBRARY})
|
||||
|
@ -39,7 +54,7 @@ find_package_handle_standard_args(PolarSSL
|
|||
POLARSSL_VERSION
|
||||
)
|
||||
|
||||
mark_as_advanced(POLARSSL_INCLUDE_DIR POLARSSL_LIBRARY)
|
||||
mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARY POLARSSL_INCLUDE_DIR POLARSSL_LIBRARY)
|
||||
|
||||
if(POLARSSL_PREFER_STATIC_LIB)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${POLARSSL_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
|
|
|
@ -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"],
|
||||
|
@ -149,7 +149,9 @@ AS_IF([test "x$want_crypto" = "xauto" -o "x$want_crypto" = "xcyassl"], [
|
|||
)
|
||||
])
|
||||
AS_IF([test "x$want_crypto" = "xauto" -o "x$want_crypto" = "xpolarssl"], [
|
||||
AC_CHECK_HEADER([polarssl/version.h],
|
||||
PKG_CHECK_MODULES(MBEDTLS, [mbedtls >= $POLARSSL_MINIMUM],
|
||||
[want_crypto="polarssl"; CRYPTO_PKG="polarssl"; CRYPTO_CFLAGS="$MBEDTLS_CFLAGS"; CRYPTO_LIBS="$MBEDTLS_LIBS"; POLARSSL_IS_MBEDTLS=yes],
|
||||
[AC_CHECK_HEADER([polarssl/version.h],
|
||||
[AC_EGREP_CPP([version_ok], [#include <polarssl/version.h>
|
||||
#if defined (POLARSSL_VERSION_NUMBER) && POLARSSL_VERSION_NUMBER >= $POLARSSL_MINIMUM
|
||||
version_ok
|
||||
|
@ -167,6 +169,7 @@ AS_IF([test "x$want_crypto" = "xauto" -o "x$want_crypto" = "xpolarssl"], [
|
|||
[AS_IF([test "x$want_crypto" = "xpolarssl"],
|
||||
[AC_MSG_ERROR([PolarSSL support requested, but headers not found.])]
|
||||
)]
|
||||
)]
|
||||
)
|
||||
])
|
||||
# we should have found the library by now
|
||||
|
@ -179,7 +182,9 @@ 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)
|
||||
AC_SUBST(CRYPTO_CFLAGS)
|
||||
AC_SUBST(CRYPTO_LIBS)
|
||||
|
|
|
@ -196,6 +196,14 @@ 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()
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SOURCE_DIR}
|
||||
${PROJECT_BINARY_DIR}
|
||||
|
|
|
@ -100,9 +100,15 @@ 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
|
||||
if POLARSSL_IS_MBEDTLS
|
||||
AM_CPPFLAGS += -DPOLARSSL_IS_MBEDTLS
|
||||
endif
|
||||
endif
|
||||
|
||||
noinst_HEADERS = \
|
||||
|
|
|
@ -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,8 +221,8 @@ 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,
|
||||
API (InitDhKey) (&handle->dh);
|
||||
if (!check_result (API (DhSetKey) (&handle->dh,
|
||||
prime_num, prime_num_length,
|
||||
generator_num, generator_num_length)))
|
||||
{
|
||||
|
@ -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,7 +266,7 @@ tr_dh_make_key (tr_dh_ctx_t raw_handle,
|
|||
|
||||
tr_lockLock (rng_lock);
|
||||
|
||||
if (!check_result (DhGenerateKeyPair (&handle->dh, get_rng (),
|
||||
if (!check_result (API (DhGenerateKeyPair) (&handle->dh, get_rng (),
|
||||
handle->private_key, &my_private_key_length,
|
||||
public_key, &my_public_key_length)))
|
||||
{
|
||||
|
@ -286,7 +300,7 @@ tr_dh_agree (tr_dh_ctx_t raw_handle,
|
|||
|
||||
ret = tr_dh_secret_new (handle->key_length);
|
||||
|
||||
if (check_result (DhAgree (&handle->dh,
|
||||
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)))
|
||||
|
@ -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;
|
||||
|
|
|
@ -1,20 +1,30 @@
|
|||
/*
|
||||
* This file Copyright (C) 2014-2015 Mnemosyne LLC
|
||||
* This file Copyright (C) 2014-2016 Mnemosyne LLC
|
||||
*
|
||||
* It may be used under the GNU GPL versions 2 or 3
|
||||
* or any future license endorsed by Mnemosyne LLC.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined (POLARSSL_IS_MBEDTLS)
|
||||
#define API_HEADER(x) <mbedtls/x>
|
||||
#define API(x) mbedtls_##x
|
||||
#define API_VERSION_NUMBER MBEDTLS_VERSION_NUMBER
|
||||
#else
|
||||
#define API_HEADER(x) <polarssl/x>
|
||||
#define API(x) x
|
||||
#define API_VERSION_NUMBER POLARSSL_VERSION_NUMBER
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <polarssl/arc4.h>
|
||||
#include <polarssl/base64.h>
|
||||
#include <polarssl/ctr_drbg.h>
|
||||
#include <polarssl/dhm.h>
|
||||
#include <polarssl/error.h>
|
||||
#include <polarssl/sha1.h>
|
||||
#include <polarssl/version.h>
|
||||
#include API_HEADER (arc4.h)
|
||||
#include API_HEADER (base64.h)
|
||||
#include API_HEADER (ctr_drbg.h)
|
||||
#include API_HEADER (dhm.h)
|
||||
#include API_HEADER (error.h)
|
||||
#include API_HEADER (sha1.h)
|
||||
#include API_HEADER (version.h)
|
||||
|
||||
#include "transmission.h"
|
||||
#include "crypto-utils.h"
|
||||
|
@ -40,7 +50,9 @@ log_polarssl_error (int error_code,
|
|||
{
|
||||
char error_message[256];
|
||||
|
||||
#if POLARSSL_VERSION_NUMBER >= 0x01030000
|
||||
#if defined (POLARSSL_IS_MBEDTLS)
|
||||
mbedtls_strerror (error_code, error_message, sizeof (error_message));
|
||||
#elif API_VERSION_NUMBER >= 0x01030000
|
||||
polarssl_strerror (error_code, error_message, sizeof (error_message));
|
||||
#else
|
||||
error_strerror (error_code, error_message, sizeof (error_message));
|
||||
|
@ -50,7 +62,7 @@ log_polarssl_error (int error_code,
|
|||
}
|
||||
}
|
||||
|
||||
#define log_error(error_code) log_polarssl_error(error_code, __FILE__, __LINE__)
|
||||
#define log_error(error_code) log_polarssl_error ((error_code), __FILE__, __LINE__)
|
||||
|
||||
static bool
|
||||
check_polarssl_result (int result,
|
||||
|
@ -82,15 +94,20 @@ my_rand (void * context UNUSED, unsigned char * buffer, size_t buffer_size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ctr_drbg_context *
|
||||
static API (ctr_drbg_context) *
|
||||
get_rng (void)
|
||||
{
|
||||
static ctr_drbg_context rng;
|
||||
static API (ctr_drbg_context) rng;
|
||||
static bool rng_initialized = false;
|
||||
|
||||
if (!rng_initialized)
|
||||
{
|
||||
if (!check_result (ctr_drbg_init (&rng, &my_rand, NULL, NULL, 0)))
|
||||
#if API_VERSION_NUMBER >= 0x02000000
|
||||
API (ctr_drbg_init) (&rng);
|
||||
if (!check_result (API (ctr_drbg_seed) (&rng, &my_rand, NULL, NULL, 0)))
|
||||
#else
|
||||
if (!check_result (API (ctr_drbg_init) (&rng, &my_rand, NULL, NULL, 0)))
|
||||
#endif
|
||||
return NULL;
|
||||
rng_initialized = true;
|
||||
}
|
||||
|
@ -116,13 +133,13 @@ get_rng_lock (void)
|
|||
tr_sha1_ctx_t
|
||||
tr_sha1_init (void)
|
||||
{
|
||||
sha1_context * handle = tr_new0 (sha1_context, 1);
|
||||
API (sha1_context) * handle = tr_new0 (API (sha1_context), 1);
|
||||
|
||||
#if POLARSSL_VERSION_NUMBER >= 0x01030800
|
||||
sha1_init (handle);
|
||||
#if API_VERSION_NUMBER >= 0x01030800
|
||||
API (sha1_init) (handle);
|
||||
#endif
|
||||
|
||||
sha1_starts (handle);
|
||||
API (sha1_starts) (handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@ -138,7 +155,7 @@ tr_sha1_update (tr_sha1_ctx_t handle,
|
|||
|
||||
assert (data != NULL);
|
||||
|
||||
sha1_update (handle, data, data_length);
|
||||
API (sha1_update) (handle, data, data_length);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -150,11 +167,11 @@ tr_sha1_final (tr_sha1_ctx_t handle,
|
|||
{
|
||||
assert (handle != NULL);
|
||||
|
||||
sha1_finish (handle, hash);
|
||||
API (sha1_finish) (handle, hash);
|
||||
}
|
||||
|
||||
#if POLARSSL_VERSION_NUMBER >= 0x01030800
|
||||
sha1_free (handle);
|
||||
#if API_VERSION_NUMBER >= 0x01030800
|
||||
API (sha1_free) (handle);
|
||||
#endif
|
||||
|
||||
tr_free (handle);
|
||||
|
@ -168,10 +185,10 @@ tr_sha1_final (tr_sha1_ctx_t handle,
|
|||
tr_rc4_ctx_t
|
||||
tr_rc4_new (void)
|
||||
{
|
||||
arc4_context * handle = tr_new0 (arc4_context, 1);
|
||||
API (arc4_context) * handle = tr_new0 (API (arc4_context), 1);
|
||||
|
||||
#if POLARSSL_VERSION_NUMBER >= 0x01030800
|
||||
arc4_init (handle);
|
||||
#if API_VERSION_NUMBER >= 0x01030800
|
||||
API (arc4_init) (handle);
|
||||
#endif
|
||||
|
||||
return handle;
|
||||
|
@ -180,8 +197,8 @@ tr_rc4_new (void)
|
|||
void
|
||||
tr_rc4_free (tr_rc4_ctx_t handle)
|
||||
{
|
||||
#if POLARSSL_VERSION_NUMBER >= 0x01030800
|
||||
arc4_free (handle);
|
||||
#if API_VERSION_NUMBER >= 0x01030800
|
||||
API (arc4_free) (handle);
|
||||
#endif
|
||||
|
||||
tr_free (handle);
|
||||
|
@ -195,7 +212,7 @@ tr_rc4_set_key (tr_rc4_ctx_t handle,
|
|||
assert (handle != NULL);
|
||||
assert (key != NULL);
|
||||
|
||||
arc4_setup (handle, key, key_length);
|
||||
API (arc4_setup) (handle, key, key_length);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -212,7 +229,7 @@ tr_rc4_process (tr_rc4_ctx_t handle,
|
|||
assert (input != NULL);
|
||||
assert (output != NULL);
|
||||
|
||||
arc4_crypt (handle, length, input, output);
|
||||
API (arc4_crypt) (handle, length, input, output);
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -225,19 +242,19 @@ tr_dh_new (const uint8_t * prime_num,
|
|||
const uint8_t * generator_num,
|
||||
size_t generator_num_length)
|
||||
{
|
||||
dhm_context * handle = tr_new0 (dhm_context, 1);
|
||||
API (dhm_context) * handle = tr_new0 (API (dhm_context), 1);
|
||||
|
||||
assert (prime_num != NULL);
|
||||
assert (generator_num != NULL);
|
||||
|
||||
#if POLARSSL_VERSION_NUMBER >= 0x01030800
|
||||
dhm_init (handle);
|
||||
#if API_VERSION_NUMBER >= 0x01030800
|
||||
API (dhm_init) (handle);
|
||||
#endif
|
||||
|
||||
if (!check_result (mpi_read_binary (&handle->P, prime_num, prime_num_length)) ||
|
||||
!check_result (mpi_read_binary (&handle->G, generator_num, generator_num_length)))
|
||||
if (!check_result (API (mpi_read_binary) (&handle->P, prime_num, prime_num_length)) ||
|
||||
!check_result (API (mpi_read_binary) (&handle->G, generator_num, generator_num_length)))
|
||||
{
|
||||
dhm_free (handle);
|
||||
API (dhm_free) (handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -252,7 +269,7 @@ tr_dh_free (tr_dh_ctx_t handle)
|
|||
if (handle == NULL)
|
||||
return;
|
||||
|
||||
dhm_free (handle);
|
||||
API (dhm_free) (handle);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -261,7 +278,7 @@ tr_dh_make_key (tr_dh_ctx_t raw_handle,
|
|||
uint8_t * public_key,
|
||||
size_t * public_key_length)
|
||||
{
|
||||
dhm_context * handle = raw_handle;
|
||||
API (dhm_context) * handle = raw_handle;
|
||||
|
||||
assert (handle != NULL);
|
||||
assert (public_key != NULL);
|
||||
|
@ -269,7 +286,7 @@ tr_dh_make_key (tr_dh_ctx_t raw_handle,
|
|||
if (public_key_length != NULL)
|
||||
*public_key_length = handle->len;
|
||||
|
||||
return check_result (dhm_make_public (handle, private_key_length, public_key,
|
||||
return check_result (API (dhm_make_public) (handle, private_key_length, public_key,
|
||||
handle->len, my_rand, NULL));
|
||||
}
|
||||
|
||||
|
@ -278,14 +295,14 @@ tr_dh_agree (tr_dh_ctx_t raw_handle,
|
|||
const uint8_t * other_public_key,
|
||||
size_t other_public_key_length)
|
||||
{
|
||||
dhm_context * handle = raw_handle;
|
||||
API (dhm_context) * handle = raw_handle;
|
||||
struct tr_dh_secret * ret;
|
||||
size_t secret_key_length;
|
||||
|
||||
assert (handle != NULL);
|
||||
assert (other_public_key != NULL);
|
||||
|
||||
if (!check_result (dhm_read_public (handle, other_public_key,
|
||||
if (!check_result (API (dhm_read_public )(handle, other_public_key,
|
||||
other_public_key_length)))
|
||||
return NULL;
|
||||
|
||||
|
@ -293,11 +310,14 @@ tr_dh_agree (tr_dh_ctx_t raw_handle,
|
|||
|
||||
secret_key_length = handle->len;
|
||||
|
||||
#if POLARSSL_VERSION_NUMBER >= 0x01030000
|
||||
if (!check_result (dhm_calc_secret (handle, ret->key,
|
||||
#if API_VERSION_NUMBER >= 0x02000000
|
||||
if (!check_result (API (dhm_calc_secret) (handle, ret->key, secret_key_length,
|
||||
&secret_key_length, my_rand, NULL)))
|
||||
#elif API_VERSION_NUMBER >= 0x01030000
|
||||
if (!check_result (API (dhm_calc_secret) (handle, ret->key,
|
||||
&secret_key_length, my_rand, NULL)))
|
||||
#else
|
||||
if (!check_result (dhm_calc_secret (handle, ret->key, &secret_key_length)))
|
||||
if (!check_result (API (dhm_calc_secret) (handle, ret->key, &secret_key_length)))
|
||||
#endif
|
||||
{
|
||||
tr_dh_secret_free (ret);
|
||||
|
@ -323,7 +343,7 @@ tr_rand_buffer (void * buffer,
|
|||
assert (buffer != NULL);
|
||||
|
||||
tr_lockLock (rng_lock);
|
||||
ret = check_result (ctr_drbg_random (get_rng (), buffer, length));
|
||||
ret = check_result (API (ctr_drbg_random) (get_rng (), buffer, length));
|
||||
tr_lockUnlock (rng_lock);
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Reference in a new issue