[pulseaudio-discuss] [PATCH v7 11/33] raop: Add a MD5 hashing fuction

Hajime Fujita crisp.fujita at gmail.com
Sun Nov 6 18:54:05 UTC 2016


From: Martin Blanchard <tchaik at gmx.com>

MD5 hashing will be needed during the authentication process.

Original patch by Martin Blanchard. Patch splitted by
Hajime Fujita <crisp.fujita at nifty.com>.
---
 src/modules/raop/raop_util.c | 27 +++++++++++++++++++++++++++
 src/modules/raop/raop_util.h |  2 ++
 2 files changed, 29 insertions(+)

diff --git a/src/modules/raop/raop_util.c b/src/modules/raop/raop_util.c
index d24d67d..c9021ec 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 7a8d73e..dc0b767 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
-- 
2.9.3



More information about the pulseaudio-discuss mailing list