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