From 34bcd0e0b65aef5a30b1b87a1e934a22757f1e5a Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Fri, 3 Feb 2006 22:37:29 +0000 Subject: 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 --- include/asterisk/sha1.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ include/asterisk/utils.h | 3 ++ 2 files changed, 85 insertions(+) create mode 100644 include/asterisk/sha1.h (limited to 'include/asterisk') diff --git a/include/asterisk/sha1.h b/include/asterisk/sha1.h new file mode 100644 index 000000000..016556ece --- /dev/null +++ b/include/asterisk/sha1.h @@ -0,0 +1,82 @@ +/* + * sha1.h + * + * Description: + * This is the header file for code which implements the Secure + * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published + * April 17, 1995. + * + * Many of the variable names in this code, especially the + * single character names, were used because those were the names + * used in the publication. + * + * Please read the file sha1.c for more information. + * + */ + + +#ifndef _SHA1_H_ +#define _SHA1_H_ + + + +#if defined(__OpenBSD__) || defined( __FreeBSD__) +#include +#else +#include +#endif + +/* + * If you do not have the ISO standard stdint.h header file, then you + * must typdef the following: + * name meaning + * uint32_t unsigned 32 bit integer + * uint8_t unsigned 8 bit integer (i.e., unsigned char) + * int_least16_t integer of >= 16 bits + * + */ + +#ifndef _SHA_enum_ +#define _SHA_enum_ +enum +{ + shaSuccess = 0, + shaNull, /* Null pointer parameter */ + shaInputTooLong, /* input data too long */ + shaStateError /* called Input after Result */ +}; +#endif +#define SHA1HashSize 20 + +/* + * This structure will hold context information for the SHA-1 + * hashing operation + */ +typedef struct SHA1Context +{ + uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */ + + uint32_t Length_Low; /* Message length in bits */ + uint32_t Length_High; /* Message length in bits */ + + /* Index into message block array */ + int_least16_t Message_Block_Index; + uint8_t Message_Block[64]; /* 512-bit message blocks */ + + int Computed; /* Is the digest computed? */ + int Corrupted; /* Is the message digest corrupted? */ +} SHA1Context; + +/* + * Function Prototypes + */ + + +int SHA1Reset( SHA1Context *); +int SHA1Input( SHA1Context *, + const uint8_t *, + unsigned int); +int SHA1Result( SHA1Context *, + uint8_t Message_Digest[SHA1HashSize]); + +#endif diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index f16817b86..416f362f6 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -145,6 +145,9 @@ struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp); /* ast_md5_hash \brief Produces MD5 hash based on input string */ void ast_md5_hash(char *output, char *input); +/* ast_sha1_hash + \brief Produces SHA1 hash based on input string */ +void ast_sha1_hash(char *output, char *input); int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max); int ast_base64decode(unsigned char *dst, const char *src, int max); -- cgit v1.2.3