[Library] SHA-256

Author Topic: [Library] SHA-256  (Read 4803 times)

In light of a SHA-1 collision being found in practice, Blockland no longer has any default functions capable of providing even the slightest glimmer of cryptographic security.  So I decided to write SHA-256 in TorqueScript.

This library was written using pseudocode from the Wikipedia page on SHA-2, an addition function by Port, and test vectors for several SHA variants from DI Management.

The function in this library operates much in the same way as the default sha1 function, taking a string and returning the hash of that string in hexadecimal.  It should work on any string that does not overflow the TorqueScript string buffer, but as it is written in TorqueScript it may hang Blockland for noticeable periods of time for very long strings.

Please note that unless you are writing code where the cryptographic properties of SHA-256 are important, you should probably stick to using the default sha1 function, which is much faster than any hashing function written in TorqueScript.


Benchmark comparisons:
Running sha1("") 999999 times: 2400 ms, or ~2.4 µs per call
Running sha256("") 9999 times: 124736 ms, or ~12.5 ms per call

Cool can it decode too?

xalos your next task is to make a sha256 decoder in torque script

Cool can it decode too?
xalos your next task is to make a sha256 decoder in torque script

Why not invent time travel while he's at it?



On topic: A bunch of scripters recommend using global variables instead of local variables as they are significantly faster (Up to 1000 times if I remember correctly).

On topic: A bunch of scripters recommend using global variables instead of local variables as they are significantly faster (Up to 1000 times if I remember correctly).
can confirm. if it wasn't for this property zeblotes' new duplicator wouldnt really be possible.

Especially since a lot of those variables are never actually being changed, just initially set.

How convenient that someone made this since I very recently thought about sha1 getting phased out from https or something...anyways I'm curious to see the practical uses of cryptography in Blockland since the only time I've seen sha1 used was for a variable saving system in one of theblackparrot's gamemodes iirc that sha1'd the blid for file names.

How convenient that someone made this since I very recently thought about sha1 getting phased out from https or something...anyways I'm curious to see the practical uses of cryptography in Blockland since the only time I've seen sha1 used was for a variable saving system in one of theblackparrot's gamemodes iirc that sha1'd the blid for file names.
its essentially useless in blockland as really no addon should be serving any sort of login or cryptography stuff stuff beyond using name+ip to auth with blockland.us but this is still interesting

occasionally its nice to use sha1 to store location data as a hash but theres not really a point where its vulnerable to these kind of collision attacks

im confused. what exactly is this

i don't speak smart so the wikipedia page doesn't help either

im confused. what exactly is this

i don't speak smart so the wikipedia page doesn't help either
It's a cryptographic hash function
It takes in arbitrary input and gives out seemingly random output. But it's still deterministic (meaning the same input gives the same output), so it's reliable.
The entire point is that you can't just take the output of sha256 and reverse it back into its input, that it's hard to find two inputs that give the same output, and that it's hard to find an input that matches any given output.

xalos your next task is to make a sha256 decoder in torque script
i mean if you want your hashrate down the drain sure (shrug)

Remember that project a couple years back to add a proper encryption library to Blockland?

On topic: A bunch of scripters recommend using global variables instead of local variables as they are significantly faster (Up to 1000 times if I remember correctly).

Object variables are the problem. Local variables are faster than global and should always be used if you don't need persistence.

anyways I'm curious to see the practical uses of cryptography in Blockland

Probably none.
« Last Edit: March 25, 2017, 03:59:03 PM by Zeblote »

Remember that project a couple years back to add a proper encryption library to Blockland?
Killed due to the finickyness of torque and 32-bit plus arithmetic and my lack of an ability to make a proper bignum modulus function :'(
rip BLCrypto

Killed due to the finickyness of torque and 32-bit plus arithmetic and my lack of an ability to make a proper bignum modulus function :'(
rip BLCrypto
such an adorable crypto nerd