2016-10-05 22:40:33 +02:00
|
|
|
--- nemo-gtkhash.orig/configure.ac
|
|
|
|
+++ nemo-gtkhash/configure.ac
|
|
|
|
@@ -144,13 +144,25 @@ AC_ARG_ENABLE([polarssl],
|
|
|
|
AC_MSG_RESULT(["${enable_polarssl}"])
|
|
|
|
AM_CONDITIONAL([ENABLE_POLARSSL], [test "${enable_polarssl}" = "yes"])
|
|
|
|
AC_DEFINE([ENABLE_POLARSSL], [0], [Use PolarSSL])
|
2016-10-05 22:47:44 +02:00
|
|
|
+AC_DEFINE([HAVE_MBEDTLS_2_0_0], [0], [Have mbed TLS 2.x+])
|
2016-10-05 22:40:33 +02:00
|
|
|
|
|
|
|
if test "${enable_polarssl}" = "yes" ; then
|
|
|
|
- AC_CHECK_HEADER([polarssl/md.h], [:], [AC_MSG_ERROR([polarssl headers not found])])
|
|
|
|
- AC_CHECK_LIB([polarssl], [md_update], [:], [AC_MSG_ERROR([polarssl library not found])])
|
|
|
|
- POLARSSL_LIBS="-lpolarssl"
|
|
|
|
+ AC_CHECK_HEADER([mbedtls/md.h], [have_mbedtls_2_0_0="yes"], [have_mbedtls_2_0_0="no"])
|
|
|
|
+ AC_CHECK_HEADER([polarssl/md.h], [have_mbedtls_1_3_0="yes"], [have_mbedtls_1_3_0="no"])
|
|
|
|
+ if test "${have_mbedtls_2_0_0}" != "yes" && test "${have_mbedtls_1_3_0}" != "yes"; then
|
|
|
|
+ AC_MSG_ERROR([mbedtls headers not found])
|
|
|
|
+ fi
|
|
|
|
+ if test "${have_mbedtls_2_0_0}" = "yes"; then
|
|
|
|
+ AC_CHECK_LIB([mbedcrypto], [mbedtls_md_update], [:], [AC_MSG_ERROR([mbedtls library not found])])
|
|
|
|
+ POLARSSL_LIBS="-lmbedcrypto"
|
|
|
|
+ hash_libs="${hash_libs} mbedtls"
|
|
|
|
+ AC_DEFINE([HAVE_MBEDTLS_2_0_0], [1])
|
|
|
|
+ else
|
|
|
|
+ AC_CHECK_LIB([polarssl], [md_update], [:], [AC_MSG_ERROR([mbedtls library not found])])
|
|
|
|
+ POLARSSL_LIBS="-lpolarssl"
|
|
|
|
+ hash_libs="${hash_libs} polarssl"
|
|
|
|
+ fi
|
|
|
|
AC_SUBST([POLARSSL_LIBS])
|
|
|
|
- hash_libs="${hash_libs} polarssl"
|
|
|
|
AC_DEFINE([ENABLE_POLARSSL], [1])
|
|
|
|
fi
|
|
|
|
|
|
|
|
@@ -365,6 +377,7 @@ nss_funcs="
|
|
|
|
SHA1 SHA256 SHA384 SHA512"
|
|
|
|
polarssl_funcs="
|
|
|
|
MD2 MD4 MD5
|
|
|
|
+ RIPEMD160
|
|
|
|
SHA1 SHA224 SHA256 SHA384 SHA512"
|
|
|
|
zlib_funcs="
|
|
|
|
CRC32
|
|
|
|
--- nemo-gtkhash.orig/src/hash/hash-lib-polarssl.c
|
|
|
|
+++ nemo-gtkhash/src/hash/hash-lib-polarssl.c
|
|
|
|
@@ -25,7 +25,11 @@
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <glib.h>
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+#include <mbedtls/md.h>
|
|
|
|
+#else
|
|
|
|
#include <polarssl/md.h>
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
#include "hash-lib-polarssl.h"
|
|
|
|
#include "hash-lib.h"
|
|
|
|
@@ -34,35 +38,83 @@
|
|
|
|
#define LIB_DATA ((struct hash_lib_polarssl_s *)func->lib_data)
|
|
|
|
|
|
|
|
struct hash_lib_polarssl_s {
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ mbedtls_md_context_t ctx;
|
|
|
|
+#else
|
|
|
|
md_context_t ctx;
|
|
|
|
+#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
-static bool gtkhash_hash_lib_polarssl_set_type(const enum hash_func_e id, md_type_t *type)
|
|
|
|
+static bool gtkhash_hash_lib_polarssl_set_type(const enum hash_func_e id,
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ mbedtls_md_type_t *type)
|
|
|
|
+#else
|
|
|
|
+ md_type_t *type)
|
|
|
|
+#endif
|
|
|
|
{
|
|
|
|
switch (id) {
|
|
|
|
case HASH_FUNC_MD2:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_MD2;
|
|
|
|
+#else
|
|
|
|
*type = POLARSSL_MD_MD2;
|
|
|
|
+#endif
|
|
|
|
break;
|
|
|
|
case HASH_FUNC_MD4:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_MD4;
|
|
|
|
+#else
|
|
|
|
*type = POLARSSL_MD_MD4;
|
|
|
|
+#endif
|
|
|
|
break;
|
|
|
|
case HASH_FUNC_MD5:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_MD5;
|
|
|
|
+#else
|
|
|
|
*type = POLARSSL_MD_MD5;
|
|
|
|
+#endif
|
|
|
|
+ break;
|
|
|
|
+ case HASH_FUNC_RIPEMD160:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_RIPEMD160;
|
|
|
|
+#else
|
|
|
|
+ *type = POLARSSL_MD_RIPEMD160;
|
|
|
|
+#endif
|
|
|
|
break;
|
|
|
|
case HASH_FUNC_SHA1:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_SHA1;
|
|
|
|
+#else
|
|
|
|
*type = POLARSSL_MD_SHA1;
|
|
|
|
+#endif
|
|
|
|
break;
|
|
|
|
case HASH_FUNC_SHA224:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_SHA224;
|
|
|
|
+#else
|
|
|
|
*type = POLARSSL_MD_SHA224;
|
|
|
|
+#endif
|
|
|
|
break;
|
|
|
|
case HASH_FUNC_SHA256:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_SHA256;
|
|
|
|
+#else
|
|
|
|
*type = POLARSSL_MD_SHA256;
|
|
|
|
+#endif
|
|
|
|
break;
|
|
|
|
case HASH_FUNC_SHA384:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_SHA384;
|
|
|
|
+#else
|
|
|
|
*type = POLARSSL_MD_SHA384;
|
|
|
|
+#endif
|
|
|
|
break;
|
|
|
|
case HASH_FUNC_SHA512:
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *type = MBEDTLS_MD_SHA512;
|
|
|
|
+#else
|
|
|
|
*type = POLARSSL_MD_SHA512;
|
|
|
|
+#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
@@ -71,14 +123,29 @@ static bool gtkhash_hash_lib_polarssl_se
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
bool gtkhash_hash_lib_polarssl_is_supported(const enum hash_func_e id)
|
|
|
|
{
|
|
|
|
- struct hash_lib_polarssl_s data;
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ mbedtls_md_type_t type;
|
|
|
|
+#else
|
|
|
|
md_type_t type;
|
|
|
|
-
|
|
|
|
+#endif
|
|
|
|
if (!gtkhash_hash_lib_polarssl_set_type(id, &type))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
+ struct hash_lib_polarssl_s data;
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ mbedtls_md_init(&data.ctx);
|
|
|
|
+
|
|
|
|
+ const mbedtls_md_info_t *info = mbedtls_md_info_from_type(type);
|
|
|
|
+ if (mbedtls_md_setup(&data.ctx, info, 0) != 0) {
|
|
|
|
+ mbedtls_md_free(&data.ctx);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mbedtls_md_free(&data.ctx);
|
|
|
|
+#else
|
|
|
|
if (md_init_ctx(&data.ctx, md_info_from_type(type)) != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
@@ -86,6 +153,7 @@ bool gtkhash_hash_lib_polarssl_is_suppor
|
|
|
|
g_assert_not_reached();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
@@ -93,34 +161,67 @@ bool gtkhash_hash_lib_polarssl_is_suppor
|
|
|
|
void gtkhash_hash_lib_polarssl_start(struct hash_func_s *func)
|
|
|
|
{
|
|
|
|
func->lib_data = g_new(struct hash_lib_polarssl_s, 1);
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ mbedtls_md_type_t type;
|
|
|
|
+#else
|
|
|
|
md_type_t type;
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
if (!gtkhash_hash_lib_polarssl_set_type(func->id, &type))
|
|
|
|
g_assert_not_reached();
|
|
|
|
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ mbedtls_md_init(&LIB_DATA->ctx);
|
|
|
|
+
|
|
|
|
+ const mbedtls_md_info_t *info = mbedtls_md_info_from_type(type);
|
|
|
|
+ if (mbedtls_md_setup(&LIB_DATA->ctx, info, 0) != 0)
|
|
|
|
+ g_assert_not_reached();
|
|
|
|
+
|
|
|
|
+ if (mbedtls_md_starts(&LIB_DATA->ctx) != 0)
|
|
|
|
+ g_assert_not_reached();
|
|
|
|
+
|
|
|
|
+#else
|
|
|
|
if (md_init_ctx(&LIB_DATA->ctx, md_info_from_type(type)) != 0)
|
|
|
|
g_assert_not_reached();
|
|
|
|
|
|
|
|
if (md_starts(&LIB_DATA->ctx) != 0)
|
|
|
|
g_assert_not_reached();
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void gtkhash_hash_lib_polarssl_update(struct hash_func_s *func,
|
|
|
|
const uint8_t *buffer, const size_t size)
|
|
|
|
{
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ mbedtls_md_update(&LIB_DATA->ctx, buffer, size);
|
|
|
|
+#else
|
|
|
|
md_update(&LIB_DATA->ctx, buffer, size);
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void gtkhash_hash_lib_polarssl_stop(struct hash_func_s *func)
|
|
|
|
{
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ mbedtls_md_free(&LIB_DATA->ctx);
|
|
|
|
+#else
|
|
|
|
if (md_free_ctx(&LIB_DATA->ctx) != 0)
|
|
|
|
g_assert_not_reached();
|
|
|
|
+#endif
|
|
|
|
g_free(LIB_DATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *gtkhash_hash_lib_polarssl_finish(struct hash_func_s *func,
|
|
|
|
size_t *size)
|
|
|
|
{
|
2016-10-05 22:59:36 +02:00
|
|
|
+#if HAVE_MBEDTLS_2_0_0
|
2016-10-05 22:40:33 +02:00
|
|
|
+ *size = mbedtls_md_get_size(LIB_DATA->ctx.md_info);
|
|
|
|
+ uint8_t *digest = g_malloc(*size);
|
|
|
|
+
|
|
|
|
+ if (mbedtls_md_finish(&LIB_DATA->ctx, digest) != 0)
|
|
|
|
+ g_assert_not_reached();
|
|
|
|
+
|
|
|
|
+ mbedtls_md_free(&LIB_DATA->ctx);
|
|
|
|
+#else
|
|
|
|
*size = LIB_DATA->ctx.md_info->size;
|
|
|
|
uint8_t *digest = g_malloc(*size);
|
|
|
|
|
|
|
|
@@ -129,6 +230,7 @@ uint8_t *gtkhash_hash_lib_polarssl_finis
|
|
|
|
|
|
|
|
if (md_free_ctx(&LIB_DATA->ctx) != 0)
|
|
|
|
g_assert_not_reached();
|
|
|
|
+#endif
|
|
|
|
g_free(LIB_DATA);
|
|
|
|
|
|
|
|
return digest;
|