summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/utils.c b/utils.c
index 977f0cdd0..0022a31bd 100644
--- a/utils.c
+++ b/utils.c
@@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/io.h"
#include "asterisk/logger.h"
#include "asterisk/md5.h"
+#include "asterisk/sha1.h"
#include "asterisk/options.h"
#include "asterisk/compat.h"
@@ -281,7 +282,7 @@ int test_for_thread_safety(void)
return(test_errors); /* return 0 on success. */
}
-/*! \brief ast_md5_hash: Produce 16 char MD5 hash of value. ---*/
+/*! \brief ast_md5_hash: Produce 32 char MD5 hash of value. ---*/
void ast_md5_hash(char *output, char *input)
{
struct MD5Context md5;
@@ -297,6 +298,24 @@ void ast_md5_hash(char *output, char *input)
ptr += sprintf(ptr, "%2.2x", digest[x]);
}
+/*! \brief ast_sha1_hash: Produce 40 char SHA1 hash of value. ---*/
+void ast_sha1_hash(char *output, char *input)
+{
+ struct SHA1Context sha;
+ char *ptr;
+ int x;
+ uint8_t Message_Digest[20];
+
+ SHA1Reset(&sha);
+
+ SHA1Input(&sha, (const unsigned char *) input, strlen(input));
+
+ SHA1Result(&sha, Message_Digest);
+ ptr = output;
+ for (x = 0; x < 20; x++)
+ ptr += sprintf(ptr, "%2.2x", Message_Digest[x]);
+}
+
int ast_base64decode(unsigned char *dst, const char *src, int max)
{
int cnt = 0;