16
Modification Help / [Library] SHA-256
« on: March 19, 2017, 09:33:52 AM »
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
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