KnightOS offers minimal cryptographic support, including SHA-1, MD5, and CRC. CRC and MD5 are suitable for data validation, and SHA-1 is suitable for cryptographic hashing. This statement is true in 2014, but may not hold up long after this document is written. Always research the latest news in cryptography before settling on an algorithm.

Cryptography

sha1AddByte View Source

Adds a single byte to the SHA1 hash input stream. Call this function once for each byte in the input stream, then call sha1Pad.

Inputs

A

Byte to add

IX

location of SHA1 state block

sha1AddRange View Source

Adds a range of bytes to a SHA1 hash. This routine is equivalent to, but faster than, calling sha1AddByte many times.

Inputs

IX

location of SHA1 state block

HL

location of range to add

BC

number of bytes to add

sha1Clean View Source

Safely deallocates a SHA1 state block allocated by sha1Init.

Inputs

IX

location of allocated block

sha1Init View Source

Allocates a memory block to keep the state and result of a SHA1 hash operation. The result is kept in the first 20 bytes of the allocated block. You must use sha1Clean to deallocate the block; simply using free will result in a memory leak!

Outputs

A

Error code (on failure)

IX

location of allocated block (on success)

Z

Set on success, reset on failure

sha1Pad View Source

Finishes the SHA1 computation by appending the required bits to the input. Call this routine once after calling sha1AddByte for each input byte. After this routine, the 8 bytes pointed to by IX will contain the big-endian SHA1 hash.

Inputs

IX

location of SHA1 state block