summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Blanchard <tchaik@gmx.com>2016-11-06 12:54:05 -0600
committerTanu Kaskinen <tanuk@iki.fi>2017-01-19 03:00:45 +0200
commita33c04c0cc82e7c4aef640801e39651bcb9342b6 (patch)
tree06ce7d37b92b41999246278c4096c5c71c9b7563
parentbac8a2ba66e0194f539a5e0fdca99f8c6c70a9c2 (diff)
raop: Add a MD5 hashing fuction
MD5 hashing will be needed during the authentication process. Original patch by Martin Blanchard. Patch splitted by Hajime Fujita <crisp.fujita@nifty.com>.
-rw-r--r--src/modules/raop/raop_util.c27
-rw-r--r--src/modules/raop/raop_util.h2
2 files changed, 29 insertions, 0 deletions
diff --git a/src/modules/raop/raop_util.c b/src/modules/raop/raop_util.c
index d24d67d6a..c9021ecad 100644
--- a/src/modules/raop/raop_util.c
+++ b/src/modules/raop/raop_util.c
@@ -30,12 +30,21 @@
#include <stdlib.h>
#include <string.h>
+#include <openssl/err.h>
+#include <openssl/md5.h>
+
#include <pulse/xmalloc.h>
#include <pulsecore/macro.h>
#include "raop_util.h"
+#ifndef MD5_DIGEST_LENGTH
+#define MD5_DIGEST_LENGTH 16
+#endif
+
+#define MD5_HASH_LENGTH (2*MD5_DIGEST_LENGTH)
+
#define BASE64_DECODE_ERROR 0xffffffff
static const char base64_chars[] =
@@ -141,3 +150,21 @@ int pa_raop_base64_decode(const char *str, void *data) {
return q - (unsigned char *) data;
}
+
+int pa_raop_md5_hash(const char *data, int len, char **str) {
+ unsigned char d[MD5_DIGEST_LENGTH];
+ char *s = NULL;
+ int i;
+
+ pa_assert(data);
+ pa_assert(str);
+
+ MD5((unsigned char*) data, len, d);
+ s = pa_xnew(char, MD5_HASH_LENGTH);
+ for (i = 0; i < MD5_DIGEST_LENGTH; i++)
+ sprintf(&s[2*i], "%02x", (unsigned int) d[i]);
+
+ *str = s;
+ s[MD5_HASH_LENGTH] = 0;
+ return strlen(s);
+}
diff --git a/src/modules/raop/raop_util.h b/src/modules/raop/raop_util.h
index 7a8d73e5b..dc0b76790 100644
--- a/src/modules/raop/raop_util.h
+++ b/src/modules/raop/raop_util.h
@@ -30,4 +30,6 @@
int pa_raop_base64_encode(const void *data, int len, char **str);
int pa_raop_base64_decode(const char *str, void *data);
+int pa_raop_md5_hash(const char *data, int len, char **str);
+
#endif