Movable Type Home Page

Movable Type Scripts

SHA-512 Cryptographic Hash Algorithm

A cryptographic hash (sometimes called ‘digest’) is a kind of ‘signature’ for a text or a data file. SHA-512 generates an almost-unique 512-bit (32-byte) signature for a text. See below for the source code.

Enter any message to check its SHA-512 hash

This is a companion to the SHA-256 script (where there’s more explanation). This is a reference implementation, as close as possible to the NIST specification, to help in understanding the algorithm (§ection numbers relate the code back to sections in the standard); it is not at all optimised (using Chrome on a low-to-middling Core i5 PC, in timing tests this script will hash a short message in around 0.4 – 0.6 ms; longer messages will be hashed at a speed of around 0.5 – 1 MB/sec.

As SHA-512 is based on 64-bit unsigned integers, which are not natively supported by JavaScript, this is more complex to implement in JavaScript than SHA-256. Here I’ve implemented a Long library for UInt64 operations; there would be more efficient means of doing this for an optimised implementation.