This repository has been archived by the owner on Feb 8, 2018. 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.
* Monsoon/Monsoon.csproj: * Monsoon/OpenSSLSha1.cs: * Monsoon/TorrentController.cs: Monsoon will use openssh for sha1 hashing if it is available, otherwise fall back to the standard hash function. svn path=/trunk/monsoon/; revision=136661
- Loading branch information
1 parent
8de5ea5
commit 3f240cc
Showing
5 changed files
with
86 additions
and
2 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
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
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
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,56 @@ | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Monsoon | ||
{ | ||
public class OpenSSLSha1 : System.Security.Cryptography.SHA1 | ||
{ | ||
IntPtr context; | ||
public OpenSSLSha1 () | ||
{ | ||
// The native SHA1 structure is 96 bytes in length | ||
context = Marshal.AllocHGlobal (96); | ||
if (SHA1_Init (context) != 1) | ||
throw new Exception ("Could not init context"); | ||
} | ||
|
||
public override void Initialize () | ||
{ | ||
if (SHA1_Init (context) != 1) | ||
throw new Exception ("Could not init context"); | ||
} | ||
|
||
protected override unsafe void HashCore (byte[] array, int ibStart, int cbSize) | ||
{ | ||
if (ibStart > array.Length) | ||
throw new IndexOutOfRangeException ("ibStart"); | ||
if ((array.Length - ibStart) < cbSize) | ||
throw new IndexOutOfRangeException ("cbSize"); | ||
|
||
if (cbSize == 0) | ||
return; | ||
|
||
fixed (byte *ptr = array) | ||
if (SHA1_Update (context, ptr + ibStart, (ulong) cbSize) != 1) | ||
throw new Exception ("Could not hash data"); | ||
} | ||
|
||
protected override byte[] HashFinal () | ||
{ | ||
// Result must be at least of length 20 | ||
byte [] result = new byte [20]; | ||
if (SHA1_Final (result, context) != 1) | ||
throw new Exception ("Could not hash final chunk"); | ||
return result; | ||
} | ||
|
||
// All return '1' for success, '0' for failure | ||
[DllImport ("libssl.so.0.9.8")] | ||
static extern int SHA1_Init (IntPtr context); | ||
[DllImport ("libssl.so.0.9.8")] | ||
static extern unsafe int SHA1_Update (IntPtr context, byte *data, ulong len); | ||
[DllImport ("libssl.so.0.9.8")] | ||
static extern int SHA1_Final (byte [] buffer, IntPtr context); | ||
} | ||
} |
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