Permalink
Browse files

initial import

svn path=/trunk/crimson/; revision=66729
  • Loading branch information...
0 parents commit a63f2fd8aa3e3b5375b8a4b82a7fd48607f7119c Sebastien Pouliot committed Oct 16, 2006
Showing with 4,546 additions and 0 deletions.
  1. +6 −0 ChangeLog
  2. +21 −0 README
  3. +6 −0 class/ChangeLog
  4. +1 −0 class/Crimson.MHash/AUTHORS
  5. +38 −0 class/Crimson.MHash/Assembly/AssemblyInfo.cs
  6. +4 −0 class/Crimson.MHash/Assembly/ChangeLog
  7. +10 −0 class/Crimson.MHash/ChangeLog
  8. +54 −0 class/Crimson.MHash/Crimson.MHash.dll.sources
  9. +6 −0 class/Crimson.MHash/Crimson.MHash/ChangeLog
  10. +121 −0 class/Crimson.MHash/Crimson.MHash/MHashHelper.cs
  11. +61 −0 class/Crimson.MHash/Crimson.MHash/MHashId.cs
  12. +50 −0 class/Crimson.MHash/Crimson.MHash/MHashWrapper.cs
  13. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/ADLER32.cs
  14. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/ADLER32Native.cs
  15. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/CRC32.cs
  16. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/CRC32B.cs
  17. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/CRC32BNative.cs
  18. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/CRC32Native.cs
  19. +51 −0 class/Crimson.MHash/Crimson.Security.Cryptography/ChangeLog
  20. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/GOST.cs
  21. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/GOSTNative.cs
  22. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL128.cs
  23. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL128Native.cs
  24. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL160.cs
  25. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL160Native.cs
  26. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL192.cs
  27. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL192Native.cs
  28. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL224.cs
  29. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL224Native.cs
  30. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL256.cs
  31. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/HAVAL256Native.cs
  32. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/MD2.cs
  33. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/MD2Native.cs
  34. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/MD4.cs
  35. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/MD4Native.cs
  36. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/MD5Native.cs
  37. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/RIPEMD128.cs
  38. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/RIPEMD128Native.cs
  39. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/RIPEMD160.cs
  40. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/RIPEMD160Native.cs
  41. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/RIPEMD256.cs
  42. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/RIPEMD256Native.cs
  43. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/RIPEMD320.cs
  44. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/RIPEMD320Native.cs
  45. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SHA1Native.cs
  46. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SHA224.cs
  47. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SHA224Native.cs
  48. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SHA256Native.cs
  49. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SHA384Native.cs
  50. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SHA512Native.cs
  51. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SNEFRU128.cs
  52. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SNEFRU128Native.cs
  53. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SNEFRU256.cs
  54. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/SNEFRU256Native.cs
  55. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/TIGER128.cs
  56. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/TIGER128Native.cs
  57. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/TIGER160.cs
  58. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/TIGER160Native.cs
  59. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/TIGER192.cs
  60. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/TIGER192Native.cs
  61. +57 −0 class/Crimson.MHash/Crimson.Security.Cryptography/WHIRLPOOL.cs
  62. +84 −0 class/Crimson.MHash/Crimson.Security.Cryptography/WHIRLPOOLNative.cs
  63. +15 −0 class/Crimson.MHash/LICENSE.LGPL
  64. +21 −0 class/Crimson.MHash/MIT.X11
  65. +19 −0 class/Crimson.MHash/Makefile
  66. +28 −0 class/Crimson.MHash/README
  67. +5 −0 class/Crimson.MHash/tools/generator/ChangeLog
  68. +9 −0 class/Crimson.MHash/tools/generator/Makefile
  69. +232 −0 class/Crimson.MHash/tools/generator/generator.cs
  70. +4 −0 class/Crimson.MHash/tools/perf/ChangeLog
  71. +41 −0 class/Crimson.MHash/tools/perf/Makefile
  72. +17 −0 class/Crimson.MHash/tools/perf/README
  73. +21 −0 class/Crimson.MHash/tools/perf/bf.cs
  74. +29 −0 class/Crimson.MHash/tools/perf/managed.cs
  75. +81 −0 class/Crimson.MHash/tools/perf/native.cs
  76. +18 −0 class/README
  77. BIN class/crimson.snk
  78. +4 −0 common/ChangeLog
  79. +51 −0 common/Locale.cs
@@ -0,0 +1,6 @@
+2006-10-16 Sebastien Pouliot <sebastien@ximian.com>
+
+ * ChangeLog: New. Track project-wide changes.
+ * class/*: New. Class libraries.
+ * common/*: New. Common source for all Crimson assemblies and tools.
+ * README: New. Information about the Crimson project.
@@ -0,0 +1,21 @@
+Crimson offers a superset of the cryptographic features available in the .NET
+framework. For various reasons Crimson isn't distributed within Mono. The main
+reasons being:
+
+* Target audience
+
+ As a superset to both .NET and Mono cryptographic features, Crimson
+ is useful to everyone, not just Mono users.
+
+* Support
+
+ Crimson is not required inside Mono to reach feature parity with MS
+ implementation of the .NET framework and it's related tools. As such
+ supporting Crimson is not the goal of the Mono project.
+
+* Export restriction on cryptographic software
+
+ Laws regarding export and, sometimes import, of cryptography are
+ diverse and complex. It is difficult to add/remove algorithms and
+ keep all the required paperwork in sync. Distribution as source-only
+ makes this a lot easier.
@@ -0,0 +1,6 @@
+2006-10-16 Sebastien Pouliot <sebastien@ximian.com>
+
+ * ChangeLog: New. Track libraries-wide changes.
+ * crimson.snk: New. Strongname key for Crimson libraries;
+ * Crimson.MHash/*: New. Wrapper for libmhash;
+ * README: New. Description about the libraries;
@@ -0,0 +1 @@
+Sebastien Pouliot <sebastien@ximian.com>
@@ -0,0 +1,38 @@
+//
+// AssemblyInfo.cs
+//
+// Authors:
+// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+// Sebastien Pouliot (sebastien@ximian.com)
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+
+using System;
+using System.Reflection;
+using System.Resources;
+using System.Security;
+using System.Security.Permissions;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about the system assembly
+
+#if NET_2_0
+[assembly: AssemblyVersion ("2.0.0.0")]
+#else
+[assembly: AssemblyVersion ("1.1.0.0")]
+#endif
+
+[assembly: AssemblyCompany ("Novell and contributors")]
+[assembly: AssemblyCopyright ("(C) 2006 Novell")]
+[assembly: AssemblyDescription ("Crimson MHash Wrapper Assembly")]
+[assembly: AssemblyTitle ("Crimson.MHash.dll")]
+[assembly: CLSCompliant (true)]
+[assembly: ComVisible (false)]
+[assembly: NeutralResourcesLanguage ("en-US")]
+
+[assembly:SecurityPermission (SecurityAction.RequestMinimum, UnmanagedCode=true)]
+
+[assembly: AssemblyDelaySign (false)]
+[assembly: AssemblyKeyFile ("../crimson.snk")]
@@ -0,0 +1,4 @@
+2006-10-16 Sebastien Pouliot <sebastien@ximian.com>
+
+ * AssemblyInfo.cs: Assembly identification.
+ * ChangeLog: New. Track changes.
@@ -0,0 +1,10 @@
+2006-10-16 Sebastien Pouliot <sebastien@ximian.com>
+
+ * AUTHORS: New.
+ * ChangeLog: New. Track library changes.
+ * Crimson.MHash.dll.sources: List of source files to build the
+ assembly.
+ * LICENSE.LGPL: License of libmhash
+ * Makefile: New. Build assembly.
+ * MIT.X11: License of the wrapper code (when not used with libmhash)
+ * README: New. Information about the wrapper assembly.
@@ -0,0 +1,54 @@
+../../common/Locale.cs
+Assembly/AssemblyInfo.cs
+Crimson.MHash/MHashHelper.cs
+Crimson.MHash/MHashId.cs
+Crimson.MHash/MHashWrapper.cs
+Crimson.Security.Cryptography/ADLER32.cs
+Crimson.Security.Cryptography/ADLER32Native.cs
+Crimson.Security.Cryptography/CRC32B.cs
+Crimson.Security.Cryptography/CRC32BNative.cs
+Crimson.Security.Cryptography/CRC32.cs
+Crimson.Security.Cryptography/CRC32Native.cs
+Crimson.Security.Cryptography/GOST.cs
+Crimson.Security.Cryptography/GOSTNative.cs
+Crimson.Security.Cryptography/HAVAL128.cs
+Crimson.Security.Cryptography/HAVAL128Native.cs
+Crimson.Security.Cryptography/HAVAL160.cs
+Crimson.Security.Cryptography/HAVAL160Native.cs
+Crimson.Security.Cryptography/HAVAL192.cs
+Crimson.Security.Cryptography/HAVAL192Native.cs
+Crimson.Security.Cryptography/HAVAL224.cs
+Crimson.Security.Cryptography/HAVAL224Native.cs
+Crimson.Security.Cryptography/HAVAL256.cs
+Crimson.Security.Cryptography/HAVAL256Native.cs
+Crimson.Security.Cryptography/MD2.cs
+Crimson.Security.Cryptography/MD2Native.cs
+Crimson.Security.Cryptography/MD4.cs
+Crimson.Security.Cryptography/MD4Native.cs
+Crimson.Security.Cryptography/MD5Native.cs
+Crimson.Security.Cryptography/RIPEMD128.cs
+Crimson.Security.Cryptography/RIPEMD128Native.cs
+Crimson.Security.Cryptography/RIPEMD160.cs
+Crimson.Security.Cryptography/RIPEMD160Native.cs
+Crimson.Security.Cryptography/RIPEMD256.cs
+Crimson.Security.Cryptography/RIPEMD256Native.cs
+Crimson.Security.Cryptography/RIPEMD320.cs
+Crimson.Security.Cryptography/RIPEMD320Native.cs
+Crimson.Security.Cryptography/SHA1Native.cs
+Crimson.Security.Cryptography/SHA224.cs
+Crimson.Security.Cryptography/SHA224Native.cs
+Crimson.Security.Cryptography/SHA256Native.cs
+Crimson.Security.Cryptography/SHA384Native.cs
+Crimson.Security.Cryptography/SHA512Native.cs
+Crimson.Security.Cryptography/SNEFRU128.cs
+Crimson.Security.Cryptography/SNEFRU128Native.cs
+Crimson.Security.Cryptography/SNEFRU256.cs
+Crimson.Security.Cryptography/SNEFRU256Native.cs
+Crimson.Security.Cryptography/TIGER128.cs
+Crimson.Security.Cryptography/TIGER128Native.cs
+Crimson.Security.Cryptography/TIGER160.cs
+Crimson.Security.Cryptography/TIGER160Native.cs
+Crimson.Security.Cryptography/TIGER192.cs
+Crimson.Security.Cryptography/TIGER192Native.cs
+Crimson.Security.Cryptography/WHIRLPOOL.cs
+Crimson.Security.Cryptography/WHIRLPOOLNative.cs
@@ -0,0 +1,6 @@
+2006-10-16 Sebastien Pouliot <sebastien@ximian.com>
+
+ * MHashHelper.cs: New. Helper class used by generated code.
+ * MHashId.cs: New. Enum of all hash algorithms currently supported
+ in libmhash.
+ * MHashWrapper.cs: P/Invoke declarations to use libmhash.
@@ -0,0 +1,121 @@
+//
+// Crimson.MHash.MHashHelper class
+//
+// Authors:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Runtime.InteropServices;
+using System.Security.Cryptography;
+
+namespace Crimson.MHash {
+
+ internal class MHashHelper : IDisposable {
+
+ private MHashId type;
+ private IntPtr handle;
+ private int blocksize;
+
+ public MHashHelper (MHashId type)
+ {
+ this.type = type;
+ handle = MHashWrapper.mhash_init (type);
+ if (handle == IntPtr.Zero) {
+ string msg = String.Format ("Unknown mhash id '{0}'.", type);
+ throw new CryptographicException (msg);
+ }
+
+ blocksize = (int) MHashWrapper.mhash_get_block_size (type);
+ }
+
+ ~MHashHelper ()
+ {
+ Dispose ();
+ }
+
+ public int BlockSize {
+ get { return blocksize; }
+ }
+
+ public IntPtr Handle {
+ get { return handle; }
+ }
+
+ public void Initialize ()
+ {
+ if (handle == IntPtr.Zero)
+ GC.ReRegisterForFinalize (this);
+ handle = MHashWrapper.mhash_init (type);
+ }
+
+ public void HashCore (byte[] data, int start, int length)
+ {
+ if (data == null)
+ throw new ArgumentNullException ("data");
+ if (start < 0)
+ throw new ArgumentException ("start");
+ if (length < 0)
+ throw new ArgumentException ("length");
+
+ if (length == 0)
+ return;
+
+ // avoid copying data unless required (API limitation)
+ if (start == 0) {
+ MHashWrapper.mhash (handle, data, (IntPtr)length);
+ } else {
+ byte[] partial = new byte [length];
+ Buffer.BlockCopy (data, start, partial, 0, length);
+ MHashWrapper.mhash (handle, partial, (IntPtr)length);
+ }
+ }
+
+ public byte[] HashFinal ()
+ {
+ byte[] result = new byte [blocksize];
+ IntPtr digest = MHashWrapper.mhash_end (handle);
+ try {
+ Marshal.Copy (digest, result, 0, blocksize);
+ }
+ finally {
+ Marshal.FreeHGlobal (digest);
+ handle = IntPtr.Zero;
+ }
+ return result;
+ }
+
+ public void Dispose ()
+ {
+ if (handle != IntPtr.Zero) {
+ // this frees the hashing structure, but allocates the digest
+ IntPtr digest = MHashWrapper.mhash_end (handle);
+ // so we still have a second free to make to complete dispose
+ Marshal.FreeHGlobal (digest);
+ handle = IntPtr.Zero;
+ GC.SuppressFinalize (this);
+ }
+ }
+ }
+}
@@ -0,0 +1,61 @@
+//
+// Crimson.MHash.MHashId enumeation
+//
+// Authors:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Crimson.MHash {
+
+ internal enum MHashId {
+ Crc32 = 0,
+ Md5 = 1,
+ Sha1 = 2,
+ Haval256 = 3,
+ Ripemd160 = 5,
+ Tiger192 = 7,
+ Gost = 8,
+ Crc32b = 9,
+ Haval224 = 10,
+ Haval192 = 11,
+ Haval160 = 12,
+ Haval128 = 13,
+ Tiger128 = 14,
+ Tiger160 = 15,
+ Md4 = 16,
+ Sha256 = 17,
+ Adler32 = 18,
+ Sha224 = 19,
+ Sha512 = 20,
+ Sha384 = 21,
+ Whirlpool = 22,
+ Ripemd128 = 23,
+ Ripemd256 = 24,
+ Ripemd320 = 25,
+ Snefru128 = 26,
+ Snefru256 = 27,
+ Md2 = 28
+ // other values are defined but aren't implemented inside libmhash
+ }
+}
@@ -0,0 +1,50 @@
+//
+// Crimson.MHash.MHashWrapper wrapper for libmhash
+//
+// Authors:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Crimson.MHash {
+
+ internal class MHashWrapper {
+
+ private const string libname = "libmhash.so.2";
+
+ [DllImport (libname)]
+ internal extern static IntPtr mhash_init (MHashId type);
+
+ [DllImport (libname)]
+ internal extern static IntPtr mhash_end (IntPtr handle);
+
+ [DllImport (libname)]
+ internal extern static IntPtr mhash_get_block_size (MHashId type);
+
+ [DllImport (libname)]
+ internal extern static int mhash (IntPtr handle, byte[] plaintext, IntPtr size);
+ }
+}
Oops, something went wrong. Retry.

0 comments on commit a63f2fd

Please sign in to comment.