[asterisk-commits] tilghman: branch tilghman/tomcrypt r83154 - in /team/tilghman/tomcrypt: chann...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 19 11:23:51 CDT 2007


Author: tilghman
Date: Wed Sep 19 11:23:51 2007
New Revision: 83154

URL: http://svn.digium.com/view/asterisk?view=rev&rev=83154
Log:
Replacement of md5 code

Modified:
    team/tilghman/tomcrypt/channels/chan_iax2.c
    team/tilghman/tomcrypt/include/asterisk/crypto.h
    team/tilghman/tomcrypt/include/asterisk/utils.h
    team/tilghman/tomcrypt/main/Makefile
    team/tilghman/tomcrypt/main/loader.c
    team/tilghman/tomcrypt/main/manager.c
    team/tilghman/tomcrypt/main/utils.c
    team/tilghman/tomcrypt/res/res_crypto.c
    team/tilghman/tomcrypt/utils/Makefile

Modified: team/tilghman/tomcrypt/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/channels/chan_iax2.c?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/channels/chan_iax2.c (original)
+++ team/tilghman/tomcrypt/channels/chan_iax2.c Wed Sep 19 11:23:51 2007
@@ -1694,7 +1694,7 @@
 	struct iax_firmware *cur = NULL;
 	int ifd, fd, res, len, chunk;
 	struct ast_iax2_firmware_header *fwh, fwh2;
-	struct MD5Context md5;
+	ltc_hash_state md;
 	unsigned char sum[16], buf[1024];
 	char *s2, *last;
 
@@ -1784,9 +1784,9 @@
 		close(fd);
 		return -1;
 	}
-	MD5Init(&md5);
-	MD5Update(&md5, fwh->data, ntohl(fwh->datalen));
-	MD5Final(sum, &md5);
+	ltc_md5_init(&md);
+	ltc_md5_process(&md, fwh->data, ntohl(fwh->datalen));
+	ltc_md5_done(&md, sum);
 	if (memcmp(sum, fwh->chksum, sizeof(sum))) {
 		ast_log(LOG_WARNING, "Firmware file '%s' fails checksum\n", s);
 		munmap((void*)fwh, stbuf.st_size);
@@ -4230,17 +4230,17 @@
 	int res=-1;
 	if (!ast_test_flag(iaxs[callno], IAX_KEYPOPULATED)) {
 		/* Search for possible keys, given secrets */
-		struct MD5Context md5;
+		ltc_hash_state md;
 		unsigned char digest[16];
 		char *tmppw, *stringp;
 		
 		tmppw = ast_strdupa(iaxs[callno]->secret);
 		stringp = tmppw;
 		while ((tmppw = strsep(&stringp, ";"))) {
-			MD5Init(&md5);
-			MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
-			MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
-			MD5Final(digest, &md5);
+			ltc_md5_init(&md);
+			ltc_md5_process(&md, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
+			ltc_md5_process(&md, (unsigned char *)tmppw, strlen(tmppw));
+			ltc_md5_done(&md, digest);
 			build_enc_keys(digest, &iaxs[callno]->ecx, &iaxs[callno]->dcx);
 			res = decode_frame(&iaxs[callno]->dcx, fh, f, datalen);
 			if (!res) {
@@ -5449,17 +5449,17 @@
 			keyn = strsep(&stringp, ":");
 		}
 	} else if (p->authmethods & IAX_AUTH_MD5) {
-		struct MD5Context md5;
+		ltc_hash_state md;
 		unsigned char digest[16];
 		char *tmppw, *stringp;
 		
 		tmppw = ast_strdupa(p->secret);
 		stringp = tmppw;
 		while((tmppw = strsep(&stringp, ";"))) {
-			MD5Init(&md5);
-			MD5Update(&md5, (unsigned char *)p->challenge, strlen(p->challenge));
-			MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
-			MD5Final(digest, &md5);
+			ltc_md5_init(&md);
+			ltc_md5_process(&md, (unsigned char *)p->challenge, strlen(p->challenge));
+			ltc_md5_process(&md, (unsigned char *)tmppw, strlen(tmppw));
+			ltc_md5_done(&md, digest);
 			/* If they support md5, authenticate with it.  */
 			for (x=0;x<16;x++)
 				sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
@@ -5561,17 +5561,17 @@
 			goto return_unref;
 		}
 	} else if (!ast_strlen_zero(md5secret) && (p->authmethods & IAX_AUTH_MD5) && !ast_strlen_zero(iaxs[callno]->challenge)) {
-		struct MD5Context md5;
+		ltc_hash_state md;
 		unsigned char digest[16];
 		char *tmppw, *stringp;
 		
 		tmppw = ast_strdupa(p->secret);
 		stringp = tmppw;
 		while((tmppw = strsep(&stringp, ";"))) {
-			MD5Init(&md5);
-			MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
-			MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
-			MD5Final(digest, &md5);
+			ltc_md5_init(&md);
+			ltc_md5_process(&md, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
+			ltc_md5_process(&md, (unsigned char *)tmppw, strlen(tmppw));
+			ltc_md5_done(&md, digest);
 			for (x=0;x<16;x++)
 				sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
 			if (!strcasecmp(requeststr, md5secret)) 
@@ -5643,13 +5643,13 @@
 	/* Fall back */
 	if (res && !ast_strlen_zero(secret)) {
 		if ((authmethods & IAX_AUTH_MD5) && !ast_strlen_zero(challenge)) {
-			struct MD5Context md5;
+			ltc_hash_state md;
 			unsigned char digest[16];
 			char digres[128];
-			MD5Init(&md5);
-			MD5Update(&md5, (unsigned char *)challenge, strlen(challenge));
-			MD5Update(&md5, (unsigned char *)secret, strlen(secret));
-			MD5Final(digest, &md5);
+			ltc_md5_init(&md);
+			ltc_md5_process(&md, (unsigned char *)challenge, strlen(challenge));
+			ltc_md5_process(&md, (unsigned char *)secret, strlen(secret));
+			ltc_md5_done(&md, digest);
 			/* If they support md5, authenticate with it.  */
 			for (x=0;x<16;x++)
 				sprintf(digres + (x << 1),  "%2.2x", digest[x]); /* safe */

Modified: team/tilghman/tomcrypt/include/asterisk/crypto.h
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/include/asterisk/crypto.h?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/include/asterisk/crypto.h (original)
+++ team/tilghman/tomcrypt/include/asterisk/crypto.h Wed Sep 19 11:23:51 2007
@@ -158,7 +158,7 @@
 int ltc_sha1_process(ltc_hash_state * md, const unsigned char *in, unsigned long inlen);
 int ltc_sha1_done(ltc_hash_state * md, unsigned char *hash);
 
-/*! \brief SHA512 cryptographic hash routines (not used yet) */
+/*! \brief SHA512 cryptographic hash routines */
 int ltc_sha512_init(ltc_hash_state * md);
 int ltc_sha512_process(ltc_hash_state * md, const unsigned char *in, unsigned long inlen);
 int ltc_sha512_done(ltc_hash_state * md, unsigned char *hash);

Modified: team/tilghman/tomcrypt/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/include/asterisk/utils.h?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/include/asterisk/utils.h (original)
+++ team/tilghman/tomcrypt/include/asterisk/utils.h Wed Sep 19 11:23:51 2007
@@ -225,6 +225,8 @@
 void ast_md5_hash(char *output, char *input);
 /*! \brief Produces SHA1 hash based on input string */
 void ast_sha1_hash(char *output, char *input);
+/*! \brief Produces SHA512 hash based on input string */
+void ast_sha512_hash(char *output, char *input);
 
 int ast_base64encode_full(char *dst, const unsigned char *src, int srclen, int max, int linebreaks);
 

Modified: team/tilghman/tomcrypt/main/Makefile
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/main/Makefile?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/main/Makefile (original)
+++ team/tilghman/tomcrypt/main/Makefile Wed Sep 19 11:23:51 2007
@@ -18,14 +18,14 @@
 include $(ASTTOPDIR)/Makefile.moddir_rules
 
 OBJS=	io.o sched.o logger.o frame.o loader.o config.o channel.o \
-	translate.o file.o pbx.o cli.o md5.o term.o \
+	translate.o file.o pbx.o cli.o term.o \
 	ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
 	cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
 	dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
-	astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
+	astmm.o enum.o srv.o dns.o \
 	utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
 	netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
-	cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \
+	cryptostub.o http.o fixedjitterbuf.o abstract_jb.o \
 	strcompat.o threadstorage.o dial.o event.o adsistub.o audiohook.o \
 	astobj2.o
 
@@ -57,6 +57,9 @@
       tomcrypt/src/misc/crypt/crypt_hash_is_valid.o \
       tomcrypt/src/misc/zeromem.o \
       tomcrypt/src/hashes/helper/hash_memory.o \
+      tomcrypt/src/hashes/md5.o \
+      tomcrypt/src/hashes/sha1.o \
+      tomcrypt/src/hashes/sha2/sha512.o \
       tomcrypt/src/pk/asn1/der/bit/der_length_bit_string.o \
       tomcrypt/src/pk/asn1/der/bit/der_decode_bit_string.o \
       tomcrypt/src/pk/asn1/der/bit/der_encode_bit_string.o \

Modified: team/tilghman/tomcrypt/main/loader.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/main/loader.c?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/main/loader.c (original)
+++ team/tilghman/tomcrypt/main/loader.c Wed Sep 19 11:23:51 2007
@@ -51,6 +51,7 @@
 #include "asterisk/rtp.h"
 #include "asterisk/http.h"
 #include "asterisk/lock.h"
+#include "asterisk/crypto.h"
 
 #ifdef DLFCNCOMPAT
 #include "asterisk/dlfcn-compat.h"
@@ -58,7 +59,6 @@
 #include <dlfcn.h>
 #endif
 
-#include "asterisk/md5.h"
 #include "asterisk/utils.h"
 
 #ifndef RTLD_NOW
@@ -267,12 +267,12 @@
 
 static int verify_key(const unsigned char *key)
 {
-	struct MD5Context c;
 	unsigned char digest[16];
-
-	MD5Init(&c);
-	MD5Update(&c, key, strlen((char *)key));
-	MD5Final(digest, &c);
+	ltc_hash_state md;
+
+	ltc_md5_init(&md);
+	ltc_md5_process(&md, key, strlen((char *)key));
+	ltc_md5_done(&md, digest);
 
 	if (key_matches(expected_key, digest))
 		return 0;

Modified: team/tilghman/tomcrypt/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/main/manager.c?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/main/manager.c (original)
+++ team/tilghman/tomcrypt/main/manager.c Wed Sep 19 11:23:51 2007
@@ -72,7 +72,6 @@
 #include "asterisk/cli.h"
 #include "asterisk/app.h"
 #include "asterisk/pbx.h"
-#include "asterisk/md5.h"
 #include "asterisk/acl.h"
 #include "asterisk/utils.h"
 #include "asterisk/http.h"
@@ -80,6 +79,7 @@
 #include "asterisk/threadstorage.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/term.h"
+#include "asterisk/crypto.h"
 
 /*!
  * Linked list of events.
@@ -1074,14 +1074,14 @@
 		    !ast_strlen_zero(password)) {
 			int x;
 			int len = 0;
-			char md5key[256] = "";
-			struct MD5Context md5;
+			char md5key[32] = "";
+			ltc_hash_state md;
 			unsigned char digest[16];
 
-			MD5Init(&md5);
-			MD5Update(&md5, (unsigned char *) s->challenge, strlen(s->challenge));
-			MD5Update(&md5, (unsigned char *) password, strlen(password));
-			MD5Final(digest, &md5);
+			ltc_md5_init(&md);
+			ltc_md5_process(&md, (unsigned char *) s->challenge, strlen(s->challenge));
+			ltc_md5_process(&md, (unsigned char *) password, strlen(password));
+			ltc_md5_done(&md, digest);
 			for (x=0; x<16; x++)
 				len += sprintf(md5key + len, "%2.2x", digest[x]);
 			if (!strcmp(md5key, key))

Modified: team/tilghman/tomcrypt/main/utils.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/main/utils.c?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/main/utils.c (original)
+++ team/tilghman/tomcrypt/main/utils.c Wed Sep 19 11:23:51 2007
@@ -53,6 +53,7 @@
 #include "asterisk/options.h"
 #include "asterisk/cli.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/crypto.h"
 
 #define AST_API_MODULE		/* ensure that inlinable API functions will be built in this module if required */
 #include "asterisk/strings.h"
@@ -298,14 +299,14 @@
 /*! \brief Produce 32 char MD5 hash of value. */
 void ast_md5_hash(char *output, char *input)
 {
-	struct MD5Context md5;
+	ltc_hash_state md;
 	unsigned char digest[16];
 	char *ptr;
 	int x;
 
-	MD5Init(&md5);
-	MD5Update(&md5, (unsigned char *)input, strlen(input));
-	MD5Final(digest, &md5);
+	ltc_md5_init(&md);
+	ltc_md5_process(&md, (unsigned char *)input, strlen(input));
+	ltc_md5_done(&md, digest);
 	ptr = output;
 	for (x = 0; x < 16; x++)
 		ptr += sprintf(ptr, "%2.2x", digest[x]);
@@ -314,20 +315,35 @@
 /*! \brief Produce 40 char SHA1 hash of value. */
 void ast_sha1_hash(char *output, char *input)
 {
-	struct SHA1Context sha;
+	ltc_hash_state md;
 	char *ptr;
 	int x;
-	uint8_t Message_Digest[20];
-
-	SHA1Reset(&sha);
-	
-	SHA1Input(&sha, (const unsigned char *) input, strlen(input));
-
-	SHA1Result(&sha, Message_Digest);
+	unsigned char Message_Digest[20];
+
+	ltc_sha1_init(&md);
+	ltc_sha1_process(&md, (const unsigned char *) input, strlen(input));
+	ltc_sha1_done(&md, Message_Digest);
 	ptr = output;
 	for (x = 0; x < 20; x++)
 		ptr += sprintf(ptr, "%2.2x", Message_Digest[x]);
 }
+
+/*! \brief Produce 128 char SHA512 hash of value */
+void ast_sha512_hash(char *output, char *input)
+{
+	ltc_hash_state md;
+	unsigned char digest[64];
+	char *ptr;
+	int x;
+
+	ltc_sha512_init(&md);
+	ltc_sha512_process(&md, (unsigned char *)input, strlen(input));
+	ltc_sha512_done(&md, digest);
+	ptr = output;
+	for (x = 0; x < 64; x++)
+		ptr += sprintf(ptr, "%2.2x", digest[x]);
+}
+
 
 /*! \brief decode BASE64 encoded text */
 int ast_base64decode(unsigned char *dst, const char *src, int max)

Modified: team/tilghman/tomcrypt/res/res_crypto.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/res/res_crypto.c?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/res/res_crypto.c (original)
+++ team/tilghman/tomcrypt/res/res_crypto.c Wed Sep 19 11:23:51 2007
@@ -162,7 +162,7 @@
 	char *c = NULL, ffname[256];
 	unsigned char digest[16];
 	FILE *f;
-	struct MD5Context md5;
+	ltc_hash_state md;
 	struct ast_key *key;
 	static int notice = 0;
 
@@ -183,15 +183,15 @@
 		return NULL;
 	}
 
-	MD5Init(&md5);
+	ltc_md5_init(&md);
 	while(!feof(f)) {
 		/* Calculate a "whatever" quality md5sum of the key */
 		char buf[256] = "";
 		fgets(buf, sizeof(buf), f);
 		if (!feof(f))
-			MD5Update(&md5, (unsigned char *) buf, strlen(buf));
-	}
-	MD5Final(digest, &md5);
+			ltc_md5_process(&md, (unsigned char *) buf, strlen(buf));
+	}
+	ltc_md5_done(&md, digest);
 
 	/* Look for an existing key */
 	AST_RWLIST_TRAVERSE(&keys, key, list) {

Modified: team/tilghman/tomcrypt/utils/Makefile
URL: http://svn.digium.com/view/asterisk/team/tilghman/tomcrypt/utils/Makefile?view=diff&rev=83154&r1=83153&r2=83154
==============================================================================
--- team/tilghman/tomcrypt/utils/Makefile (original)
+++ team/tilghman/tomcrypt/utils/Makefile Wed Sep 19 11:23:51 2007
@@ -17,7 +17,7 @@
 
 # to get check_expr, add it to the ALL_UTILS list
 ALL_UTILS:=astman smsq stereorize streamplayer aelparse muted check_expr conf2ael hashtest2
-UTILS:=$(ALL_UTILS)
+#UTILS:=$(ALL_UTILS)
 
 include $(ASTTOPDIR)/Makefile.rules
 
@@ -114,7 +114,7 @@
 
 aelparse: aelparse.o aelbison.o pbx_ael.o ael_main.o ast_expr2f.o ast_expr2.o strcompat.o pval.o extconf.o
 
-astobj2.c : ../main/astobj2.c  ../include/asterisk/astobj2.h
+astobj2.c : ../main/astobj2.c  ../include/asterisk/astobj2.h ../main/tomcrypt/
 	cp ../main/astobj2.c .
 
 utils.c : ../main/utils.c




More information about the asterisk-commits mailing list