diff -Naur libdkim/src/Makefile libdkim_17_patched/src/Makefile
--- libdkim/src/Makefile	2007-02-22 13:40:30.000000000 +0000
+++ libdkim_17_patched/src/Makefile	2008-04-09 15:24:53.000000000 +0100
@@ -1,41 +1,41 @@
-# libdkim makefile for UNIX
-#
-
-#ifdef LINUX
-CFLAGS  = -c
-LFLAGS  = 
-LIBS    = -lcrypto -lresolv
-#else
-CFLAGS  = -c
-LFLAGS  = 
-LIBS    = -lcrypto 
-#endif
-
-INCL	=  -I /usr/include/openssl/
-
-SRCS = dkim.cpp dns.cpp dkimbase.cpp dkimsign.cpp dkimverify.cpp
-
-OBJS = $(SRCS:.cpp=.o)
-
-HDRS = dkim.h dns.h dkimbase.h dkimsign.h dkimverify.h
-
-all: libdkim.a libdkimtest
-
-libdkim.a: $(OBJS)
-	rm -f libdkim.a
-	ar cr libdkim.a $(OBJS)
-	ranlib libdkim.a
-
-libdkimtest : libdkim.a libdkimtest.o
-	g++ -olibdkimtest $(LFLAGS) \
-	       -L . libdkimtest.o $(LIBS) -ldkim
-	
-libdkimtest.o: libdkimtest.cpp $(HDRS)
-
-.cpp.o:
-	g++ $(CFLAGS) -c $<
-
-clean:
-	rm  *.o libdkim.lib libdkimtest
-
-
+# libdkim makefile for UNIX
+#
+
+ifdef LINUX
+CFLAGS  = -c
+LFLAGS  = 
+LIBS    = -lcrypto -lresolv
+else
+CFLAGS  = -c
+LFLAGS  = 
+LIBS    = -lcrypto -lresolv
+endif
+
+INCL	=  -I /usr/include/openssl/
+
+SRCS = dkim.cpp dns.cpp dkimbase.cpp dkimsign.cpp dkimverify.cpp
+
+OBJS = $(SRCS:.cpp=.o)
+
+HDRS = dkim.h dns.h dkimbase.h dkimsign.h dkimverify.h
+
+all: libdkim.a libdkimtest
+
+libdkim.a: $(OBJS)
+	rm -f libdkim.a
+	ar cr libdkim.a $(OBJS)
+	ranlib libdkim.a
+
+libdkimtest : libdkim.a libdkimtest.o
+	g++ -olibdkimtest $(LFLAGS) $(INCL) \
+	       -L . libdkimtest.o $(LIBS) -ldkim
+
+libdkimtest.o: libdkimtest.cpp $(HDRS)
+
+.cpp.o:
+	g++ $(CFLAGS) $(INCL) -c $<
+
+clean:
+	rm  *.o libdkim.lib libdkimtest
+
+
diff -Naur libdkim/src/dkimbase.cpp libdkim_17_patched/src/dkimbase.cpp
--- libdkim/src/dkimbase.cpp	2007-02-22 13:40:30.000000000 +0000
+++ libdkim_17_patched/src/dkimbase.cpp	2008-04-09 14:12:50.000000000 +0100
@@ -27,7 +27,6 @@
 
 #include <algorithm>
 
-
 CDKIMBase::CDKIMBase()
 {
 	m_From = NULL;
@@ -122,7 +121,7 @@
 
 	while( p < e )
 	{
-		if( *p != '\n' || m_LinePos == 0 || m_Line[m_LinePos-1] != '\r' )
+		if(*p != '\n' && *p != '\r' )
 		{
 			// add char to line
 			if (m_LinePos >= m_LineSize)
@@ -135,13 +134,13 @@
 		}
 		else
 		{
-			// back up past the CR
-			m_LinePos--;
-
-			if( m_LinePos == 0 )
+			if(*p == '\r' && p+1<e && *(p+1)=='\n') p++;
+			if( m_LinePos==0 )
 			{
 				// empty line found.  count it but do not process it
 				m_EmptyLineCount++;
+				m_LinePos=0;
+
 			}
 			else
 			{
diff -Naur libdkim/src/dkimsign.cpp libdkim_17_patched/src/dkimsign.cpp
--- libdkim/src/dkimsign.cpp	2007-09-04 14:38:44.000000000 +0100
+++ libdkim_17_patched/src/dkimsign.cpp	2008-04-10 01:00:21.000000000 +0100
@@ -38,9 +38,9 @@
 
 	EVP_SignInit( &m_allman_sha1ctx, EVP_sha1() );
 	EVP_SignInit( &m_Hdr_ietf_sha1ctx, EVP_sha1() );
-	EVP_SignInit( &m_Hdr_ietf_sha256ctx, EVP_sha256() );
+	EVP_SignInit( &m_Hdr_ietf_sha256ctx, EVP_sha1() );
 	EVP_DigestInit( &m_Bdy_ietf_sha1ctx, EVP_sha1() );
-	EVP_DigestInit( &m_Bdy_ietf_sha256ctx, EVP_sha256() );
+	EVP_DigestInit( &m_Bdy_ietf_sha256ctx, EVP_sha1() );
 }
 
 CDKIMSign::~CDKIMSign()
@@ -163,9 +163,9 @@
 			if( m_nHash & DKIM_HASH_SHA256 )
 			{
 				if( bHdr )
-					EVP_SignUpdate( &m_Hdr_ietf_sha256ctx, szBuffer, nBufLength );
+					EVP_SignUpdate( &m_Hdr_ietf_sha1ctx, szBuffer, nBufLength );
 				else
-					EVP_DigestUpdate( &m_Bdy_ietf_sha256ctx, szBuffer, nBufLength );
+					EVP_DigestUpdate( &m_Bdy_ietf_sha1ctx, szBuffer, nBufLength );
 			}
 			if( m_nHash != DKIM_HASH_SHA256 )
 			{
@@ -766,7 +766,7 @@
 		AddTagToSig( "v", "1", 0, false );
 	}
 
-	AddTagToSig( "a", bUseSha256 ? "rsa-sha256" : "rsa-sha1", 0, false );
+	AddTagToSig( "a", bUseSha256 ? "rsa-sha1" : "rsa-sha1", 0, false );
 
 	switch( m_Canon )
 	{
@@ -827,7 +827,7 @@
 		unsigned char Hash[EVP_MAX_MD_SIZE];
 		unsigned int nHashLen = 0;
 
-		EVP_DigestFinal( bUseSha256 ? &m_Bdy_ietf_sha256ctx : &m_Bdy_ietf_sha1ctx, Hash, &nHashLen );
+		EVP_DigestFinal( bUseSha256 ? &m_Bdy_ietf_sha1ctx : &m_Bdy_ietf_sha1ctx, Hash, &nHashLen );
 
 		bio = BIO_new(BIO_s_mem());
 		if (!bio) {
@@ -898,7 +898,7 @@
 
 	if( bUseIetfBodyHash )
 	{
-		EVP_SignUpdate( bUseSha256 ? &m_Hdr_ietf_sha256ctx : &m_Hdr_ietf_sha1ctx, sTemp.c_str(), sTemp.size() );
+		EVP_SignUpdate( bUseSha256 ? &m_Hdr_ietf_sha1ctx : &m_Hdr_ietf_sha1ctx, sTemp.c_str(), sTemp.size() );
 	}
 	else
 	{
@@ -929,7 +929,7 @@
 	
 	if( bUseIetfBodyHash )
 	{
-		nSignRet = EVP_SignFinal( bUseSha256 ? &m_Hdr_ietf_sha256ctx : &m_Hdr_ietf_sha1ctx, sig, &siglen, pkey);
+		nSignRet = EVP_SignFinal( bUseSha256 ? &m_Hdr_ietf_sha1ctx : &m_Hdr_ietf_sha1ctx, sig, &siglen, pkey);
 	}
 	else
 	{
@@ -1043,19 +1043,6 @@
 			nRet = ConstructSignature( szPrivKey, true, true );
 			if( nRet == DKIM_SUCCESS )
 			{
-				ietfsha256Sig.assign( m_sSig );
-			}
-			else
-			{
-				return nRet;
-			}
-		}
-		if( m_nHash != DKIM_HASH_SHA256 )
-		{
-			nRet = ConstructSignature( szPrivKey, true, false );
-			
-			if( nRet == DKIM_SUCCESS )
-			{
 				ietfsha1Sig.assign( m_sSig );
 			}
 			else
@@ -1063,6 +1050,19 @@
 				return nRet;
 			}
 		}
+// 		if( m_nHash != DKIM_HASH_SHA256 )
+// 		{
+// 			nRet = ConstructSignature( szPrivKey, true, false );
+			
+// 			if( nRet == DKIM_SUCCESS )
+// 			{
+// 				ietfsha1Sig.assign( m_sSig );
+// 			}
+// 			else
+// 			{
+// 				return nRet;
+// 			}
+// 		}
 	}
 
 
@@ -1086,7 +1086,7 @@
 		{
 			m_sReturnedSig.append( "\r\n" );
 		}
-		m_sReturnedSig.append( ietfsha256Sig );
+		m_sReturnedSig.append( ietfsha1Sig );
 	}
 
 	m_bReturnedSigAssembled = true;
diff -Naur libdkim/src/dkimverify.cpp libdkim_17_patched/src/dkimverify.cpp
--- libdkim/src/dkimverify.cpp	2007-10-29 15:15:18.000000000 +0000
+++ libdkim_17_patched/src/dkimverify.cpp	2008-04-10 00:35:19.000000000 +0100
@@ -203,14 +203,15 @@
 unsigned DecodeBase64(char *ptr)
 {
 	static const unsigned char base64_table[256] = {
-		-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-		-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
-		-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
-		-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1,
-		-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-		-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-		-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-		-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
+		(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,
+		(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,62,(unsigned)-1,(unsigned)-1,(unsigned)-1,63,52,53,54,55,56,57,58,59,60,61,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,
+		(unsigned)-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,
+		(unsigned)-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,
+		(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,
+		(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,
+		(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,
+		(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1,(unsigned)-1};
+
 
 	unsigned char *s = (unsigned char *)ptr;
 	unsigned char *d = (unsigned char *)ptr;
@@ -718,7 +719,7 @@
 				sig.Status = DKIM_SELECTOR_GRANULARITY_MISMATCH;		// this error causes the signature to fail
 
 			// check the hash algorithm
-			if ( (sig.m_nHash == DKIM_HASH_SHA1 && !sel.AllowSHA1) || (sig.m_nHash == DKIM_HASH_SHA256 && !sel.AllowSHA256) )
+			if ( (sig.m_nHash == DKIM_HASH_SHA1 && !sel.AllowSHA1) )
 				sig.Status = DKIM_SELECTOR_ALGORITHM_MISMATCH;			// causes signature to fail
 
 			// check for same domain
@@ -732,8 +733,8 @@
 		// initialize the hashes
 		if (sig.m_nHash == DKIM_HASH_SHA256)
 		{
-			EVP_VerifyInit( &sig.m_Hdr_ctx, EVP_sha256() );
-			EVP_DigestInit( &sig.m_Bdy_ctx, EVP_sha256() );
+			EVP_VerifyInit( &sig.m_Hdr_ctx, EVP_sha1() );
+			EVP_DigestInit( &sig.m_Bdy_ctx, EVP_sha1() );
 		}
 		else
 		{
@@ -831,7 +832,7 @@
 		s++;
 	} while (*s != '\0');
 
-	*result = overflowed ? -1 : temp;
+	*result = overflowed ? (unsigned)-1 : temp;
 	return true;
 }
 
@@ -894,10 +895,6 @@
 	{
 		sig.m_nHash = DKIM_HASH_SHA1;
 	}
-	else if (strcmp(values[1], "rsa-sha256") == 0)
-	{
-		sig.m_nHash = DKIM_HASH_SHA256;
-	}
 	else
 	{
 		return DKIM_BAD_SYNTAX;		// todo: maybe create a new error code for unknown algorithm
@@ -1008,7 +1005,7 @@
 	// body count
 	if (values[8] == NULL || !m_HonorBodyLengthTag)
 	{
-		sig.BodyLength = -1;
+		sig.BodyLength = (unsigned)-1;
 	}
 	else
 	{
@@ -1036,7 +1033,7 @@
 	}
 
 	// signature time
-	unsigned SignedTime = -1;
+	unsigned SignedTime = (unsigned)-1;
 	if (values[10] != NULL)
 	{
 		if (!ParseUnsigned(values[10], &SignedTime))
@@ -1046,7 +1043,7 @@
 	// expiration time
 	if (values[11] == NULL)
 	{
-		sig.ExpireTime = -1;
+		sig.ExpireTime = (unsigned)-1;
 	}
 	else
 	{
@@ -1136,7 +1133,7 @@
 SelectorInfo::SelectorInfo(const string &sSelector, const string &sDomain) : Selector(sSelector), Domain(sDomain)
 {
 	AllowSHA1 = true;
-	AllowSHA256 = true;
+	AllowSHA256 = false;
 	PublicKey = NULL;
 	Testing = false;
 	SameDomain = false;
@@ -1194,7 +1191,7 @@
 	if (values[2] == NULL)
 	{
 		AllowSHA1 = true;
-		AllowSHA256 = true;
+		AllowSHA256 = false;
 	}
 	else
 	{
@@ -1204,8 +1201,6 @@
 		{
 			if (strcmp(s, "sha1") == 0)
 				AllowSHA1 = true;
-			else if (strcmp(s, "sha256") == 0)
-				AllowSHA256 = true;
 			s = strtok(NULL, ":");
 		}
 		if ( !(AllowSHA1 || AllowSHA256) )
@@ -1266,7 +1261,7 @@
 	}
 	else
 	{
-		const unsigned char *PublicKeyData = (unsigned char *)values[4];
+		unsigned char *PublicKeyData = (unsigned char *)values[4];
 		EVP_PKEY *pkey = d2i_PUBKEY(NULL, &PublicKeyData, PublicKeyLen);
 
 		if (pkey == NULL)
diff -Naur libdkim/src/libdkimtest.cpp libdkim_17_patched/src/libdkimtest.cpp
--- libdkim/src/libdkimtest.cpp	2007-02-22 17:05:46.000000000 +0000
+++ libdkim_17_patched/src/libdkimtest.cpp	2008-04-09 15:22:21.000000000 +0100
@@ -35,8 +35,23 @@
 	return 0;
 }
 
+void usage()
+{
 
-
+	printf( "usage: libdkimtest [-b<allman|ietf|both>] [-c<r|s|t|u>] [-d<domain>] [-l] [-h] [-i<you@yourdomain.com>] [-q] [-s] [-t] [-v] [-x<expire time>] [-z<hash>] <msgfile> <privkeyfile> <outfile>\n");
+	printf( "-b<standard> allman , ietf or both\n");
+	printf( "-c<canonicalization> r for relaxed [DEFAULT], s - simple, t relaxed/simple, u - simple/relaxed\n");
+	printf( "-d<domain> the domain tag, if not provided it will be determined from the sender/from header\n");
+	printf( "-l include body length tag\n");
+	printf( "-h this help\n");
+	printf( "-i<identity> the identity, if not provided it will not be included\n");
+	printf( "-s sign the message\n");
+	printf( "-t include a timestamp tag\n");
+	printf( "-v verify the message\n");
+	printf( "-x<expire_time> the expire time in seconds since epoch ( DEFAULT = current time + 604800)\n\t if set to - then it will not be included");
+	printf( "-z<hash>  1 for sha1, 2 for sha256, 3 for both\n");
+	printf( "-y<selector> the selector tag DEFAULT=MDaemon\n");
+}
 int main(int argc, char* argv[])
 {
 	int n;
@@ -57,13 +72,11 @@
 	time(&t);
 
 	opts.nCanon = DKIM_SIGN_RELAXED;
-	opts.nIncludeBodyLengthTag = 1;
+	opts.nIncludeBodyLengthTag = 0;
 	opts.nIncludeQueryMethod = 0;
 	opts.nIncludeTimeStamp = 0;
 	opts.expireTime = t + 604800;		// expires in 1 week
 	strcpy( opts.szSelector, "MDaemon" );
-	strcpy( opts.szDomain, "bardenhagen.com" );
-	strcpy( opts.szIdentity, "dkimtest@bardenhagen.com" );
 	opts.pfnHeaderCallback = SignThisHeader;
 	strcpy( opts.szRequiredHeaders, "NonExistant" );
 	opts.nIncludeCopiedHeaders = 0;
@@ -72,6 +85,11 @@
 	int nArgParseState = 0;
 	bool bSign = true;
 
+	if(argc<2){
+		usage();
+		exit(1);
+	}
+
 	for( n = 1; n < argc; n++ )
 	{
 		if( argv[n][0] == '-' && strlen(argv[n]) > 1 )
@@ -101,14 +119,16 @@
 				}
 				break;
 
-
+			case 'd': 
+				strncpy(opts.szDomain,(const char*)(argv[n]+2),sizeof(opts.szDomain)-1);
+				break;
 			case 'l':		// body length tag
 				opts.nIncludeBodyLengthTag = 1;
 				break;
 
 
 			case 'h':
-				printf( "usage: \n" );
+				usage();	
 				return 0;
 
 			case 'i':		// identity 
@@ -118,7 +138,7 @@
 				}
 				else
 				{
-					strcpy( opts.szIdentity, argv[n] + 2 );
+					strncpy( opts.szIdentity, argv[n] + 2,sizeof(opts.szIdentity)-1 );
 				}
 				break;
 
@@ -149,6 +169,9 @@
 				}
 				break;
 
+			case 'y':
+				strncpy( opts.szSelector, argv[n]+2, sizeof(opts.szSelector)-1);
+				break;
 
 			case 'z':		// sign w/ sha1, sha256 or both 
 				opts.nHash = atoi( &argv[n][2] );
@@ -256,7 +279,7 @@
 
 		DKIMVerifyOptions vopts;
 		vopts.pfnSelectorCallback = NULL; //SelectorCallback;
-		vopts.pfnPolicyCallback = NULL; //PolicyCallback;
+		vopts.pfnPracticesCallback = NULL; //PolicyCallback;
 
 		n = DKIMVerifyInit( &ctxt, &vopts );
 
