[build] Clean up common crypto build
authorMarek Safar <marek.safar@gmail.com>
Wed, 13 Apr 2016 15:46:25 +0000 (17:46 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 13 Apr 2016 15:48:04 +0000 (17:48 +0200)
20 files changed:
mcs/class/Mono.Security/Makefile
mcs/class/Mono.Security/monotouch_Mono.Security.dll.sources
mcs/class/Mono.Security/xammac_Mono.Security.dll.sources
mcs/class/corlib/CommonCrypto/.gitignore
mcs/class/corlib/CommonCrypto/CommonCryptorGenerator.cs [deleted file]
mcs/class/corlib/CommonCrypto/CommonDigestGenerator.cs [deleted file]
mcs/class/corlib/CommonCrypto/Makefile [new file with mode: 0644]
mcs/class/corlib/CommonCrypto/Makefile.include [deleted file]
mcs/class/corlib/CommonCrypto/generator.cs [deleted file]
mcs/class/corlib/Makefile
mcs/class/corlib/monotouch_corlib.dll.sources
mcs/class/corlib/monotouch_tv_corlib.dll.sources
mcs/class/corlib/monotouch_watch_corlib.dll.sources
mcs/class/corlib/xammac_corlib.dll.sources
mcs/tools/Makefile
mcs/tools/commoncryptogenerator/CommonCryptorGenerator.cs [new file with mode: 0644]
mcs/tools/commoncryptogenerator/CommonDigestGenerator.cs [new file with mode: 0644]
mcs/tools/commoncryptogenerator/Makefile [new file with mode: 0644]
mcs/tools/commoncryptogenerator/commoncryptogenerator.exe.sources [new file with mode: 0644]
mcs/tools/commoncryptogenerator/generator.cs [new file with mode: 0644]

index 1fbfd14ec8efcff4e6514e1cac32c6d3794648a0..522c3583f79850dd7835f2c7106bb85877a204b3 100644 (file)
@@ -8,6 +8,19 @@ LIB_REFS = bare/System
 LIB_MCS_FLAGS = -unsafe -nowarn:1030,3009
 TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:169,219,618,672
 
+CC_PROFILE := $(filter monotouch% xammac, $(PROFILE))
+ifdef CC_PROFILE
+
+BUILT_SOURCES = \
+       ../corlib/CommonCrypto/SHA224Managed.g.cs \
+       ../corlib/CommonCrypto/MD2Managed.g.cs \
+       ../corlib/CommonCrypto/MD4Managed.g.cs
+
+CommonCrypto/%.g.cs:
+       $(MAKE) -C ../corlib/CommonCrypto
+
+endif
+
 include ../../build/library.make
 
 $(build_lib): $(the_libdir_base)bare/System.dll
index 17f56e3c4054885b5f5cf4477cef4bed1ff63c44..36918de7763e9ed1c24609f0a67e752c39967081 100644 (file)
@@ -1,6 +1,3 @@
 #include mobile_Mono.Security.dll.sources
 ../corlib/CommonCrypto/CommonCrypto.cs
 ../corlib/CommonCrypto/RC4CommonCrypto.cs
-../corlib/CommonCrypto/MD2Managed.g.cs
-../corlib/CommonCrypto/MD4Managed.g.cs
-../corlib/CommonCrypto/SHA224Managed.g.cs
index 6c1b4dbef6fda25d7d76612c984ad0776f33ee7f..698996a1d709c630c585a43f2f5ac90021c5e65a 100644 (file)
@@ -1,7 +1,4 @@
 #include monotouch_Mono.Security.dll.sources
 ../corlib/CommonCrypto/CommonCrypto.cs
 ../corlib/CommonCrypto/RC4CommonCrypto.cs
-../corlib/CommonCrypto/MD2Managed.g.cs
-../corlib/CommonCrypto/MD4Managed.g.cs
-../corlib/CommonCrypto/SHA224Managed.g.cs
 
index 1252b936471eb76b900e31855df7d32f96ee64d2..bd99fb05241810f064a23fdfe7198f084576344d 100644 (file)
@@ -1,2 +1 @@
 *.g.cs
-generator.exe
diff --git a/mcs/class/corlib/CommonCrypto/CommonCryptorGenerator.cs b/mcs/class/corlib/CommonCrypto/CommonCryptorGenerator.cs
deleted file mode 100644 (file)
index f177c17..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-//
-// CommonCrypto code generator for symmetric block cipher algorithms
-//
-// Authors:
-//     Sebastien Pouliot  <sebastien@xamarin.com>
-//
-// Copyright 2012 Xamarin Inc.
-//
-
-using System;
-using System.IO;
-
-namespace Xamarin {
-
-       public static class CommonCryptor {
-               
-               static public void Generate (string namespaceName, string typeName, string baseTypeName, string ccAlgorithmName, string feedbackSize = "8", string ctorInitializers = null)
-               {
-                       string template = @"// Generated file to bind CommonCrypto cipher algorithms - DO NOT EDIT
-//
-// Authors:
-//     Sebastien Pouliot  <sebastien@xamarin.com>
-//
-// Copyright 2012-2014 Xamarin Inc.
-
-using System;
-using System.Security.Cryptography;
-
-using Mono.Security.Cryptography;
-using Crimson.CommonCrypto;
-
-namespace %NAMESPACE% {
-
-       public sealed partial class %TYPE% : %BASE% {
-               
-               public %TYPE% ()
-               {
-                       FeedbackSizeValue = %FEEDBACKSIZE%;
-                       %CTOR_INIT%
-               }
-               
-               public override void GenerateIV ()
-               {
-                       IVValue = KeyBuilder.IV (BlockSizeValue >> 3);
-               }
-               
-               public override void GenerateKey ()
-               {
-                       KeyValue = KeyBuilder.Key (KeySizeValue >> 3);
-               }
-               
-               public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV) 
-               {
-                       IntPtr decryptor = IntPtr.Zero;
-                       switch (Mode) {
-                       case CipherMode.CBC:
-                               decryptor = Cryptor.Create (CCOperation.Decrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.None, rgbKey, rgbIV);
-                               return new FastCryptorTransform (decryptor, this, false, rgbIV);
-                       case CipherMode.ECB:
-                               decryptor = Cryptor.Create (CCOperation.Decrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
-                               return new FastCryptorTransform (decryptor, this, false, rgbIV);
-                       case CipherMode.CFB:
-#if MONOTOUCH || XAMMAC
-                               IntPtr encryptor = Cryptor.Create (CCOperation.Encrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
-                               decryptor = Cryptor.Create (CCOperation.Decrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
-                               return new CryptorTransform (decryptor, encryptor, this, false, rgbIV);
-#else
-                               throw new CryptographicException (""CFB is not supported by Crimson.CommonCrypto"");
-#endif
-                       default:
-                               throw new CryptographicException (String.Format (""{0} is not supported by the .NET framework"", Mode));
-                       }
-               }
-               
-               public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV) 
-               {
-                       IntPtr encryptor = IntPtr.Zero;
-                       switch (Mode) {
-                       case CipherMode.CBC:
-                               encryptor = Cryptor.Create (CCOperation.Encrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.None, rgbKey, rgbIV);
-                               return new FastCryptorTransform (encryptor, this, true, rgbIV);
-                       case CipherMode.ECB:
-                               encryptor = Cryptor.Create (CCOperation.Encrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
-                               return new FastCryptorTransform (encryptor, this, true, rgbIV);
-                       case CipherMode.CFB:
-#if MONOTOUCH || XAMMAC
-                               encryptor = Cryptor.Create (CCOperation.Encrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
-                               return new CryptorTransform (encryptor, IntPtr.Zero, this, true, rgbIV);
-#else
-                               throw new CryptographicException (""CFB is not supported by Crimson.CommonCrypto"");
-#endif
-                       default:
-                               throw new CryptographicException (String.Format (""{0} is not supported by the .NET framework"", Mode));
-                       }
-               }
-       }
-}";
-                       
-                       File.WriteAllText (typeName + ".g.cs", template.Replace ("%NAMESPACE%", namespaceName).
-                               Replace ("%TYPE%", typeName).Replace ("%BASE%", baseTypeName).Replace("%FEEDBACKSIZE%", feedbackSize).Replace ("%CTOR_INIT%", ctorInitializers).
-                               Replace ("%CCALGORITHM%", ccAlgorithmName.ToString ()));
-               }
-       }
-}
diff --git a/mcs/class/corlib/CommonCrypto/CommonDigestGenerator.cs b/mcs/class/corlib/CommonCrypto/CommonDigestGenerator.cs
deleted file mode 100644 (file)
index 1b729e3..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-//
-// CommonCrypto code generator for digest algorithms
-//
-// Authors:
-//     Sebastien Pouliot  <sebastien@xamarin.com>
-//
-// Copyright 2012-2014 Xamarin Inc.
-//
-
-using System;
-using System.IO;
-
-namespace Xamarin {
-
-       public static class CommonDigest {
-               
-#if !MONOTOUCH && !XAMMAC
-               // we do not add anything in MonoTouch, just replacing, so this is not needed
-               // however we can avoid a dependency on Mono.Security for Crimson.CommonCrypto.dll by including the base classes
-               static public void GenerateBaseClass (string namespaceName, string typeName, string baseTypeName, int hashSize,
-                       string visibilityStart = "", string visibilityEnd = "")
-               {
-                       string template = @"// Generated file to bind CommonCrypto/CommonDigest - DO NOT EDIT
-//
-// Authors:
-//     Sebastien Pouliot  <sebastien@xamarin.com>
-//
-// Copyright 2012-2014 Xamarin Inc.
-
-using System;
-using System.Security.Cryptography;
-using System.Runtime.InteropServices;
-
-namespace %NAMESPACE% {
-
-%VISIBILITY_START%
-       public
-%VISIBILITY_END%
-       abstract class %BASE% : HashAlgorithm {
-
-               protected %BASE% () 
-               {
-                       HashSizeValue = %HASHSIZE%; 
-               }
-
-               public static new %BASE% Create ()
-               {
-                       return Create (""%BASE%"");
-               }
-
-               public static new %BASE% Create (string hashName)
-               {
-                       object o = CryptoConfig.CreateFromName (hashName);
-                       return (%BASE%) o ?? new %TYPE% ();
-               }
-       }
-}";
-                       
-                       File.WriteAllText (baseTypeName + ".g.cs", template.Replace ("%NAMESPACE%", namespaceName).
-                               Replace ("%TYPE%", typeName).Replace ("%BASE%", baseTypeName).
-                               Replace ("%VISIBILITY_START%", visibilityStart).Replace ("%VISIBILITY_END%", visibilityEnd).
-                               Replace ("%HASHSIZE%", hashSize.ToString ()));
-               }
-#endif
-               static public void Generate (string namespaceName, string typeName, string baseTypeName, int contextSize,
-                       string visibilityStart = "", string visibilityEnd = "")
-               {
-                       string template = @"// Generated file to bind CommonCrypto/CommonDigest - DO NOT EDIT
-//
-// Authors:
-//     Sebastien Pouliot  <sebastien@xamarin.com>
-//
-// Copyright 2011-2014 Xamarin Inc.
-
-using System;
-using System.Security.Cryptography;
-using System.Runtime.InteropServices;
-
-using Mono.Security.Cryptography;
-
-namespace %NAMESPACE% {
-
-%VISIBILITY_START%
-       public
-%VISIBILITY_END%
-       sealed class %TYPE% : %BASE% {
-
-               IntPtr ctx;
-
-               [DllImport (""/usr/lib/libSystem.dylib"", EntryPoint=""CC_%BASE%_Init"")]
-               static extern int Init (/* CC_%BASE%_CTX */ IntPtr c);
-
-               [DllImport (""/usr/lib/libSystem.dylib"", EntryPoint=""CC_%BASE%_Update"")]
-               static extern int Update (/* CC_%BASE%_CTX */ IntPtr c, /* const void * */ IntPtr data, /* uint32_t */ uint len);
-
-               [DllImport (""/usr/lib/libSystem.dylib"", EntryPoint=""CC_%BASE%_Final"")]
-               static extern int Final (/* unsigned char * */ byte [] md, /* CC_%BASE%_CTX */ IntPtr c);
-
-               public %TYPE% ()
-               {
-                       ctx = IntPtr.Zero;
-               }
-
-               ~%TYPE% ()
-               {
-                       Dispose (false);
-               }
-
-               protected override void Dispose (bool disposing)
-               {
-                       if (ctx != IntPtr.Zero) {
-                               Marshal.FreeHGlobal (ctx);
-                               ctx = IntPtr.Zero;
-                       }
-                       base.Dispose (disposing);
-                       GC.SuppressFinalize (this);
-               }
-
-               public override void Initialize ()
-               {
-                       if (ctx == IntPtr.Zero)
-                               ctx = Marshal.AllocHGlobal (%CTX_SIZE%);
-                       
-                       int hr = Init (ctx);
-                       if (hr != 1)
-                               throw new CryptographicException (hr);
-               }
-
-               protected override void HashCore (byte[] data, int start, int length) 
-               {
-                       if (ctx == IntPtr.Zero)
-                               Initialize ();
-
-                       if (data.Length == 0)
-                               return;
-
-                       unsafe {
-                               fixed (byte* p = &data [0]) {
-                                       int hr = Update (ctx, (IntPtr) (p + start), (uint) length);
-                                       if (hr != 1)
-                                               throw new CryptographicException (hr);
-                               }
-                       }
-               }
-
-               protected override byte[] HashFinal () 
-               {
-                       if (ctx == IntPtr.Zero)
-                               Initialize ();
-                       
-                       byte[] data = new byte [HashSize >> 3];
-                       int hr = Final (data, ctx);
-                       if (hr != 1)
-                               throw new CryptographicException (hr);
-
-                       return data;
-               }
-       }
-}";
-                       
-                       File.WriteAllText (typeName + ".g.cs", template.Replace ("%NAMESPACE%", namespaceName).
-                               Replace ("%TYPE%", typeName).Replace ("%BASE%", baseTypeName).
-                               Replace ("%VISIBILITY_START%", visibilityStart).Replace ("%VISIBILITY_END%", visibilityEnd).
-                               Replace ("%CTX_SIZE%", contextSize.ToString ()));
-               }
-       }
-}
diff --git a/mcs/class/corlib/CommonCrypto/Makefile b/mcs/class/corlib/CommonCrypto/Makefile
new file mode 100644 (file)
index 0000000..36ea8d3
--- /dev/null
@@ -0,0 +1,8 @@
+thisdir = class/corlib/CommonCrypto
+SUBDIRS =
+include ../../../build/rules.make
+
+.NOTPARALLEL:
+all:
+       MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/commoncryptogenerator.exe
+
diff --git a/mcs/class/corlib/CommonCrypto/Makefile.include b/mcs/class/corlib/CommonCrypto/Makefile.include
deleted file mode 100644 (file)
index 25e1379..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-CommonCrypto/%.g.cs: CommonCrypto/generator.exe
-       cd CommonCrypto && mono --debug generator.exe
-
-CommonCrypto/generator.exe: CommonCrypto/generator.cs CommonCrypto/CommonDigestGenerator.cs CommonCrypto/CommonCryptorGenerator.cs
-       mcs CommonCrypto/generator.cs CommonCrypto/CommonDigestGenerator.cs CommonCrypto/CommonCryptorGenerator.cs -o $@
diff --git a/mcs/class/corlib/CommonCrypto/generator.cs b/mcs/class/corlib/CommonCrypto/generator.cs
deleted file mode 100644 (file)
index a7d13c8..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-//
-// CommonCrypto Code Generator
-//
-// Authors:
-//     Sebastien Pouliot  <sebastien@xamarin.com>
-//
-// Copyright 2012 Xamarin Inc.
-//
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-
-namespace Xamarin {
-       
-       class Program {
-               static void Main (string [] args)
-               {
-                       // mscorlib replacements
-                       CommonDigest.Generate ("System.Security.Cryptography", "MD5CryptoServiceProvider", "MD5", 1000);
-                       CommonDigest.Generate ("System.Security.Cryptography", "SHA1CryptoServiceProvider", "SHA1", 1000);
-                       CommonDigest.Generate ("System.Security.Cryptography", "SHA1Managed", "SHA1", 1000);
-                       CommonDigest.Generate ("System.Security.Cryptography", "SHA256Managed", "SHA256", 1000);
-                       CommonDigest.Generate ("System.Security.Cryptography", "SHA384Managed", "SHA384", 1000);
-                       CommonDigest.Generate ("System.Security.Cryptography", "SHA512Managed", "SHA512", 1000);
-                       
-                       // System.Core replacements - not yet in MT profile (4.0 - functional dupes anyway)
-                       //CommonDigest.Generate ("System.Security.Cryptography", "MD5Cng", "MD5", 1000);
-                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA256Cng", "SHA256", 1000);
-                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA384Cng", "SHA384", 1000);
-                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA512Cng", "SHA512", 1000);
-                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA256CryptoServiceProvider", "SHA256", 1000);
-                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA384CryptoServiceProvider", "SHA384", 1000);
-                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA512CryptoServiceProvider", "SHA512", 1000);
-                       
-                       // Mono.Security replacements
-                       CommonDigest.Generate ("Mono.Security.Cryptography", "MD2Managed", "MD2", 1000, "#if !INSIDE_CORLIB", "#endif");
-                       CommonDigest.Generate ("Mono.Security.Cryptography", "MD4Managed", "MD4", 1000, "#if !INSIDE_CORLIB", "#endif");
-                       CommonDigest.Generate ("Mono.Security.Cryptography", "SHA224Managed", "SHA224", 1000);
-
-                       // mscorlib replacements
-                       CommonCryptor.Generate ("System.Security.Cryptography", "DESCryptoServiceProvider", "DES", "DES");
-                       CommonCryptor.Generate ("System.Security.Cryptography", "TripleDESCryptoServiceProvider", "TripleDES", "TripleDES");
-                       CommonCryptor.Generate ("System.Security.Cryptography", "RC2CryptoServiceProvider", "RC2", "RC2", ctorInitializers: "LegalKeySizesValue = new[] { new KeySizes(40, 128, 8) };");
-                       // Rijndael supports block sizes that are not available in AES - as such it does not use the same generated code
-                       // but has it's own version, using AES (128 bits block size) and falling back to managed (192/256 bits block size)
-
-                       // System.Core replacements
-                       CommonCryptor.Generate ("System.Security.Cryptography", "AesManaged", "Aes", "AES128", "128");
-                       CommonCryptor.Generate ("System.Security.Cryptography", "AesCryptoServiceProvider", "Aes", "AES128");
-
-                       // Mono.Security replacements
-                       // RC4 is a stream (not a block) cipher so it can not reuse the generated code
-               }
-       }
-}
\ No newline at end of file
index 95b3bc8d33703c3e3ba1bee382763bebd35f5267..4d3f433161c2ae157c301168ba5410aa66921350 100644 (file)
@@ -1,7 +1,6 @@
 thisdir = class/corlib
 SUBDIRS =
 include ../../build/rules.make
-include CommonCrypto/Makefile.include
 export __SECURITY_BOOTSTRAP_DB=$(topdir)/class/corlib
 
 LIBRARY = corlib.dll
@@ -71,6 +70,30 @@ endif
 TEST_MCS_FLAGS += -debug -nowarn:168,219,618,672 -unsafe \
                                 -define:MONO_DATACONVERTER_STATIC_METHODS $(TEST_RESX_RESOURCES:%=-resource:%)
 
+
+CC_PROFILE := $(filter monotouch% xammac, $(PROFILE))
+ifdef CC_PROFILE
+
+BUILT_SOURCES = \
+       CommonCrypto/AesCryptoServiceProvider.g.cs \
+       CommonCrypto/MD5CryptoServiceProvider.g.cs      \
+       CommonCrypto/SHA256Managed.g.cs \
+       CommonCrypto/AesManaged.g.cs \
+       CommonCrypto/RC2CryptoServiceProvider.g.cs \
+       CommonCrypto/SHA384Managed.g.cs \
+       CommonCrypto/DESCryptoServiceProvider.g.cs \
+       CommonCrypto/SHA1CryptoServiceProvider.g.cs     \
+       CommonCrypto/SHA512Managed.g.cs \
+       CommonCrypto/MD2Managed.g.cs \
+       CommonCrypto/SHA1Managed.g.cs \
+       CommonCrypto/TripleDESCryptoServiceProvider.g.cs \
+       CommonCrypto/MD4Managed.g.cs
+
+CommonCrypto/%.g.cs:
+       $(MAKE) -C CommonCrypto
+
+endif
+
 EXTRA_DISTFILES = \
        Test/resources/MyResources.resources    \
        Test/resources/MyResources.de.resources \
index e802a034dd64f2aa7f7a9a97dd76b0aaf3ed4294..6acc765c090d0c5e18bf7673c56328dbb30053a8 100644 (file)
@@ -3,21 +3,9 @@ CommonCrypto/CommonCrypto.cs
 CommonCrypto/CryptorTransform.cs
 CommonCrypto/FastCryptorTransform.cs
 CommonCrypto/CorlibExtras.cs
-CommonCrypto/MD5CryptoServiceProvider.g.cs
-CommonCrypto/SHA1CryptoServiceProvider.g.cs
-CommonCrypto/SHA1CryptoServiceProvider.g.cs
-CommonCrypto/SHA1Managed.g.cs
-CommonCrypto/SHA256Managed.g.cs
-CommonCrypto/SHA384Managed.g.cs
-CommonCrypto/SHA512Managed.g.cs
-CommonCrypto/TripleDESCryptoServiceProvider.g.cs
-CommonCrypto/DESCryptoServiceProvider.g.cs
-CommonCrypto/RC2CryptoServiceProvider.g.cs
 CommonCrypto/RijndaelManaged.cs
 CommonCrypto/SecRandom.cs
 CommonCrypto/RC4CommonCrypto.cs
-CommonCrypto/MD2Managed.g.cs
-CommonCrypto/MD4Managed.g.cs
 System/Environment.iOS.cs
 System/Guid.MonoTouch.cs
 System/NotSupportedException.iOS.cs
index e802a034dd64f2aa7f7a9a97dd76b0aaf3ed4294..6acc765c090d0c5e18bf7673c56328dbb30053a8 100644 (file)
@@ -3,21 +3,9 @@ CommonCrypto/CommonCrypto.cs
 CommonCrypto/CryptorTransform.cs
 CommonCrypto/FastCryptorTransform.cs
 CommonCrypto/CorlibExtras.cs
-CommonCrypto/MD5CryptoServiceProvider.g.cs
-CommonCrypto/SHA1CryptoServiceProvider.g.cs
-CommonCrypto/SHA1CryptoServiceProvider.g.cs
-CommonCrypto/SHA1Managed.g.cs
-CommonCrypto/SHA256Managed.g.cs
-CommonCrypto/SHA384Managed.g.cs
-CommonCrypto/SHA512Managed.g.cs
-CommonCrypto/TripleDESCryptoServiceProvider.g.cs
-CommonCrypto/DESCryptoServiceProvider.g.cs
-CommonCrypto/RC2CryptoServiceProvider.g.cs
 CommonCrypto/RijndaelManaged.cs
 CommonCrypto/SecRandom.cs
 CommonCrypto/RC4CommonCrypto.cs
-CommonCrypto/MD2Managed.g.cs
-CommonCrypto/MD4Managed.g.cs
 System/Environment.iOS.cs
 System/Guid.MonoTouch.cs
 System/NotSupportedException.iOS.cs
index e802a034dd64f2aa7f7a9a97dd76b0aaf3ed4294..6acc765c090d0c5e18bf7673c56328dbb30053a8 100644 (file)
@@ -3,21 +3,9 @@ CommonCrypto/CommonCrypto.cs
 CommonCrypto/CryptorTransform.cs
 CommonCrypto/FastCryptorTransform.cs
 CommonCrypto/CorlibExtras.cs
-CommonCrypto/MD5CryptoServiceProvider.g.cs
-CommonCrypto/SHA1CryptoServiceProvider.g.cs
-CommonCrypto/SHA1CryptoServiceProvider.g.cs
-CommonCrypto/SHA1Managed.g.cs
-CommonCrypto/SHA256Managed.g.cs
-CommonCrypto/SHA384Managed.g.cs
-CommonCrypto/SHA512Managed.g.cs
-CommonCrypto/TripleDESCryptoServiceProvider.g.cs
-CommonCrypto/DESCryptoServiceProvider.g.cs
-CommonCrypto/RC2CryptoServiceProvider.g.cs
 CommonCrypto/RijndaelManaged.cs
 CommonCrypto/SecRandom.cs
 CommonCrypto/RC4CommonCrypto.cs
-CommonCrypto/MD2Managed.g.cs
-CommonCrypto/MD4Managed.g.cs
 System/Environment.iOS.cs
 System/Guid.MonoTouch.cs
 System/NotSupportedException.iOS.cs
index 0dbb5163c7042ef38fd2f08e6f1fc01a3611dd6f..f321e0bc800fc1f1ecca58a541972df1fe8b7d29 100644 (file)
@@ -3,20 +3,8 @@ CommonCrypto/CommonCrypto.cs
 CommonCrypto/CryptorTransform.cs
 CommonCrypto/FastCryptorTransform.cs
 CommonCrypto/CorlibExtras.cs
-CommonCrypto/MD5CryptoServiceProvider.g.cs
-CommonCrypto/SHA1CryptoServiceProvider.g.cs
-CommonCrypto/SHA1CryptoServiceProvider.g.cs
-CommonCrypto/SHA1Managed.g.cs
-CommonCrypto/SHA256Managed.g.cs
-CommonCrypto/SHA384Managed.g.cs
-CommonCrypto/SHA512Managed.g.cs
-CommonCrypto/TripleDESCryptoServiceProvider.g.cs
-CommonCrypto/DESCryptoServiceProvider.g.cs
-CommonCrypto/RC2CryptoServiceProvider.g.cs
 CommonCrypto/RijndaelManaged.cs
 CommonCrypto/RC4CommonCrypto.cs
-CommonCrypto/MD2Managed.g.cs
-CommonCrypto/MD4Managed.g.cs
 CoreFoundation/CFHelpers.cs
 System.Security.Cryptography.X509Certificates/X509CertificateImplApple.cs
 System.Security.Cryptography.X509Certificates/X509Helper.Apple.cs
index d95558b30831328d0943d51f4ca56f88f894aad7..693318cbea7e07fdb27df8413379a15d159e7ac0 100644 (file)
@@ -49,7 +49,7 @@ net_4_5_dirs := \
        mono-symbolicate        \
        linker-analyzer
 
-build_SUBDIRS = gacutil security culevel cil-stringreplacer
+build_SUBDIRS = gacutil security culevel cil-stringreplacer commoncryptogenerator
 net_4_5_SUBDIRS = gacutil
 net_4_5_PARALLEL_SUBDIRS = $(net_4_5_dirs)
 
diff --git a/mcs/tools/commoncryptogenerator/CommonCryptorGenerator.cs b/mcs/tools/commoncryptogenerator/CommonCryptorGenerator.cs
new file mode 100644 (file)
index 0000000..f177c17
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// CommonCrypto code generator for symmetric block cipher algorithms
+//
+// Authors:
+//     Sebastien Pouliot  <sebastien@xamarin.com>
+//
+// Copyright 2012 Xamarin Inc.
+//
+
+using System;
+using System.IO;
+
+namespace Xamarin {
+
+       public static class CommonCryptor {
+               
+               static public void Generate (string namespaceName, string typeName, string baseTypeName, string ccAlgorithmName, string feedbackSize = "8", string ctorInitializers = null)
+               {
+                       string template = @"// Generated file to bind CommonCrypto cipher algorithms - DO NOT EDIT
+//
+// Authors:
+//     Sebastien Pouliot  <sebastien@xamarin.com>
+//
+// Copyright 2012-2014 Xamarin Inc.
+
+using System;
+using System.Security.Cryptography;
+
+using Mono.Security.Cryptography;
+using Crimson.CommonCrypto;
+
+namespace %NAMESPACE% {
+
+       public sealed partial class %TYPE% : %BASE% {
+               
+               public %TYPE% ()
+               {
+                       FeedbackSizeValue = %FEEDBACKSIZE%;
+                       %CTOR_INIT%
+               }
+               
+               public override void GenerateIV ()
+               {
+                       IVValue = KeyBuilder.IV (BlockSizeValue >> 3);
+               }
+               
+               public override void GenerateKey ()
+               {
+                       KeyValue = KeyBuilder.Key (KeySizeValue >> 3);
+               }
+               
+               public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV) 
+               {
+                       IntPtr decryptor = IntPtr.Zero;
+                       switch (Mode) {
+                       case CipherMode.CBC:
+                               decryptor = Cryptor.Create (CCOperation.Decrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.None, rgbKey, rgbIV);
+                               return new FastCryptorTransform (decryptor, this, false, rgbIV);
+                       case CipherMode.ECB:
+                               decryptor = Cryptor.Create (CCOperation.Decrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
+                               return new FastCryptorTransform (decryptor, this, false, rgbIV);
+                       case CipherMode.CFB:
+#if MONOTOUCH || XAMMAC
+                               IntPtr encryptor = Cryptor.Create (CCOperation.Encrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
+                               decryptor = Cryptor.Create (CCOperation.Decrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
+                               return new CryptorTransform (decryptor, encryptor, this, false, rgbIV);
+#else
+                               throw new CryptographicException (""CFB is not supported by Crimson.CommonCrypto"");
+#endif
+                       default:
+                               throw new CryptographicException (String.Format (""{0} is not supported by the .NET framework"", Mode));
+                       }
+               }
+               
+               public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV) 
+               {
+                       IntPtr encryptor = IntPtr.Zero;
+                       switch (Mode) {
+                       case CipherMode.CBC:
+                               encryptor = Cryptor.Create (CCOperation.Encrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.None, rgbKey, rgbIV);
+                               return new FastCryptorTransform (encryptor, this, true, rgbIV);
+                       case CipherMode.ECB:
+                               encryptor = Cryptor.Create (CCOperation.Encrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
+                               return new FastCryptorTransform (encryptor, this, true, rgbIV);
+                       case CipherMode.CFB:
+#if MONOTOUCH || XAMMAC
+                               encryptor = Cryptor.Create (CCOperation.Encrypt, CCAlgorithm.%CCALGORITHM%, CCOptions.ECBMode, rgbKey, rgbIV);
+                               return new CryptorTransform (encryptor, IntPtr.Zero, this, true, rgbIV);
+#else
+                               throw new CryptographicException (""CFB is not supported by Crimson.CommonCrypto"");
+#endif
+                       default:
+                               throw new CryptographicException (String.Format (""{0} is not supported by the .NET framework"", Mode));
+                       }
+               }
+       }
+}";
+                       
+                       File.WriteAllText (typeName + ".g.cs", template.Replace ("%NAMESPACE%", namespaceName).
+                               Replace ("%TYPE%", typeName).Replace ("%BASE%", baseTypeName).Replace("%FEEDBACKSIZE%", feedbackSize).Replace ("%CTOR_INIT%", ctorInitializers).
+                               Replace ("%CCALGORITHM%", ccAlgorithmName.ToString ()));
+               }
+       }
+}
diff --git a/mcs/tools/commoncryptogenerator/CommonDigestGenerator.cs b/mcs/tools/commoncryptogenerator/CommonDigestGenerator.cs
new file mode 100644 (file)
index 0000000..1b729e3
--- /dev/null
@@ -0,0 +1,167 @@
+//
+// CommonCrypto code generator for digest algorithms
+//
+// Authors:
+//     Sebastien Pouliot  <sebastien@xamarin.com>
+//
+// Copyright 2012-2014 Xamarin Inc.
+//
+
+using System;
+using System.IO;
+
+namespace Xamarin {
+
+       public static class CommonDigest {
+               
+#if !MONOTOUCH && !XAMMAC
+               // we do not add anything in MonoTouch, just replacing, so this is not needed
+               // however we can avoid a dependency on Mono.Security for Crimson.CommonCrypto.dll by including the base classes
+               static public void GenerateBaseClass (string namespaceName, string typeName, string baseTypeName, int hashSize,
+                       string visibilityStart = "", string visibilityEnd = "")
+               {
+                       string template = @"// Generated file to bind CommonCrypto/CommonDigest - DO NOT EDIT
+//
+// Authors:
+//     Sebastien Pouliot  <sebastien@xamarin.com>
+//
+// Copyright 2012-2014 Xamarin Inc.
+
+using System;
+using System.Security.Cryptography;
+using System.Runtime.InteropServices;
+
+namespace %NAMESPACE% {
+
+%VISIBILITY_START%
+       public
+%VISIBILITY_END%
+       abstract class %BASE% : HashAlgorithm {
+
+               protected %BASE% () 
+               {
+                       HashSizeValue = %HASHSIZE%; 
+               }
+
+               public static new %BASE% Create ()
+               {
+                       return Create (""%BASE%"");
+               }
+
+               public static new %BASE% Create (string hashName)
+               {
+                       object o = CryptoConfig.CreateFromName (hashName);
+                       return (%BASE%) o ?? new %TYPE% ();
+               }
+       }
+}";
+                       
+                       File.WriteAllText (baseTypeName + ".g.cs", template.Replace ("%NAMESPACE%", namespaceName).
+                               Replace ("%TYPE%", typeName).Replace ("%BASE%", baseTypeName).
+                               Replace ("%VISIBILITY_START%", visibilityStart).Replace ("%VISIBILITY_END%", visibilityEnd).
+                               Replace ("%HASHSIZE%", hashSize.ToString ()));
+               }
+#endif
+               static public void Generate (string namespaceName, string typeName, string baseTypeName, int contextSize,
+                       string visibilityStart = "", string visibilityEnd = "")
+               {
+                       string template = @"// Generated file to bind CommonCrypto/CommonDigest - DO NOT EDIT
+//
+// Authors:
+//     Sebastien Pouliot  <sebastien@xamarin.com>
+//
+// Copyright 2011-2014 Xamarin Inc.
+
+using System;
+using System.Security.Cryptography;
+using System.Runtime.InteropServices;
+
+using Mono.Security.Cryptography;
+
+namespace %NAMESPACE% {
+
+%VISIBILITY_START%
+       public
+%VISIBILITY_END%
+       sealed class %TYPE% : %BASE% {
+
+               IntPtr ctx;
+
+               [DllImport (""/usr/lib/libSystem.dylib"", EntryPoint=""CC_%BASE%_Init"")]
+               static extern int Init (/* CC_%BASE%_CTX */ IntPtr c);
+
+               [DllImport (""/usr/lib/libSystem.dylib"", EntryPoint=""CC_%BASE%_Update"")]
+               static extern int Update (/* CC_%BASE%_CTX */ IntPtr c, /* const void * */ IntPtr data, /* uint32_t */ uint len);
+
+               [DllImport (""/usr/lib/libSystem.dylib"", EntryPoint=""CC_%BASE%_Final"")]
+               static extern int Final (/* unsigned char * */ byte [] md, /* CC_%BASE%_CTX */ IntPtr c);
+
+               public %TYPE% ()
+               {
+                       ctx = IntPtr.Zero;
+               }
+
+               ~%TYPE% ()
+               {
+                       Dispose (false);
+               }
+
+               protected override void Dispose (bool disposing)
+               {
+                       if (ctx != IntPtr.Zero) {
+                               Marshal.FreeHGlobal (ctx);
+                               ctx = IntPtr.Zero;
+                       }
+                       base.Dispose (disposing);
+                       GC.SuppressFinalize (this);
+               }
+
+               public override void Initialize ()
+               {
+                       if (ctx == IntPtr.Zero)
+                               ctx = Marshal.AllocHGlobal (%CTX_SIZE%);
+                       
+                       int hr = Init (ctx);
+                       if (hr != 1)
+                               throw new CryptographicException (hr);
+               }
+
+               protected override void HashCore (byte[] data, int start, int length) 
+               {
+                       if (ctx == IntPtr.Zero)
+                               Initialize ();
+
+                       if (data.Length == 0)
+                               return;
+
+                       unsafe {
+                               fixed (byte* p = &data [0]) {
+                                       int hr = Update (ctx, (IntPtr) (p + start), (uint) length);
+                                       if (hr != 1)
+                                               throw new CryptographicException (hr);
+                               }
+                       }
+               }
+
+               protected override byte[] HashFinal () 
+               {
+                       if (ctx == IntPtr.Zero)
+                               Initialize ();
+                       
+                       byte[] data = new byte [HashSize >> 3];
+                       int hr = Final (data, ctx);
+                       if (hr != 1)
+                               throw new CryptographicException (hr);
+
+                       return data;
+               }
+       }
+}";
+                       
+                       File.WriteAllText (typeName + ".g.cs", template.Replace ("%NAMESPACE%", namespaceName).
+                               Replace ("%TYPE%", typeName).Replace ("%BASE%", baseTypeName).
+                               Replace ("%VISIBILITY_START%", visibilityStart).Replace ("%VISIBILITY_END%", visibilityEnd).
+                               Replace ("%CTX_SIZE%", contextSize.ToString ()));
+               }
+       }
+}
diff --git a/mcs/tools/commoncryptogenerator/Makefile b/mcs/tools/commoncryptogenerator/Makefile
new file mode 100644 (file)
index 0000000..64c52e4
--- /dev/null
@@ -0,0 +1,11 @@
+thisdir = tools/commoncryptogenerator
+SUBDIRS =
+include ../../build/rules.make
+
+LIB_REFS = 
+LOCAL_MCS_FLAGS =
+
+PROGRAM = commoncryptogenerator.exe
+NO_INSTALL = yes
+
+include ../../build/executable.make
diff --git a/mcs/tools/commoncryptogenerator/commoncryptogenerator.exe.sources b/mcs/tools/commoncryptogenerator/commoncryptogenerator.exe.sources
new file mode 100644 (file)
index 0000000..e2ecba4
--- /dev/null
@@ -0,0 +1,3 @@
+CommonCryptorGenerator.cs
+generator.cs
+CommonDigestGenerator.cs
diff --git a/mcs/tools/commoncryptogenerator/generator.cs b/mcs/tools/commoncryptogenerator/generator.cs
new file mode 100644 (file)
index 0000000..a7d13c8
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// CommonCrypto Code Generator
+//
+// Authors:
+//     Sebastien Pouliot  <sebastien@xamarin.com>
+//
+// Copyright 2012 Xamarin Inc.
+//
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+namespace Xamarin {
+       
+       class Program {
+               static void Main (string [] args)
+               {
+                       // mscorlib replacements
+                       CommonDigest.Generate ("System.Security.Cryptography", "MD5CryptoServiceProvider", "MD5", 1000);
+                       CommonDigest.Generate ("System.Security.Cryptography", "SHA1CryptoServiceProvider", "SHA1", 1000);
+                       CommonDigest.Generate ("System.Security.Cryptography", "SHA1Managed", "SHA1", 1000);
+                       CommonDigest.Generate ("System.Security.Cryptography", "SHA256Managed", "SHA256", 1000);
+                       CommonDigest.Generate ("System.Security.Cryptography", "SHA384Managed", "SHA384", 1000);
+                       CommonDigest.Generate ("System.Security.Cryptography", "SHA512Managed", "SHA512", 1000);
+                       
+                       // System.Core replacements - not yet in MT profile (4.0 - functional dupes anyway)
+                       //CommonDigest.Generate ("System.Security.Cryptography", "MD5Cng", "MD5", 1000);
+                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA256Cng", "SHA256", 1000);
+                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA384Cng", "SHA384", 1000);
+                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA512Cng", "SHA512", 1000);
+                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA256CryptoServiceProvider", "SHA256", 1000);
+                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA384CryptoServiceProvider", "SHA384", 1000);
+                       //CommonDigest.Generate ("System.Security.Cryptography", "SHA512CryptoServiceProvider", "SHA512", 1000);
+                       
+                       // Mono.Security replacements
+                       CommonDigest.Generate ("Mono.Security.Cryptography", "MD2Managed", "MD2", 1000, "#if !INSIDE_CORLIB", "#endif");
+                       CommonDigest.Generate ("Mono.Security.Cryptography", "MD4Managed", "MD4", 1000, "#if !INSIDE_CORLIB", "#endif");
+                       CommonDigest.Generate ("Mono.Security.Cryptography", "SHA224Managed", "SHA224", 1000);
+
+                       // mscorlib replacements
+                       CommonCryptor.Generate ("System.Security.Cryptography", "DESCryptoServiceProvider", "DES", "DES");
+                       CommonCryptor.Generate ("System.Security.Cryptography", "TripleDESCryptoServiceProvider", "TripleDES", "TripleDES");
+                       CommonCryptor.Generate ("System.Security.Cryptography", "RC2CryptoServiceProvider", "RC2", "RC2", ctorInitializers: "LegalKeySizesValue = new[] { new KeySizes(40, 128, 8) };");
+                       // Rijndael supports block sizes that are not available in AES - as such it does not use the same generated code
+                       // but has it's own version, using AES (128 bits block size) and falling back to managed (192/256 bits block size)
+
+                       // System.Core replacements
+                       CommonCryptor.Generate ("System.Security.Cryptography", "AesManaged", "Aes", "AES128", "128");
+                       CommonCryptor.Generate ("System.Security.Cryptography", "AesCryptoServiceProvider", "Aes", "AES128");
+
+                       // Mono.Security replacements
+                       // RC4 is a stream (not a block) cipher so it can not reuse the generated code
+               }
+       }
+}
\ No newline at end of file