From a33c04c0cc82e7c4aef640801e39651bcb9342b6 Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Sun, 6 Nov 2016 12:54:05 -0600 Subject: [PATCH] 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 . --- 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 d24d67d6a..c9021ecad 100644 --- a/src/modules/raop/raop_util.c +++ b/src/modules/raop/raop_util.c @@ -30,12 +30,21 @@ #include #include +#include +#include + #include #include #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