This repository has been archived by the owner on Mar 1, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
initial import
svn path=/trunk/crimson/; revision=66729
- Loading branch information
Sebastien Pouliot
committed
Oct 16, 2006
0 parents
commit a63f2fd
Showing
79 changed files
with
4,546 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Sebastien Pouliot <sebastien@ximian.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
2006-10-16 Sebastien Pouliot <sebastien@ximian.com> | ||
|
||
* AssemblyInfo.cs: Assembly identification. | ||
* ChangeLog: New. Track changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.