Re: Help with SHA class
Re: Help with SHA class
- Subject: Re: Help with SHA class
- From: Greg Guerin <email@hidden>
- Date: Thu, 4 Jun 2009 10:35:02 -0700
I wrote a SHA class using the algorithm at http://en.wikipedia.org/
wiki/SHA1#SHA-1_pseudocode and while it runs without crashing, the
hashes it produces are not the same as those from numerous online
SHA-1 hashing converters. Of particular confusion is the issue of
byte swapping and how that might affect the rotation/addition
operations within the block hashing method. I'm clearly doing
something wrong, but after several days of trying, I haven't been
able to get the hashes to match online examples.
Why are you writing this algorithm?
Googling these keywords:
sha1 public domain
shows numerous hits. Since "public domain" means "no license", I
don't see why you'd want to reinvent this wheel, especially given the
known weaknesses of SHA1.
If you're writing it in order to learn about hash algorithms, then I
think it makes more sense for you to debug your code yourself, as
unhelpful as that may seem to be. I also suggest reading sources
other than Wikipedia, not necessarily because Wikipedia might be
wrong or have a typo, but because there might be more detailed step-
by-step explanations elsewhere on the web. Or look at the public
domain ones and see how they differ from yours.
You might also try running your code on a machine that's actually big-
endian, to see what happens. Unless you already are.
Iff you're running it on an Intel CPU, simply compile the code for
ppc and use the 'arch' command to run that slice instead of the
native slice. If it doesn't produce the same output, then you have
an implied-endian bug. If it does produce the same output, you still
have a bug.
If you're using an Intel CPU, maybe try finding a little-endian
implementation of the algorithm.
BTW, your code should probably be using the type names UInt32 and
UInt64, instead of making assumptions about sizes. There are also
places where you use the constant 4 instead of sizeof(UInt32).
Though these may not affect this implementation, they seem
questionable to me.
-- GG
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden