Test name | Executions per second |
---|---|
forge | 45760.9 Ops/sec |
native | 97131.1 Ops/sec |
sjcl | 0.0 Ops/sec |
cryptojs | 10074.4 Ops/sec |
<script src="https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.6/sjcl.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/rusha/0.8.7/rusha.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/forge/0.9.1/forge.min.js"></script>
var data = new Uint32Array(1024);
window.crypto.getRandomValues(data);
var dataBuffer = new Uint8Array(data);
data = String.fromCharCode.apply(null, dataBuffer);
// src: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
function hex(buffer) {
var hexCodes = [];
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 4) {
// Using getUint32 reduces the number of iterations needed (we process 4 bytes each time)
var value = view.getUint32(i)
// toString(16) will give the hex representation of the number without padding
var stringValue = value.toString(16)
// We use concatenation and slice for padding
var padding = '00000000'
var paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
// Join all the hex strings into one
return hexCodes.join("");
}
forge.md.sha1.create().update(data).digest()
crypto.subtle.digest("SHA-1", dataBuffer ).then(function (hash) {console.log(hex(hash));});
sjcl.hash.sha1.hash(data);
CryptoJS.SHA1(data);