Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/eWert-Online/rescript-hash. Secure Hash Algorithms for ReScript
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189// Generated by ReScript, PLEASE EDIT WITH CARE'use strict';
var Belt_Array = require("bs-platform/lib/js/belt_Array.js");
function rotl(x, n) { return (x << n) | (x >>> (64 - n | 0)) | 0;}
function append(hash, value, offset) { for(var j = 0; j <= 3; ++j){ hash[j + offset | 0] = (value >>> (j << 3)) & 255; } return hash;}
var k = [ -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162, 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632, 643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784, 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222, -722521979, 76029189, -640364487, -421815835, 530742520, -995338651, -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649, -145523070, -1120210379, 718787259, -343485551];
var s = [ 7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21];
function pad(msg) { var size = (msg.length + 8 | 0) + 1 | 0; while(size % 64 !== 0) { size = size + 1 | 0; }; var length = msg.length; var bytes = Belt_Array.makeBy(size, (function (index) { if (index < length) { return msg.charCodeAt(index) | 0; } else if (index === length) { return 128; } else { return 0; } })); var va = (length << 3); for(var i = 0; i <= 7; ++i){ bytes[i + (size - 8 | 0) | 0] = va & 255; va = (va >>> 8); } return bytes;}
function make(message) { var message$1 = pad(message); var chunks = ((message$1.length + 8 | 0) >> 6); var a = { contents: 1732584193 }; var b = { contents: -271733879 }; var c = { contents: -1732584194 }; var d = { contents: 271733878 }; var w = Belt_Array.make(16, 0); for(var i = 0; i < chunks; ++i){ for(var j = 0; j <= 63; ++j){ var result = (message$1[(i << 6) + j | 0] << 24) | (w[(j >>> 2)] >>> 8); w[(j >>> 2)] = result; } var originalA = a.contents; var originalB = b.contents; var originalC = c.contents; var originalD = d.contents; k.forEach(function (k, j) { var f = 0 <= j && j <= 15 ? b.contents & c.contents | (b.contents ^ -1) & d.contents : ( 16 <= j && j <= 31 ? b.contents & d.contents | c.contents & (d.contents ^ -1) : ( 32 <= j && j <= 47 ? b.contents ^ c.contents ^ d.contents : c.contents ^ (b.contents | d.contents ^ -1) ) ); var g = 0 <= j && j <= 15 ? j : ( 16 <= j && j <= 31 ? (Math.imul(5, j) + 1 | 0) % 16 : ( 32 <= j && j <= 47 ? (Math.imul(3, j) + 5 | 0) % 16 : Math.imul(7, j) % 16 ) ); var temp = b.contents + rotl(((a.contents + f | 0) + w[g] | 0) + k | 0, s[((j >>> 4) << 2) | j & 3]) | 0; a.contents = d.contents; d.contents = c.contents; c.contents = b.contents; b.contents = temp; }); a.contents = originalA + a.contents | 0; b.contents = originalB + b.contents | 0; c.contents = originalC + c.contents | 0; d.contents = originalD + d.contents | 0; } var input = append(append(append(append(Belt_Array.make(16, 0), a.contents, 0), b.contents, 4), c.contents, 8), d.contents, 12).reduce((function (acc, curr) { return acc + String.fromCharCode(curr); }), ""); var hex = "0123456789abcdef"; return input.split("").reduce((function (acc, curr) { var charCode = curr.charCodeAt(0) | 0; return acc + (hex.charAt((charCode >>> 4) & 15) + hex.charAt(charCode & 15)); }), "");}
var makeU = make;
exports.make = make;exports.makeU = makeU;/* No side effect */