Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

SHA1 Hash Implementation


  • Please log in to reply
4 replies to this topic

#1 light

light

    Member

  • Members
  • PipPip
  • 13 posts

Posted 11 January 2011 - 11:29 PM

I have created a library called SHA1LIB that implements the SHA1 hash algorithm. It is an adaptation of the SHA1 code fount at c-sharpcorder.com that was posted by Mihai Popescu. The project files can be found here: http://ronlight.com/...cts/sha1lib.zip -Ron

#2 rexomale

rexomale

    New Member

  • Members
  • Pip
  • 2 posts

Posted 21 March 2013 - 12:46 AM

The link is not working. I'm looking for a Sha1 implementation for my websocket handshake. This could help me.

 

Thanks,

 

Rex



#3 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 21 March 2013 - 01:27 PM

The link is not working. I'm looking for a Sha1 implementation for my websocket handshake. This could help me.

 

Thanks,

 

Rex

 

funny, just yesterday I needed sha1 (and hmac), what I did was to extract the pertinent modules from bouncy castle (which is very well respected if you aren't already familiar).  just download the current (v1.7 as of this writing) and pluck out what you need.  Its under MIT-style license, btw, if thats important for your project.

 

OK to save you an hour rummaging for what you need, here is what I pulled out to get SHA1 and HMAC:

 

GeneralDigest.cs HMac.cs ICipherParameters.cs IDigest.cs IMac.cs KeyParameter.cs Pack.cs Sha1Digest.cs

 

you'll have to find exactly where they are in the source tree since I didn't write that down, sorry, but it's all under the 'crypto' folder in various directories.

 

Also this list has the HMAC stuff, too, which I needed,  you didn't say you needed, so you'll have to figure out which of those files to discard yourself if you want to optimise a little.  I think the group added a couple K to my overall executable.

 

BouncyCastle is not known for their C# docco, but you could use the javadocs to get an idea since it's mostly a straight port.  To give you a head start, here is my snippet testing against one of the test vectors so I could verify the implementation:

 

obviously include those files, and you'll be 'using' stuff:

using Org.BouncyCastle.Crypto.Macs;using Org.BouncyCastle.Crypto.Digests;using Org.BouncyCastle.Crypto.Parameters;

and here I am verifying against one of the rfc 2202 test vectors:

			byte[] key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 };			byte[] data = { 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 							 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 							 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 							 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 							 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd };			HMac hmac = new HMac(new Sha1Digest());			hmac.Init(new KeyParameter(key, 0, key.Length));			hmac.BlockUpdate(data, 0, data.Length);			byte[] abyDigest = new byte[hmac.GetMacSize()];			int nRet = hmac.DoFinal(abyDigest, 0);			//digest =        0x4c9007f4026250c6bc8414f9bf50c86c2d7235da

so now it's time to get cryppy with it...

 

EDIT:  oh it's customary to welcome folks on their first post, so 'welcome to the forum'!



#4 rexomale

rexomale

    New Member

  • Members
  • Pip
  • 2 posts

Posted 21 March 2013 - 04:15 PM

I downloaded bouncy castle and will try to investigate the classes you suggest.

 

I also found another SHA1 implementation https://code.google....ase/SHA.cs?r=92 and it looks like this is the one I need.

 

Thanks for the help and thanks for the warm welcome.



#5 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 21 March 2013 - 05:34 PM

oh, nice find!  I might try that one out myself....






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.