PNet has a very nice crypto library, but to be ECMA-compliant it only needs
SHA1 hash function. In constrained environments it might be useful to build
PNet with the only hash function needed by standard and no
encryption/decryption support at all. This patch makes full-blown crypto
library optional via profile option.

From: Roman I Khimov <roman@khimov.ru>

diff -puraN pnet.orig/profiles/compact pnet/profiles/compact
--- pnet.orig/profiles/compact	2005-10-29 22:24:30.000000000 +0400
+++ pnet/profiles/compact	2006-11-07 14:27:23.405565000 +0300
@@ -101,3 +101,6 @@ IL_CONFIG_FILESYSTEM=y
 # ECMA compliance. Might differ from observed behavior of .NET (y/n).
 IL_CONFIG_ECMA=y
 
+#Full crypto library support (MD5, SHA256-512, DES, AES, etc...)
+IL_CONFIG_FULL_CRYPTO=y
+
diff -puraN pnet.orig/profiles/compact-fp pnet/profiles/compact-fp
--- pnet.orig/profiles/compact-fp	2005-10-29 22:24:30.000000000 +0400
+++ pnet/profiles/compact-fp	2006-11-07 14:27:23.405565000 +0300
@@ -100,3 +100,6 @@ IL_CONFIG_FILESYSTEM=y
 # ECMA compliance. Might differ from observed behavior of .NET (y/n).
 IL_CONFIG_ECMA=y
 
+#Full crypto library support (MD5, SHA256-512, DES, AES, etc...)
+IL_CONFIG_FULL_CRYPTO=y
+
diff -puraN pnet.orig/profiles/full pnet/profiles/full
--- pnet.orig/profiles/full	2005-10-29 22:24:30.000000000 +0400
+++ pnet/profiles/full	2006-11-07 14:27:23.405565000 +0300
@@ -100,3 +100,6 @@ IL_CONFIG_FILESYSTEM=y
 # ECMA compliance. Might differ from observed behavior of .NET (y/n).
 IL_CONFIG_ECMA=y
 
+#Full crypto library support (MD5, SHA256-512, DES, AES, etc...)
+IL_CONFIG_FULL_CRYPTO=y
+
diff -puraN pnet.orig/profiles/full-tl pnet/profiles/full-tl
--- pnet.orig/profiles/full-tl	2005-10-29 22:24:30.000000000 +0400
+++ pnet/profiles/full-tl	2006-11-07 14:27:23.405565000 +0300
@@ -100,3 +100,6 @@ IL_CONFIG_FILESYSTEM=y
 # ECMA compliance. Might differ from observed behavior of .NET (y/n).
 IL_CONFIG_ECMA=y
 
+#Full crypto library support (MD5, SHA256-512, DES, AES, etc...)
+IL_CONFIG_FULL_CRYPTO=y
+
diff -puraN pnet.orig/profiles/kernel pnet/profiles/kernel
--- pnet.orig/profiles/kernel	2005-10-29 22:24:30.000000000 +0400
+++ pnet/profiles/kernel	2006-11-07 14:27:23.405565000 +0300
@@ -100,3 +100,6 @@ IL_CONFIG_FILESYSTEM=y
 # ECMA compliance. Might differ from observed behavior of .NET (y/n).
 IL_CONFIG_ECMA=y
 
+#Full crypto library support (MD5, SHA256-512, DES, AES, etc...)
+IL_CONFIG_FULL_CRYPTO=y
+
diff -puraN pnet.orig/profiles/kernel-fp pnet/profiles/kernel-fp
--- pnet.orig/profiles/kernel-fp	2005-10-29 22:24:30.000000000 +0400
+++ pnet/profiles/kernel-fp	2006-11-07 14:27:23.405565000 +0300
@@ -100,3 +100,6 @@ IL_CONFIG_FILESYSTEM=y
 # ECMA compliance. Might differ from observed behavior of .NET (y/n).
 IL_CONFIG_ECMA=y
 
+#Full crypto library support (MD5, SHA256-512, DES, AES, etc...)
+IL_CONFIG_FULL_CRYPTO=y
+
diff -puraN pnet.orig/profiles/tiny pnet/profiles/tiny
--- pnet.orig/profiles/tiny	2005-10-29 22:24:30.000000000 +0400
+++ pnet/profiles/tiny	2006-11-07 14:27:54.839529500 +0300
@@ -97,3 +97,6 @@ IL_CONFIG_FILESYSTEM=n
 # ECMA compliance. Might differ from observed behavior of .NET (y/n).
 IL_CONFIG_ECMA=y
 
+#Full crypto library support (MD5, SHA256-512, DES, AES, etc...)
+IL_CONFIG_FULL_CRYPTO=n
+
--- pnet.orig/support/aes.c	2003-05-15 05:12:10.000000000 +0400
+++ pnet/support/aes.c	2006-11-07 15:00:17.668948750 +0300
@@ -28,6 +28,7 @@
 #include "il_crypt.h"
 #include "il_system.h"
 
+#ifdef IL_CONFIG_FULL_CRYPTO
 #ifdef	__cplusplus
 extern	"C" {
 #endif
@@ -587,3 +588,5 @@ int main(int argc, char *argv[])
 #ifdef	__cplusplus
 };
 #endif
+
+#endif /* IL_CONFIG_FULL_CRYPTO */
--- pnet.orig/support/des.c	2002-07-15 04:24:24.000000000 +0400
+++ pnet/support/des.c	2006-11-07 15:00:51.239046750 +0300
@@ -22,6 +22,7 @@
 #include "il_crypt.h"
 #include "il_system.h"
 
+#ifdef IL_CONFIG_FULL_CRYPTO
 #ifdef	__cplusplus
 extern	"C" {
 #endif
@@ -836,3 +837,5 @@ int main(int argc, char *argv[])
 #ifdef	__cplusplus
 };
 #endif
+
+#endif /* IL_CONFIG_FULL_CRYPTO */
--- pnet.orig/support/md5.c	2001-12-04 13:00:20.000000000 +0300
+++ pnet/support/md5.c	2006-11-07 15:01:30.465498250 +0300
@@ -24,6 +24,7 @@
 #include "il_crypt.h"
 #include "il_system.h"
 
+#ifdef IL_CONFIG_FULL_CRYPTO
 #ifdef	__cplusplus
 extern	"C" {
 #endif
@@ -387,3 +388,5 @@ int main(int argc, char *argv[])
 #ifdef	__cplusplus
 };
 #endif
+
+#endif /* IL_CONFIG_FULL_CRYPTO */
--- pnet.orig/support/rc2.c	2003-04-29 11:35:12.000000000 +0400
+++ pnet/support/rc2.c	2006-11-07 15:02:31.897337500 +0300
@@ -26,6 +26,7 @@
 #include "il_crypt.h"
 #include "il_system.h"
 
+#ifdef IL_CONFIG_FULL_CRYPTO
 #ifdef	__cplusplus
 extern	"C" {
 #endif
@@ -409,3 +410,5 @@ int main(int argc, char *argv[])
 #ifdef	__cplusplus
 };
 #endif
+
+#endif /* IL_CONFIG_FULL_CRYPTO */
--- pnet.orig/support/ripemd160.c	2003-11-28 06:59:48.000000000 +0300
+++ pnet/support/ripemd160.c	2006-11-07 15:02:50.118476250 +0300
@@ -23,6 +23,7 @@
 #include "il_crypt.h"
 #include "il_system.h"
 
+#ifdef IL_CONFIG_FULL_CRYPTO
 #ifdef	__cplusplus
 extern	"C" {
 #endif
@@ -564,3 +565,5 @@ int main(int argc, char *argv[])
 #ifdef	__cplusplus
 };
 #endif
+
+#endif /* IL_CONFIG_FULL_CRYPTO */
--- pnet.orig/support/sha256.c	2002-07-12 07:02:42.000000000 +0400
+++ pnet/support/sha256.c	2006-11-07 15:03:12.003844000 +0300
@@ -25,6 +25,7 @@
 #include "il_crypt.h"
 #include "il_system.h"
 
+#ifdef IL_CONFIG_FULL_CRYPTO
 #ifdef	__cplusplus
 extern	"C" {
 #endif
@@ -335,3 +336,5 @@ int main(int argc, char *argv[])
 #ifdef	__cplusplus
 };
 #endif
+
+#endif /* IL_CONFIG_FULL_CRYPTO */
--- pnet.orig/support/sha384.c	2003-11-12 02:24:36.000000000 +0300
+++ pnet/support/sha384.c	2006-11-07 15:03:29.160916250 +0300
@@ -25,6 +25,7 @@
 #include "il_crypt.h"
 #include "il_system.h"
 
+#ifdef IL_CONFIG_FULL_CRYPTO
 #ifdef	__cplusplus
 extern	"C" {
 #endif
@@ -154,3 +155,5 @@ int main(int argc, char *argv[])
 #ifdef	__cplusplus
 };
 #endif
+
+#endif /* IL_CONFIG_FULL_CRYPTO */
--- pnet.orig/support/sha512.c	2003-11-12 02:24:36.000000000 +0300
+++ pnet/support/sha512.c	2006-11-07 15:03:44.613882000 +0300
@@ -25,6 +25,7 @@
 #include "il_crypt.h"
 #include "il_system.h"
 
+#ifdef IL_CONFIG_FULL_CRYPTO
 #ifdef	__cplusplus
 extern	"C" {
 #endif
@@ -380,3 +381,5 @@ int main(int argc, char *argv[])
 #ifdef	__cplusplus
 };
 #endif
+
+#endif /* IL_CONFIG_FULL_CRYPTO */
--- pnet/engine/lib_crypt.c.orig	2006-11-07 15:41:48.176595750 +0300
+++ pnet/engine/lib_crypt.c	2006-11-07 15:43:43.911828750 +0300
@@ -194,8 +194,9 @@ ILBool _IL_CryptoMethods_AlgorithmSuppor
 {
 	switch(algorithm)
 	{
-		case IL_ALG_MD5:
 		case IL_ALG_SHA1:
+#ifdef IL_CONFIG_FULL_CRYPTO
+		case IL_ALG_MD5:
 		case IL_ALG_SHA256:
 		case IL_ALG_SHA384:
 		case IL_ALG_SHA512:
@@ -203,7 +204,9 @@ ILBool _IL_CryptoMethods_AlgorithmSuppor
 		case IL_ALG_TRIPLE_DES:
 		case IL_ALG_RC2:
 		case IL_ALG_RIJNDAEL:
-		case IL_ALG_RIPEMD160: return 1;
+		case IL_ALG_RIPEMD160: 
+#endif /* IL_CONFIG_FULL_CRYPTO */
+			return 1;
 	}
 	return 0;
 }
@@ -216,36 +219,36 @@ ILNativeInt _IL_CryptoMethods_HashNew(IL
 	HashContext *context;
 	switch(algorithm)
 	{
-		case IL_ALG_MD5:
+		case IL_ALG_SHA1:
 		{
-			/* Create and initialize an MD5 context */
-			context = (HashContext *)ILMalloc(sizeof(MD5HashContext));
+			/* Create and initialize an SHA1 context */
+			context = (HashContext *)ILMalloc(sizeof(SHA1HashContext));
 			if(!context)
 			{
 				ILExecThreadThrowOutOfMemory(_thread);
 				return 0;
 			}
-			context->reset = (HashResetFunc)ILMD5Init;
-			context->update = (HashUpdateFunc)ILMD5Data;
-			context->final = (HashFinalFunc)ILMD5Finalize;
-			ILMD5Init(&(((MD5HashContext *)context)->md5));
+			context->reset = (HashResetFunc)ILSHAInit;
+			context->update = (HashUpdateFunc)ILSHAData;
+			context->final = (HashFinalFunc)ILSHAFinalize;
+			ILSHAInit(&(((SHA1HashContext *)context)->sha1));
 			return (ILNativeInt)context;
 		}
 		/* Not reached */
-
-		case IL_ALG_SHA1:
+#ifdef IL_CONFIG_FULL_CRYPTO
+		case IL_ALG_MD5:
 		{
-			/* Create and initialize an SHA1 context */
-			context = (HashContext *)ILMalloc(sizeof(SHA1HashContext));
+			/* Create and initialize an MD5 context */
+			context = (HashContext *)ILMalloc(sizeof(MD5HashContext));
 			if(!context)
 			{
 				ILExecThreadThrowOutOfMemory(_thread);
 				return 0;
 			}
-			context->reset = (HashResetFunc)ILSHAInit;
-			context->update = (HashUpdateFunc)ILSHAData;
-			context->final = (HashFinalFunc)ILSHAFinalize;
-			ILSHAInit(&(((SHA1HashContext *)context)->sha1));
+			context->reset = (HashResetFunc)ILMD5Init;
+			context->update = (HashUpdateFunc)ILMD5Data;
+			context->final = (HashFinalFunc)ILMD5Finalize;
+			ILMD5Init(&(((MD5HashContext *)context)->md5));
 			return (ILNativeInt)context;
 		}
 		/* Not reached */
@@ -317,6 +320,7 @@ ILNativeInt _IL_CryptoMethods_HashNew(IL
 			return (ILNativeInt)context;
 		}
 		/* Not reached */
+#endif /* IL_CONFIG_FULL_CRYPTO */
 	}
 	ILExecThreadSetException(_thread,
 			_ILSystemException(_thread, "System.NotImplementedException"));
@@ -383,7 +387,13 @@ void _IL_CryptoMethods_HashFree(ILExecTh
 ILBool _IL_CryptoMethods_IsSemiWeakKey(ILExecThread *_thread,
 									   System_Array *key, ILInt32 offset)
 {
+#ifdef IL_CONFIG_FULL_CRYPTO
 	return ILDESIsSemiWeakKey(((unsigned char *)ArrayToBuffer(key)) + offset);
+#else /* !IL_CONFIG_FULL_CRYPTO */
+	ILExecThreadSetException(_thread,
+		_ILSystemException(_thread, "System.NotImplementedException"));
+	return 0;
+#endif /* !IL_CONFIG_FULL_CRYPTO */
 }
 
 /*
@@ -392,7 +402,13 @@ ILBool _IL_CryptoMethods_IsSemiWeakKey(I
 ILBool _IL_CryptoMethods_IsWeakKey(ILExecThread *_thread, System_Array *key,
 								   ILInt32 offset)
 {
+#ifdef IL_CONFIG_FULL_CRYPTO
 	return ILDESIsWeakKey(((unsigned char *)ArrayToBuffer(key)) + offset);
+#else /* !IL_CONFIG_FULL_CRYPTO */
+	ILExecThreadSetException(_thread,
+		_ILSystemException(_thread, "System.NotImplementedException"));
+	return 0;
+#endif /* !IL_CONFIG_FULL_CRYPTO */
 }
 
 /*
@@ -548,6 +564,7 @@ ILNativeInt _IL_CryptoMethods_EncryptCre
 											ILInt32 algorithm,
 											System_Array *key)
 {
+#ifdef IL_CONFIG_FULL_CRYPTO
 	SymContext *context;
 	switch(algorithm)
 	{
@@ -623,6 +640,7 @@ ILNativeInt _IL_CryptoMethods_EncryptCre
 		}
 		/* Not reached */
 	}
+#endif /* IL_CONFIG_FULL_CRYPTO */
 	ILExecThreadSetException(_thread,
 			_ILSystemException(_thread, "System.NotImplementedException"));
 	return 0;
@@ -635,6 +653,7 @@ ILNativeInt _IL_CryptoMethods_DecryptCre
 											ILInt32 algorithm,
 											System_Array *key)
 {
+#ifdef IL_CONFIG_FULL_CRYPTO
 	SymContext *context;
 
 	/* DES and Triple-DES need to set up the key schedule
@@ -677,7 +696,7 @@ ILNativeInt _IL_CryptoMethods_DecryptCre
 		}
 		/* Not reached */
 	}
-
+#endif /* IL_CONFIG_FULL_CRYPTO */
 	/* The other algorithms use the same key schedule for
 	   encryption and decryption */
 	return _IL_CryptoMethods_EncryptCreate(_thread, algorithm, key);
