[Mono-bugs] [Bug 345510] CryptoStream ignores the ICryptoTransform. CanTransformMultipleBlocks property when reading
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Dec 3 11:26:06 EST 2007
https://bugzilla.novell.com/show_bug.cgi?id=345510#c2
Sebastien Pouliot <spouliot at novell.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|Normal |Enhancement
Status|ASSIGNED |NEEDINFO
Info Provider| |lordhabbit at gmail.com
--- Comment #2 from Sebastien Pouliot <spouliot at novell.com> 2007-12-03 09:26:06 MST ---
Here are my results for a 90mb file using sha1sum, HashAlgorithm.ComputeHash
and CryptoStream
poupou at pollux:~/src/bugzilla> l
~/Desktop/RX-34_2007SE_4.2007.26-8_PR_COMBINED_MR0_ARM.bin
-rw-r--r-- 1 poupou users 90298052 2007-09-07 17:43
/home/poupou/Desktop/RX-34_2007SE_4.2007.26-8_PR_COMBINED_MR0_ARM.bin
poupou at pollux:~/src/bugzilla> time sha1sum
~/Desktop/RX-34_2007SE_4.2007.26-8_PR_COMBINED_MR0_ARM.bin
8f932c938a677f9e5a67070aa3dee0c170a32f69
/home/poupou/Desktop/RX-34_2007SE_4.2007.26-8_PR_COMBINED_MR0_ARM.bin
real 0m2.314s
user 0m1.440s
sys 0m0.104s
poupou at pollux:~/src/bugzilla> time mono 345510.exe SHA1 hash
~/Desktop/RX-34_2007SE_4.2007.26-8_PR_COMBINED_MR0_ARM.bin
8F-93-2C-93-8A-67-7F-9E-5A-67-07-0A-A3-DE-E0-C1-70-A3-2F-69
real 0m3.556s
user 0m3.416s
sys 0m0.072s
poupou at pollux:~/src/bugzilla> time mono 345510.exe SHA1 cryptostream
~/Desktop/RX-34_2007SE_4.2007.26-8_PR_COMBINED_MR0_ARM.bin
8F-93-2C-93-8A-67-7F-9E-5A-67-07-0A-A3-DE-E0-C1-70-A3-2F-69
real 0m3.550s
user 0m3.444s
sys 0m0.048s
I'm actually impressed that the later is as fast as ComputeHash since it
involves extra steps. This also means that my CryptoStream code is different
than yours ;-)
Here's mine:
using System;
using System.IO;
using System.Security.Cryptography;
class Digest {
private const int Size = 4096;
static byte[] hash (HashAlgorithm algo, Stream s)
{
return algo.ComputeHash (s);
}
static byte[] cryptostream (HashAlgorithm algo, Stream s)
{
// note: it could make sense to use a BufferedStream
byte[] data = new byte[Size];
using (CryptoStream cs = new CryptoStream (Stream.Null, algo,
CryptoStreamMode.Write)) {
int size = s.Read (data, 0, Size);
while (size > 0) {
cs.Write (data, 0, size);
size = s.Read (data, 0, Size);
}
}
return algo.Hash;
}
// args: algorithm method filename
static void Main (string [] args)
{
using (FileStream fs = File.OpenRead (args [2])) {
using (HashAlgorithm algo = HashAlgorithm.Create (args
[0])) {
byte[] digest = null;
switch (args [1].ToLower ()) {
case "hash":
digest = hash (algo, fs);
break;
case "cryptostream":
digest = cryptostream (algo, fs);
break;
default:
throw new NotSupportedException (args
[1]);
}
Console.WriteLine (BitConverter.ToString
(digest));
}
}
}
}
Downgrading priority to Enhancement since the original test case _probably_
occurs only when reading byte-by-byte (which is bad for performance, crypto or
not).
Please attach your own test case so I can see where the bottleneck lies in this
particular case.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list