Just-for-fun implementation of SHA-256. It is much more computationally intensive than MD5, so this time I went for performance, code size be damned. What resulted is probably the fastest SHA-256 for the 6502, hashing at a blistering pace of 410 bytes/s on a C64. All that with a minimal use of ZP.
You will need cc65 (https://github.com/cc65/cc65) to build.
In order to calculate SHA-256 hash of a message:
- Call
_sha256_init
. - Call
_sha256_next_block
for every 64-byte block of the message, passing a pointer to beginning of the block in A/X (lo/hi) and size of the block in Y. Only the final block's size can be smaller than 64 bytes! - Call
_sha256_finalize
. - Find computed SHA-256 hash in 32 bytes starting at
_sha256_hash
.
See tests.s
for examples.
Currently messages of up to 2MiB are supported. This should not be a problem in practice, but if the need arises, the limit can be increased easily.
Sure. Run make test
. If it fails, you optimized too much.
Yes. make sha256.prg
and have fun benchmarking.
Milek Smyk (@laubzega)