Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jb@evain.net>2014-11-13 20:17:40 +0300
committerJb Evain <jbevain@gmail.com>2015-05-28 12:14:01 +0300
commit4e3b95b140c4777eb315b411b7fd1fba6b5268d4 (patch)
treef712c92cf0b3b80535de44a4265bad2f00b4f2e7
parent8177a546ba10c34f40d35c78f4930ea506a83541 (diff)
Compiling version of PCL
-rw-r--r--Mono.Cecil.Cil/Symbols.cs2
-rw-r--r--Mono.Cecil.csproj1
-rw-r--r--Mono.Cecil.settings2
-rw-r--r--Mono.Cecil.sln5
-rw-r--r--Mono.Cecil/AssemblyDefinition.cs2
-rw-r--r--Mono.Cecil/AssemblyNameReference.cs4
-rw-r--r--Mono.Cecil/AssemblyReader.cs8
-rw-r--r--Mono.Cecil/BaseAssemblyResolver.cs4
-rw-r--r--Mono.Cecil/DefaultAssemblyResolver.cs4
-rw-r--r--Mono.Cecil/Import.cs4
-rw-r--r--Mono.Cecil/ModuleDefinition.cs16
-rw-r--r--Mono.Security.Cryptography/CryptoService.cs4
-rw-r--r--System.Security.Cryptography/SHA1Managed.cs373
13 files changed, 424 insertions, 5 deletions
diff --git a/Mono.Cecil.Cil/Symbols.cs b/Mono.Cecil.Cil/Symbols.cs
index ac685d8..aed7650 100644
--- a/Mono.Cecil.Cil/Symbols.cs
+++ b/Mono.Cecil.Cil/Symbols.cs
@@ -159,6 +159,7 @@ namespace Mono.Cecil.Cil {
ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream);
}
+#if !PCL
static class SymbolProvider {
static readonly string symbol_kind = Type.GetType ("Mono.Runtime") != null ? "Mdb" : "Pdb";
@@ -239,6 +240,7 @@ namespace Mono.Cecil.Cil {
#endif
}
+#endif
#if !READ_ONLY
diff --git a/Mono.Cecil.csproj b/Mono.Cecil.csproj
index 662f15b..f296271 100644
--- a/Mono.Cecil.csproj
+++ b/Mono.Cecil.csproj
@@ -137,6 +137,7 @@
<Compile Include="Mono\Actions.cs" />
<Compile Include="Mono\Empty.cs" />
<Compile Include="Mono\Funcs.cs" />
+ <Compile Include="System.Security.Cryptography\SHA1Managed.cs" />
</ItemGroup>
<Import Project="Mono.Cecil.settings" />
<Import Project="$(MSBuildCSharpTargets)" />
diff --git a/Mono.Cecil.settings b/Mono.Cecil.settings
index 924b14c..3a52248 100644
--- a/Mono.Cecil.settings
+++ b/Mono.Cecil.settings
@@ -66,7 +66,7 @@
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile158</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <DefineConstants>$(DefineConstants);NET_3_5;NET_4_0;SILVERLIGHT;PCL</DefineConstants>
+ <DefineConstants>$(DefineConstants);NET_3_5;NET_4_0;SILVERLIGHT;PCL;READ_ONLY;</DefineConstants>
<MSBuildCSharpTargets>$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets</MSBuildCSharpTargets>
</PropertyGroup>
<!-- Shared References -->
diff --git a/Mono.Cecil.sln b/Mono.Cecil.sln
index bdc8c87..58014e9 100644
--- a/Mono.Cecil.sln
+++ b/Mono.Cecil.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
-VisualStudioVersion = 12.0.30723.0
+VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{74E5ECE0-06B4-401C-AEBA-E8DD53E17943}"
EndProject
@@ -107,7 +107,6 @@ Global
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_4_5_Release|Any CPU.ActiveCfg = net_4_5_Release|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_4_5_Release|Any CPU.Build.0 = net_4_5_Release|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.pcl_Debug|Any CPU.ActiveCfg = pcl_Debug|Any CPU
- {8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.pcl_Debug|Any CPU.Build.0 = pcl_Debug|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.pcl_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.pcl_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
@@ -153,7 +152,6 @@ Global
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_4_5_Release|Any CPU.ActiveCfg = net_4_5_Release|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_4_5_Release|Any CPU.Build.0 = net_4_5_Release|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.pcl_Debug|Any CPU.ActiveCfg = pcl_Debug|Any CPU
- {63E6915C-7EA4-4D76-AB28-0D7191EEA626}.pcl_Debug|Any CPU.Build.0 = pcl_Debug|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.pcl_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.pcl_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
@@ -217,7 +215,6 @@ Global
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_4_5_Release|Any CPU.ActiveCfg = net_4_5_Release|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_4_5_Release|Any CPU.Build.0 = net_4_5_Release|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.pcl_Debug|Any CPU.ActiveCfg = pcl_Debug|Any CPU
- {FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.pcl_Debug|Any CPU.Build.0 = pcl_Debug|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.pcl_Release|Any CPU.ActiveCfg = pcl_Release|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.pcl_Release|Any CPU.Build.0 = pcl_Release|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.silverlight_Debug|Any CPU.ActiveCfg = silverlight_Debug|Any CPU
diff --git a/Mono.Cecil/AssemblyDefinition.cs b/Mono.Cecil/AssemblyDefinition.cs
index de6ed17..b472d81 100644
--- a/Mono.Cecil/AssemblyDefinition.cs
+++ b/Mono.Cecil/AssemblyDefinition.cs
@@ -112,6 +112,7 @@ namespace Mono.Cecil {
}
#endif
+#if !PCL
public static AssemblyDefinition ReadAssembly (string fileName)
{
return ReadAssembly (ModuleDefinition.ReadModule (fileName));
@@ -121,6 +122,7 @@ namespace Mono.Cecil {
{
return ReadAssembly (ModuleDefinition.ReadModule (fileName, parameters));
}
+#endif
public static AssemblyDefinition ReadAssembly (Stream stream)
{
diff --git a/Mono.Cecil/AssemblyNameReference.cs b/Mono.Cecil/AssemblyNameReference.cs
index 9cacef1..52bcbb4 100644
--- a/Mono.Cecil/AssemblyNameReference.cs
+++ b/Mono.Cecil/AssemblyNameReference.cs
@@ -109,6 +109,7 @@ namespace Mono.Cecil {
byte [] HashPublicKey ()
{
+#if !PCL
HashAlgorithm algorithm;
switch (hash_algorithm) {
@@ -132,6 +133,9 @@ namespace Mono.Cecil {
using (algorithm)
return algorithm.ComputeHash (public_key);
+#else
+ return new SHA1Managed ().ComputeHash (public_key);
+#endif
}
public virtual MetadataScopeType MetadataScopeType {
diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs
index ee667cb..cf7d768 100644
--- a/Mono.Cecil/AssemblyReader.cs
+++ b/Mono.Cecil/AssemblyReader.cs
@@ -89,8 +89,10 @@ namespace Mono.Cecil {
{
var symbol_reader_provider = parameters.SymbolReaderProvider;
+#if !PCL
if (symbol_reader_provider == null && parameters.ReadSymbols)
symbol_reader_provider = SymbolProvider.GetPlatformReaderProvider ();
+#endif
if (symbol_reader_provider != null) {
module.SymbolReaderProvider = symbol_reader_provider;
@@ -551,6 +553,7 @@ namespace Mono.Cecil {
if (attributes != FileAttributes.ContainsMetaData)
continue;
+#if !PCL
var parameters = new ReaderParameters {
ReadingMode = module.ReadingMode,
SymbolReaderProvider = module.SymbolReaderProvider,
@@ -559,11 +562,15 @@ namespace Mono.Cecil {
modules.Add (ModuleDefinition.ReadModule (
GetModuleFileName (name), parameters));
+#else
+ throw new NotSupportedException ();
+#endif
}
return modules;
}
+#if !PCL
string GetModuleFileName (string name)
{
if (module.FullyQualifiedName == null)
@@ -572,6 +579,7 @@ namespace Mono.Cecil {
var path = Path.GetDirectoryName (module.FullyQualifiedName);
return Path.Combine (path, name);
}
+#endif
void InitializeModuleReferences ()
{
diff --git a/Mono.Cecil/BaseAssemblyResolver.cs b/Mono.Cecil/BaseAssemblyResolver.cs
index 76f5da1..691c28b 100644
--- a/Mono.Cecil/BaseAssemblyResolver.cs
+++ b/Mono.Cecil/BaseAssemblyResolver.cs
@@ -8,6 +8,8 @@
// Licensed under the MIT/X11 license.
//
+#if !PCL
+
using System;
using System.Collections.Generic;
using System.IO;
@@ -350,3 +352,5 @@ namespace Mono.Cecil {
#endif
}
}
+
+#endif
diff --git a/Mono.Cecil/DefaultAssemblyResolver.cs b/Mono.Cecil/DefaultAssemblyResolver.cs
index a21405b..aa4e278 100644
--- a/Mono.Cecil/DefaultAssemblyResolver.cs
+++ b/Mono.Cecil/DefaultAssemblyResolver.cs
@@ -8,6 +8,8 @@
// Licensed under the MIT/X11 license.
//
+#if !PCL
+
using System;
using System.Collections.Generic;
@@ -50,3 +52,5 @@ namespace Mono.Cecil {
}
}
}
+
+#endif
diff --git a/Mono.Cecil/Import.cs b/Mono.Cecil/Import.cs
index 8a3345a..2e2f230 100644
--- a/Mono.Cecil/Import.cs
+++ b/Mono.Cecil/Import.cs
@@ -8,6 +8,8 @@
// Licensed under the MIT/X11 license.
//
+#if !READ_ONLY
+
using System;
using System.Collections.Generic;
using Mono.Collections.Generic;
@@ -773,3 +775,5 @@ namespace Mono.Cecil {
#endif
}
+
+#endif
diff --git a/Mono.Cecil/ModuleDefinition.cs b/Mono.Cecil/ModuleDefinition.cs
index 134dd99..fac634e 100644
--- a/Mono.Cecil/ModuleDefinition.cs
+++ b/Mono.Cecil/ModuleDefinition.cs
@@ -343,8 +343,10 @@ namespace Mono.Cecil {
public IAssemblyResolver AssemblyResolver {
get {
+#if !PCL
if (assembly_resolver == null)
Interlocked.CompareExchange (ref assembly_resolver, new DefaultAssemblyResolver (), null);
+#endif
return assembly_resolver;
}
@@ -649,16 +651,28 @@ namespace Mono.Cecil {
internal FieldDefinition Resolve (FieldReference field)
{
+#if PCL
+ if (MetadataResolver == null)
+ throw new NotSupportedException ();
+#endif
return MetadataResolver.Resolve (field);
}
internal MethodDefinition Resolve (MethodReference method)
{
+#if PCL
+ if (MetadataResolver == null)
+ throw new NotSupportedException ();
+#endif
return MetadataResolver.Resolve (method);
}
internal TypeDefinition Resolve (TypeReference type)
{
+#if PCL
+ if (MetadataResolver == null)
+ throw new NotSupportedException ();
+#endif
return MetadataResolver.Resolve (type);
}
@@ -972,6 +986,7 @@ namespace Mono.Cecil {
#endif
+#if !PCL
public void ReadSymbols ()
{
if (string.IsNullOrEmpty (fq_name))
@@ -983,6 +998,7 @@ namespace Mono.Cecil {
ReadSymbols (provider.GetSymbolReader (this, fq_name));
}
+#endif
public void ReadSymbols (ISymbolReader reader)
{
diff --git a/Mono.Security.Cryptography/CryptoService.cs b/Mono.Security.Cryptography/CryptoService.cs
index 6f28623..5cb7e0e 100644
--- a/Mono.Security.Cryptography/CryptoService.cs
+++ b/Mono.Security.Cryptography/CryptoService.cs
@@ -104,6 +104,7 @@ namespace Mono.Cecil {
public static byte [] ComputeHash (string file)
{
+#if !PCL
if (!File.Exists (file))
return Empty<byte>.Array;
@@ -120,6 +121,9 @@ namespace Mono.Cecil {
}
return sha1.Hash;
+#else
+ return Empty<byte>.Array;
+#endif
}
}
diff --git a/System.Security.Cryptography/SHA1Managed.cs b/System.Security.Cryptography/SHA1Managed.cs
new file mode 100644
index 0000000..a162278
--- /dev/null
+++ b/System.Security.Cryptography/SHA1Managed.cs
@@ -0,0 +1,373 @@
+//
+// System.Security.Cryptography.SHA1CryptoServiceProvider.cs
+//
+// Authors:
+// Matthew S. Ford (Matthew.S.Ford@Rose-Hulman.Edu)
+// Sebastien Pouliot (sebastien@ximian.com)
+//
+// Copyright 2001 by Matthew S. Ford.
+// Copyright (C) 2004, 2005, 2008 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.
+//
+
+// Note:
+// The MS Framework includes two (almost) identical class for SHA1.
+// SHA1Managed is a 100% managed implementation.
+// SHA1CryptoServiceProvider (this file) is a wrapper on CryptoAPI.
+// Mono must provide those two class for binary compatibility.
+// In our case both class are wrappers around a managed internal class SHA1Internal.
+
+#if PCL
+
+namespace System.Security.Cryptography {
+
+ internal class SHA1Internal {
+
+ private const int BLOCK_SIZE_BYTES = 64;
+ private uint[] _H; // these are my chaining variables
+ private ulong count;
+ private byte[] _ProcessingBuffer; // Used to start data when passed less than a block worth.
+ private int _ProcessingBufferCount; // Counts how much data we have stored that still needs processed.
+ private uint[] buff;
+
+ public SHA1Internal ()
+ {
+ _H = new uint[5];
+ _ProcessingBuffer = new byte[BLOCK_SIZE_BYTES];
+ buff = new uint[80];
+
+ Initialize();
+ }
+
+ public void HashCore (byte[] rgb, int ibStart, int cbSize)
+ {
+ int i;
+
+ if (_ProcessingBufferCount != 0) {
+ if (cbSize < (BLOCK_SIZE_BYTES - _ProcessingBufferCount)) {
+ System.Buffer.BlockCopy (rgb, ibStart, _ProcessingBuffer, _ProcessingBufferCount, cbSize);
+ _ProcessingBufferCount += cbSize;
+ return;
+ }
+ else {
+ i = (BLOCK_SIZE_BYTES - _ProcessingBufferCount);
+ System.Buffer.BlockCopy (rgb, ibStart, _ProcessingBuffer, _ProcessingBufferCount, i);
+ ProcessBlock (_ProcessingBuffer, 0);
+ _ProcessingBufferCount = 0;
+ ibStart += i;
+ cbSize -= i;
+ }
+ }
+
+ for (i = 0; i < cbSize - cbSize % BLOCK_SIZE_BYTES; i += BLOCK_SIZE_BYTES) {
+ ProcessBlock (rgb, (uint)(ibStart + i));
+ }
+
+ if (cbSize % BLOCK_SIZE_BYTES != 0) {
+ System.Buffer.BlockCopy (rgb, cbSize - cbSize % BLOCK_SIZE_BYTES + ibStart, _ProcessingBuffer, 0, cbSize % BLOCK_SIZE_BYTES);
+ _ProcessingBufferCount = cbSize % BLOCK_SIZE_BYTES;
+ }
+ }
+
+ public byte[] HashFinal ()
+ {
+ byte[] hash = new byte[20];
+
+ ProcessFinalBlock (_ProcessingBuffer, 0, _ProcessingBufferCount);
+
+ for (int i=0; i<5; i++) {
+ for (int j=0; j<4; j++) {
+ hash [i*4+j] = (byte)(_H[i] >> (8*(3-j)));
+ }
+ }
+
+ return hash;
+ }
+
+ public void Initialize ()
+ {
+ count = 0;
+ _ProcessingBufferCount = 0;
+
+ _H[0] = 0x67452301;
+ _H[1] = 0xefcdab89;
+ _H[2] = 0x98badcfe;
+ _H[3] = 0x10325476;
+ _H[4] = 0xC3D2E1F0;
+ }
+
+ private void ProcessBlock(byte[] inputBuffer, uint inputOffset)
+ {
+ uint a, b, c, d, e;
+
+ count += BLOCK_SIZE_BYTES;
+
+ // abc removal would not work on the fields
+ uint[] _H = this._H;
+ uint[] buff = this.buff;
+ InitialiseBuff(buff, inputBuffer, inputOffset);
+ FillBuff(buff);
+
+ a = _H[0];
+ b = _H[1];
+ c = _H[2];
+ d = _H[3];
+ e = _H[4];
+
+ // This function was unrolled because it seems to be doubling our performance with current compiler/VM.
+ // Possibly roll up if this changes.
+
+ // ---- Round 1 --------
+ int i=0;
+ while (i < 20)
+ {
+ e += ((a << 5) | (a >> 27)) + (((c ^ d) & b) ^ d) + 0x5A827999 + buff[i];
+ b = (b << 30) | (b >> 2);
+
+ d += ((e << 5) | (e >> 27)) + (((b ^ c) & a) ^ c) + 0x5A827999 + buff[i+1];
+ a = (a << 30) | (a >> 2);
+
+ c += ((d << 5) | (d >> 27)) + (((a ^ b) & e) ^ b) + 0x5A827999 + buff[i+2];
+ e = (e << 30) | (e >> 2);
+
+ b += ((c << 5) | (c >> 27)) + (((e ^ a) & d) ^ a) + 0x5A827999 + buff[i+3];
+ d = (d << 30) | (d >> 2);
+
+ a += ((b << 5) | (b >> 27)) + (((d ^ e) & c) ^ e) + 0x5A827999 + buff[i+4];
+ c = (c << 30) | (c >> 2);
+ i += 5;
+ }
+
+ // ---- Round 2 --------
+ while (i < 40)
+ {
+ e += ((a << 5) | (a >> 27)) + (b ^ c ^ d) + 0x6ED9EBA1 + buff[i];
+ b = (b << 30) | (b >> 2);
+
+ d += ((e << 5) | (e >> 27)) + (a ^ b ^ c) + 0x6ED9EBA1 + buff[i + 1];
+ a = (a << 30) | (a >> 2);
+
+ c += ((d << 5) | (d >> 27)) + (e ^ a ^ b) + 0x6ED9EBA1 + buff[i + 2];
+ e = (e << 30) | (e >> 2);
+
+ b += ((c << 5) | (c >> 27)) + (d ^ e ^ a) + 0x6ED9EBA1 + buff[i + 3];
+ d = (d << 30) | (d >> 2);
+
+ a += ((b << 5) | (b >> 27)) + (c ^ d ^ e) + 0x6ED9EBA1 + buff[i + 4];
+ c = (c << 30) | (c >> 2);
+ i += 5;
+ }
+
+ // ---- Round 3 --------
+ while (i < 60)
+ {
+ e += ((a << 5) | (a >> 27)) + ((b & c) | (b & d) | (c & d)) + 0x8F1BBCDC + buff[i];
+ b = (b << 30) | (b >> 2);
+
+ d += ((e << 5) | (e >> 27)) + ((a & b) | (a & c) | (b & c)) + 0x8F1BBCDC + buff[i + 1];
+ a = (a << 30) | (a >> 2);
+
+ c += ((d << 5) | (d >> 27)) + ((e & a) | (e & b) | (a & b)) + 0x8F1BBCDC + buff[i + 2];
+ e = (e << 30) | (e >> 2);
+
+ b += ((c << 5) | (c >> 27)) + ((d & e) | (d & a) | (e & a)) + 0x8F1BBCDC + buff[i + 3];
+ d = (d << 30) | (d >> 2);
+
+ a += ((b << 5) | (b >> 27)) + ((c & d) | (c & e) | (d & e)) + 0x8F1BBCDC + buff[i + 4];
+ c = (c << 30) | (c >> 2);
+ i += 5;
+ }
+
+ // ---- Round 4 --------
+ while (i < 80)
+ {
+ e += ((a << 5) | (a >> 27)) + (b ^ c ^ d) + 0xCA62C1D6 + buff[i];
+ b = (b << 30) | (b >> 2);
+
+ d += ((e << 5) | (e >> 27)) + (a ^ b ^ c) + 0xCA62C1D6 + buff[i + 1];
+ a = (a << 30) | (a >> 2);
+
+ c += ((d << 5) | (d >> 27)) + (e ^ a ^ b) + 0xCA62C1D6 + buff[i + 2];
+ e = (e << 30) | (e >> 2);
+
+ b += ((c << 5) | (c >> 27)) + (d ^ e ^ a) + 0xCA62C1D6 + buff[i + 3];
+ d = (d << 30) | (d >> 2);
+
+ a += ((b << 5) | (b >> 27)) + (c ^ d ^ e) + 0xCA62C1D6 + buff[i + 4];
+ c = (c << 30) | (c >> 2);
+ i += 5;
+ }
+
+ _H[0] += a;
+ _H[1] += b;
+ _H[2] += c;
+ _H[3] += d;
+ _H[4] += e;
+ }
+
+ private static void InitialiseBuff(uint[] buff, byte[] input, uint inputOffset)
+ {
+ buff[0] = (uint)((input[inputOffset + 0] << 24) | (input[inputOffset + 1] << 16) | (input[inputOffset + 2] << 8) | (input[inputOffset + 3]));
+ buff[1] = (uint)((input[inputOffset + 4] << 24) | (input[inputOffset + 5] << 16) | (input[inputOffset + 6] << 8) | (input[inputOffset + 7]));
+ buff[2] = (uint)((input[inputOffset + 8] << 24) | (input[inputOffset + 9] << 16) | (input[inputOffset + 10] << 8) | (input[inputOffset + 11]));
+ buff[3] = (uint)((input[inputOffset + 12] << 24) | (input[inputOffset + 13] << 16) | (input[inputOffset + 14] << 8) | (input[inputOffset + 15]));
+ buff[4] = (uint)((input[inputOffset + 16] << 24) | (input[inputOffset + 17] << 16) | (input[inputOffset + 18] << 8) | (input[inputOffset + 19]));
+ buff[5] = (uint)((input[inputOffset + 20] << 24) | (input[inputOffset + 21] << 16) | (input[inputOffset + 22] << 8) | (input[inputOffset + 23]));
+ buff[6] = (uint)((input[inputOffset + 24] << 24) | (input[inputOffset + 25] << 16) | (input[inputOffset + 26] << 8) | (input[inputOffset + 27]));
+ buff[7] = (uint)((input[inputOffset + 28] << 24) | (input[inputOffset + 29] << 16) | (input[inputOffset + 30] << 8) | (input[inputOffset + 31]));
+ buff[8] = (uint)((input[inputOffset + 32] << 24) | (input[inputOffset + 33] << 16) | (input[inputOffset + 34] << 8) | (input[inputOffset + 35]));
+ buff[9] = (uint)((input[inputOffset + 36] << 24) | (input[inputOffset + 37] << 16) | (input[inputOffset + 38] << 8) | (input[inputOffset + 39]));
+ buff[10] = (uint)((input[inputOffset + 40] << 24) | (input[inputOffset + 41] << 16) | (input[inputOffset + 42] << 8) | (input[inputOffset + 43]));
+ buff[11] = (uint)((input[inputOffset + 44] << 24) | (input[inputOffset + 45] << 16) | (input[inputOffset + 46] << 8) | (input[inputOffset + 47]));
+ buff[12] = (uint)((input[inputOffset + 48] << 24) | (input[inputOffset + 49] << 16) | (input[inputOffset + 50] << 8) | (input[inputOffset + 51]));
+ buff[13] = (uint)((input[inputOffset + 52] << 24) | (input[inputOffset + 53] << 16) | (input[inputOffset + 54] << 8) | (input[inputOffset + 55]));
+ buff[14] = (uint)((input[inputOffset + 56] << 24) | (input[inputOffset + 57] << 16) | (input[inputOffset + 58] << 8) | (input[inputOffset + 59]));
+ buff[15] = (uint)((input[inputOffset + 60] << 24) | (input[inputOffset + 61] << 16) | (input[inputOffset + 62] << 8) | (input[inputOffset + 63]));
+ }
+
+ private static void FillBuff(uint[] buff)
+ {
+ uint val;
+ for (int i = 16; i < 80; i += 8)
+ {
+ val = buff[i - 3] ^ buff[i - 8] ^ buff[i - 14] ^ buff[i - 16];
+ buff[i] = (val << 1) | (val >> 31);
+
+ val = buff[i - 2] ^ buff[i - 7] ^ buff[i - 13] ^ buff[i - 15];
+ buff[i + 1] = (val << 1) | (val >> 31);
+
+ val = buff[i - 1] ^ buff[i - 6] ^ buff[i - 12] ^ buff[i - 14];
+ buff[i + 2] = (val << 1) | (val >> 31);
+
+ val = buff[i + 0] ^ buff[i - 5] ^ buff[i - 11] ^ buff[i - 13];
+ buff[i + 3] = (val << 1) | (val >> 31);
+
+ val = buff[i + 1] ^ buff[i - 4] ^ buff[i - 10] ^ buff[i - 12];
+ buff[i + 4] = (val << 1) | (val >> 31);
+
+ val = buff[i + 2] ^ buff[i - 3] ^ buff[i - 9] ^ buff[i - 11];
+ buff[i + 5] = (val << 1) | (val >> 31);
+
+ val = buff[i + 3] ^ buff[i - 2] ^ buff[i - 8] ^ buff[i - 10];
+ buff[i + 6] = (val << 1) | (val >> 31);
+
+ val = buff[i + 4] ^ buff[i - 1] ^ buff[i - 7] ^ buff[i - 9];
+ buff[i + 7] = (val << 1) | (val >> 31);
+ }
+ }
+
+ private void ProcessFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
+ {
+ ulong total = count + (ulong)inputCount;
+ int paddingSize = (56 - (int)(total % BLOCK_SIZE_BYTES));
+
+ if (paddingSize < 1)
+ paddingSize += BLOCK_SIZE_BYTES;
+
+ int length = inputCount+paddingSize+8;
+ byte[] fooBuffer = (length == 64) ? _ProcessingBuffer : new byte[length];
+
+ for (int i=0; i<inputCount; i++) {
+ fooBuffer[i] = inputBuffer[i+inputOffset];
+ }
+
+ fooBuffer[inputCount] = 0x80;
+ for (int i=inputCount+1; i<inputCount+paddingSize; i++) {
+ fooBuffer[i] = 0x00;
+ }
+
+ // I deal in bytes. The algorithm deals in bits.
+ ulong size = total << 3;
+ AddLength (size, fooBuffer, inputCount+paddingSize);
+ ProcessBlock (fooBuffer, 0);
+
+ if (length == 128)
+ ProcessBlock (fooBuffer, 64);
+ }
+
+ internal void AddLength (ulong length, byte[] buffer, int position)
+ {
+ buffer [position++] = (byte)(length >> 56);
+ buffer [position++] = (byte)(length >> 48);
+ buffer [position++] = (byte)(length >> 40);
+ buffer [position++] = (byte)(length >> 32);
+ buffer [position++] = (byte)(length >> 24);
+ buffer [position++] = (byte)(length >> 16);
+ buffer [position++] = (byte)(length >> 8);
+ buffer [position] = (byte)(length);
+ }
+ }
+
+ class SHA1Managed {
+
+ private SHA1Internal sha;
+
+ public SHA1Managed ()
+ {
+ sha = new SHA1Internal ();
+ }
+
+ public byte[] ComputeHash (byte[] buffer)
+ {
+ if (buffer == null)
+ throw new ArgumentNullException ("buffer");
+
+ return ComputeHash (buffer, 0, buffer.Length);
+ }
+
+ public byte[] ComputeHash (byte[] buffer, int offset, int count)
+ {
+ if (buffer == null)
+ throw new ArgumentNullException ("buffer");
+ if (offset < 0)
+ throw new ArgumentOutOfRangeException ("offset", "< 0");
+ if (count < 0)
+ throw new ArgumentException ("count", "< 0");
+ // ordered to avoid possible integer overflow
+ if (offset > buffer.Length - count) {
+ throw new ArgumentException ("offset + count", "Overflow");
+ }
+
+ HashCore (buffer, offset, count);
+ var hash_value = HashFinal ();
+ Initialize ();
+
+ return hash_value;
+ }
+
+ protected void HashCore (byte[] rgb, int ibStart, int cbSize)
+ {
+ sha.HashCore (rgb, ibStart, cbSize);
+ }
+
+ protected byte[] HashFinal ()
+ {
+ return sha.HashFinal ();
+ }
+
+ protected void Initialize ()
+ {
+ sha.Initialize ();
+ }
+ }
+}
+
+#endif