Bug 6322 - Implementation of SHA1 in Asterisk (plus dialplan function to use it)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@9138 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2006-02-03 22:37:29 +00:00
parent 193b923925
commit 34bcd0e0b6
8 changed files with 594 additions and 3 deletions

21
utils.c
View File

@@ -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;