Jump to content

SHA256 Hash Algorithm


Recommended Posts

Greetings, all!

This is pretty self-explanatory. I need a LabVIEW implementation of the SHA256 hash algorithm. I could do it myself, but I was hoping one already exists. Has anyone written such a beast?

Thanks!

Link to post
Share on other sites

I've never made anything like this in LabVIEW but there are several commonly used DLLs which give you this function.

Searching Hashes.dll in google came up with several places to get a DLL that calculates a whole bunch of hashes.

MD2

MD4

MD5

SHA1

SHA256

SHA384

SHA512

HAVAL128

HAVAL160

HAVAL192

HAVAL224

HAVAL256

GHOST

TIGER128

TIGER160

TIGER192

RIPE-MD128

RIPE-MD160

CRC32

CRC16

ARC-CRC

I don't have any VI that uses this DLL but I don't think it should be too hard to get the functionality you want.

Link to post
Share on other sites
  • 9 years later...
On 7/15/2010 at 7:31 PM, MikaelH said:

I tried it through .net and it works.

post-941-005122700 1279247370_thumb.png

I had to browse for the mscorlib.dll file for LabVIEW to find the SHA256Managed-class.

Cheers,

Mikael

Hey @MikaelH. I can't seem to be able to create this on my system. Can you post a VI or a snippet of the above code? Thanks and wishing you well.

Link to post
Share on other sites

There is no need to go through external code for this. There have been many attempts at crypto libraries that are written natively in LabVIEW and they didn't fail because it is impossible but because nobody is interested to spend some time in searching for them or what a bad word, fork a few dollars over for them. That way authors have put out libraries in the past only to have them forgotten by the public and that is the most sure way for any maintenance work and improvement to be discouraged.

Probably the first one was Enrico Vargas who wrote a pretty versatile Crypto library all in LabVIEW somewhere around 2000. It contained many hash and even symmetric algorithmes that were pretty well tested and he was an expert in that subject. And yes he charged something for that library which I found reasonable, I bought a license too and collaborated with him a little on some algorithmes and testing of them. I doubt he made much money with it though, as most Toolkit providers. Eventually it died of because he pursuaded other carrier options and maybe also partly because providing support for something that many were asking for but very few were willing to pay for is a frustrating exercise.

A little googling delivers following solutions currently available:

https://github.com/gb119/LabVIEW-Bits/tree/master/Cryptographic Services/SHA256

https://lvs-tools.co.uk/software/encryption-compendium-labview-library/

https://gpackage.io/packages/@mgi/hash

Interesting disclaimer in the last link! 😀

I would say whoever understands the implications of this, is already aware of the limits in using such functions, but whoever isn't won't be bothered by it. There are several aspects to this, such that calling the same function in .Net or WinAPI (also a possibility) is not necessarily more safe as the actual string is still possibly somewhere in LabVIEW memory after the function is called, no matter how diligent the external library is about clearing any buffer it uses.

Also many hashes are mostly used for hashing known sources. which does not have the problem that the original string or byte stream needs to stay secret at all as it is already in memory anyways elsewhere. So for such applications the use of these functions in LabVIEW would not cause any extra concerns about lingering memory buffers that might contain "the secret" after the function has finished.

Edited by Rolf Kalbermatter
  • Like 1
Link to post
Share on other sites

For the first of those, you'd want the LV2018 branch. Jim K recently brpught some infelicities in the code to my attention - which of cousre becomes an incentive to fix things (thus proving Rolf's point!). I'm still having an issue with files> 2Gb - there's something I don't understand when dealing with 64bit files (on 64bit Windows and 64bit Labview). Not helped by the fact that testing is slooooooow.

Link to post
Share on other sites
  • 3 months later...
On 4/4/2020 at 11:15 AM, gb119 said:

For the first of those, you'd want the LV2018 branch. Jim K recently brpught some infelicities in the code to my attention - which of cousre becomes an incentive to fix things (thus proving Rolf's point!). I'm still having an issue with files> 2Gb - there's something I don't understand when dealing with 64bit files (on 64bit Windows and 64bit Labview). Not helped by the fact that testing is slooooooow.

@gb119 I am trying to use your HMAC - SHA256 to generate a token to allow me access to an Azure Iot hub. I have a snippet of c# code that works fine and I am trying to translate into LabVIEW but not having much luck.

I don't really understand the HMAC stuff properly. Are all SHA256 HMAC implementations the same?

 

image.png.e8dc9b89def8e2c5717ef9e5dcf34350.png

image.png.10803d7db9ed25a107907881b9abd859.png

The LabVIEW code above is mostly correct, the decoding of the URI is not quite the same but I manually change this to match the c# code.

I have verified that stringToSign is identical in both implementations, so something is happening after this. The string coming out of the HMA SHA256 is completely different to the c# code which does not look like a Base64 string at all.

image.png.b2dc9e23f4730a99bd6ff4882cfbebe0.png

My knowledge of this kinda stuff is not good so I am probably missing something super obvious.

Any tips?

ps: apologies for resurrecting this old thread, I should certainly have started a new one.

Edited by Neil Pate
Link to post
Share on other sites
34 minutes ago, Neil Pate said:

I am trying to use your HMAC - SHA256 to generate a token to allow me access to an Azure Iot hub. I have a snippet of c# code that works fine and I am trying to translate into LabVIEW but not having much luck.

I remember having to figure this out when generating tokens for the LabVIEW Cloud Toolkit for Azure. I remember that there was some weird stuff I had to figure out, but I've long since forgotten how I did it. On the bright side, the toolkit is open source, you can browse through the source code here to see how I did it.

  • Like 2
Link to post
Share on other sites
29 minutes ago, Darren said:

I remember having to figure this out when generating tokens for the LabVIEW Cloud Toolkit for Azure. I remember that there was some weird stuff I had to figure out, but I've long since forgotten how I did it. On the bright side, the toolkit is open source, you can browse through the source code here to see how I did it.

Ah excellent, thanks!

Link to post
Share on other sites
  • 1 month later...

"Available in LabVIEW 2020 and later: the TLS functions are available in the Functions > Data Communication > Protocols > TCP > Transport Layer Security (TLS) palette."

I'm posting here in case someone comes along like myself after stepping into a deep "let's secure this" hole and needs ideas or hasn't seen this yet.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.