Browse Source

Fix #1908

pull/1947/head
Max Lv 7 years ago
parent
commit
6e1e005221
1 changed files with 13 additions and 0 deletions
  1. 13
      src/crypto.c

13
src/crypto.c

@ -33,6 +33,7 @@
#include <stdint.h> #include <stdint.h>
#include <sodium.h> #include <sodium.h>
#include <mbedtls/version.h>
#include <mbedtls/md5.h> #include <mbedtls/md5.h>
#include "base64.h" #include "base64.h"
@ -102,7 +103,19 @@ crypto_md5(const unsigned char *d, size_t n, unsigned char *md)
if (md == NULL) { if (md == NULL) {
md = m; md = m;
} }
#if MBEDTLS_VERSION_NUMBER >= 0x02070000
mbedtls_md5_context md5;
mbedtls_md5_init(&md5);
if (mbedtls_md5_starts_ret(&md5) != 0)
FATAL("Failed to initialize MD5 context");
if (mbedtls_md5_update_ret(&md5, d, n) != 0)
FATAL("Failed to update MD5 sum");
if (mbedtls_md5_finish_ret(&md5, md) != 0)
FATAL("Failed to generate MD5 hash");
mbedtls_md5_free(&md5);
#else
mbedtls_md5(d, n, md); mbedtls_md5(d, n, md);
#endif
return md; return md;
} }

Loading…
Cancel
Save