Alexei Sorokin 2016-10-05 20:59:36 +00:00 committed by Git OBS Bridge
parent fd06a90ed6
commit c0cd7febd3

View File

@ -44,7 +44,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <glib.h>
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+#include <mbedtls/md.h>
+#else
#include <polarssl/md.h>
@ -56,7 +56,7 @@
#define LIB_DATA ((struct hash_lib_polarssl_s *)func->lib_data)
struct hash_lib_polarssl_s {
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ mbedtls_md_context_t ctx;
+#else
md_context_t ctx;
@ -65,7 +65,7 @@
-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,
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ mbedtls_md_type_t *type)
+#else
+ md_type_t *type)
@ -73,63 +73,63 @@
{
switch (id) {
case HASH_FUNC_MD2:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_MD2;
+#else
*type = POLARSSL_MD_MD2;
+#endif
break;
case HASH_FUNC_MD4:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_MD4;
+#else
*type = POLARSSL_MD_MD4;
+#endif
break;
case HASH_FUNC_MD5:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_MD5;
+#else
*type = POLARSSL_MD_MD5;
+#endif
+ break;
+ case HASH_FUNC_RIPEMD160:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_RIPEMD160;
+#else
+ *type = POLARSSL_MD_RIPEMD160;
+#endif
break;
case HASH_FUNC_SHA1:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_SHA1;
+#else
*type = POLARSSL_MD_SHA1;
+#endif
break;
case HASH_FUNC_SHA224:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_SHA224;
+#else
*type = POLARSSL_MD_SHA224;
+#endif
break;
case HASH_FUNC_SHA256:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_SHA256;
+#else
*type = POLARSSL_MD_SHA256;
+#endif
break;
case HASH_FUNC_SHA384:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_SHA384;
+#else
*type = POLARSSL_MD_SHA384;
+#endif
break;
case HASH_FUNC_SHA512:
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *type = MBEDTLS_MD_SHA512;
+#else
*type = POLARSSL_MD_SHA512;
@ -145,7 +145,7 @@
bool gtkhash_hash_lib_polarssl_is_supported(const enum hash_func_e id)
{
- struct hash_lib_polarssl_s data;
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ mbedtls_md_type_t type;
+#else
md_type_t type;
@ -155,7 +155,7 @@
return false;
+ struct hash_lib_polarssl_s data;
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ mbedtls_md_init(&data.ctx);
+
+ const mbedtls_md_info_t *info = mbedtls_md_info_from_type(type);
@ -181,7 +181,7 @@
void gtkhash_hash_lib_polarssl_start(struct hash_func_s *func)
{
func->lib_data = g_new(struct hash_lib_polarssl_s, 1);
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ mbedtls_md_type_t type;
+#else
md_type_t type;
@ -190,7 +190,7 @@
if (!gtkhash_hash_lib_polarssl_set_type(func->id, &type))
g_assert_not_reached();
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ mbedtls_md_init(&LIB_DATA->ctx);
+
+ const mbedtls_md_info_t *info = mbedtls_md_info_from_type(type);
@ -212,7 +212,7 @@
void gtkhash_hash_lib_polarssl_update(struct hash_func_s *func,
const uint8_t *buffer, const size_t size)
{
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ mbedtls_md_update(&LIB_DATA->ctx, buffer, size);
+#else
md_update(&LIB_DATA->ctx, buffer, size);
@ -221,7 +221,7 @@
void gtkhash_hash_lib_polarssl_stop(struct hash_func_s *func)
{
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ mbedtls_md_free(&LIB_DATA->ctx);
+#else
if (md_free_ctx(&LIB_DATA->ctx) != 0)
@ -233,7 +233,7 @@
uint8_t *gtkhash_hash_lib_polarssl_finish(struct hash_func_s *func,
size_t *size)
{
+#ifdef HAVE_MBEDTLS_2_0_0
+#if HAVE_MBEDTLS_2_0_0
+ *size = mbedtls_md_get_size(LIB_DATA->ctx.md_info);
+ uint8_t *digest = g_malloc(*size);
+