From 8d3170cf84c94801b1390e88dc1b4189e4b65c09 Mon Sep 17 00:00:00 2001 From: Torben Ewert Date: Mon, 20 Apr 2020 10:22:20 +0200 Subject: [PATCH] TASK: Reorganize Folder Structure --- lib/js/__tests__/ReCrypt_test.bs.js | 13 +- lib/js/src/ReCrypt.bs.js | 24 +- .../ReCrypt/MD5/ReCrypt_MD5_Constants.bs.js | 101 ++++ .../ReCrypt/MD5/ReCrypt_MD5_Preprocess.bs.js | 32 ++ .../src/ReCrypt/MD5/ReCrypt_MD5_Process.bs.js | 60 +++ lib/js/src/ReCrypt/ReCrypt_MD5.bs.js | 175 +------ lib/js/src/ReCrypt/ReCrypt_Sha1.bs.js | 80 +--- lib/js/src/ReCrypt/ReCrypt_Sha224.bs.js | 151 +----- lib/js/src/ReCrypt/ReCrypt_Sha256.bs.js | 152 +----- lib/js/src/ReCrypt/ReCrypt_Sha384.bs.js | 445 +---------------- lib/js/src/ReCrypt/ReCrypt_Sha512.bs.js | 447 +----------------- .../ReCrypt/Sha1/ReCrypt_Sha1_Constants.bs.js | 29 ++ .../Sha1/ReCrypt_Sha1_Preprocess.bs.js | 32 ++ .../ReCrypt/Sha1/ReCrypt_Sha1_Process.bs.js | 58 +++ .../Sha224/ReCrypt_Sha224_Constants.bs.js | 85 ++++ .../Sha224/ReCrypt_Sha224_Preprocess.bs.js | 32 ++ .../Sha224/ReCrypt_Sha224_Process.bs.js | 73 +++ .../Sha256/ReCrypt_Sha256_Constants.bs.js | 85 ++++ .../Sha256/ReCrypt_Sha256_Preprocess.bs.js | 32 ++ .../Sha256/ReCrypt_Sha256_Process.bs.js | 74 +++ .../Sha384/ReCrypt_Sha384_Constants.bs.js | 365 ++++++++++++++ .../Sha384/ReCrypt_Sha384_Preprocess.bs.js | 32 ++ .../Sha384/ReCrypt_Sha384_Process.bs.js | 87 ++++ .../Sha512/ReCrypt_Sha512_Constants.bs.js | 365 ++++++++++++++ .../Sha512/ReCrypt_Sha512_Preprocess.bs.js | 32 ++ .../Sha512/ReCrypt_Sha512_Process.bs.js | 89 ++++ src/ReCrypt.rei | 2 - src/ReCrypt/MD5/ReCrypt_MD5_Constants.re | 70 +++ src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.re | 25 + src/ReCrypt/MD5/ReCrypt_MD5_Process.re | 72 +++ src/ReCrypt/ReCrypt_MD5.re | 175 +------ src/ReCrypt/ReCrypt_MD5.rei | 4 - src/ReCrypt/ReCrypt_Preprocess.re | 64 --- src/ReCrypt/ReCrypt_Preprocess.rei | 2 - src/ReCrypt/ReCrypt_Sha1.re | 119 +---- src/ReCrypt/ReCrypt_Sha1.rei | 4 - src/ReCrypt/ReCrypt_Sha224.re | 196 +------- src/ReCrypt/ReCrypt_Sha224.rei | 4 - src/ReCrypt/ReCrypt_Sha256.re | 196 +------- src/ReCrypt/ReCrypt_Sha256.rei | 4 - src/ReCrypt/ReCrypt_Sha384.re | 190 +------- src/ReCrypt/ReCrypt_Sha384.rei | 4 - src/ReCrypt/ReCrypt_Sha512.re | 192 +------- src/ReCrypt/ReCrypt_Sha512.rei | 4 - src/ReCrypt/ReCrypt_Utils.rei | 16 - src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.re | 17 + src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.re | 28 ++ src/ReCrypt/Sha1/ReCrypt_Sha1_Process.re | 94 ++++ .../Sha224/ReCrypt_Sha224_Constants.re | 77 +++ .../Sha224/ReCrypt_Sha224_Preprocess.re | 28 ++ src/ReCrypt/Sha224/ReCrypt_Sha224_Process.re | 111 +++++ .../Sha256/ReCrypt_Sha256_Constants.re | 76 +++ .../Sha256/ReCrypt_Sha256_Preprocess.re | 28 ++ src/ReCrypt/Sha256/ReCrypt_Sha256_Process.re | 112 +++++ .../Sha384/ReCrypt_Sha384_Constants.re | 93 ++++ .../Sha384/ReCrypt_Sha384_Preprocess.re | 28 ++ src/ReCrypt/Sha384/ReCrypt_Sha384_Process.re | 89 ++++ .../Sha512/ReCrypt_Sha512_Constants.re | 93 ++++ .../Sha512/ReCrypt_Sha512_Preprocess.re | 28 ++ src/ReCrypt/Sha512/ReCrypt_Sha512_Process.re | 91 ++++ 60 files changed, 2925 insertions(+), 2561 deletions(-) create mode 100644 lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Constants.bs.js create mode 100644 lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.bs.js create mode 100644 lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Process.bs.js create mode 100644 lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.bs.js create mode 100644 lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.bs.js create mode 100644 lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Process.bs.js create mode 100644 lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Constants.bs.js create mode 100644 lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Preprocess.bs.js create mode 100644 lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Process.bs.js create mode 100644 lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Constants.bs.js create mode 100644 lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Preprocess.bs.js create mode 100644 lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Process.bs.js create mode 100644 lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Constants.bs.js create mode 100644 lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Preprocess.bs.js create mode 100644 lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Process.bs.js create mode 100644 lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Constants.bs.js create mode 100644 lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Preprocess.bs.js create mode 100644 lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Process.bs.js create mode 100644 src/ReCrypt/MD5/ReCrypt_MD5_Constants.re create mode 100644 src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.re create mode 100644 src/ReCrypt/MD5/ReCrypt_MD5_Process.re delete mode 100644 src/ReCrypt/ReCrypt_MD5.rei delete mode 100644 src/ReCrypt/ReCrypt_Preprocess.re delete mode 100644 src/ReCrypt/ReCrypt_Preprocess.rei delete mode 100644 src/ReCrypt/ReCrypt_Sha1.rei delete mode 100644 src/ReCrypt/ReCrypt_Sha224.rei delete mode 100644 src/ReCrypt/ReCrypt_Sha256.rei delete mode 100644 src/ReCrypt/ReCrypt_Sha384.rei delete mode 100644 src/ReCrypt/ReCrypt_Sha512.rei delete mode 100644 src/ReCrypt/ReCrypt_Utils.rei create mode 100644 src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.re create mode 100644 src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.re create mode 100644 src/ReCrypt/Sha1/ReCrypt_Sha1_Process.re create mode 100644 src/ReCrypt/Sha224/ReCrypt_Sha224_Constants.re create mode 100644 src/ReCrypt/Sha224/ReCrypt_Sha224_Preprocess.re create mode 100644 src/ReCrypt/Sha224/ReCrypt_Sha224_Process.re create mode 100644 src/ReCrypt/Sha256/ReCrypt_Sha256_Constants.re create mode 100644 src/ReCrypt/Sha256/ReCrypt_Sha256_Preprocess.re create mode 100644 src/ReCrypt/Sha256/ReCrypt_Sha256_Process.re create mode 100644 src/ReCrypt/Sha384/ReCrypt_Sha384_Constants.re create mode 100644 src/ReCrypt/Sha384/ReCrypt_Sha384_Preprocess.re create mode 100644 src/ReCrypt/Sha384/ReCrypt_Sha384_Process.re create mode 100644 src/ReCrypt/Sha512/ReCrypt_Sha512_Constants.re create mode 100644 src/ReCrypt/Sha512/ReCrypt_Sha512_Preprocess.re create mode 100644 src/ReCrypt/Sha512/ReCrypt_Sha512_Process.re diff --git a/lib/js/__tests__/ReCrypt_test.bs.js b/lib/js/__tests__/ReCrypt_test.bs.js index 5e40ed2..c309d4c 100644 --- a/lib/js/__tests__/ReCrypt_test.bs.js +++ b/lib/js/__tests__/ReCrypt_test.bs.js @@ -3,7 +3,6 @@ var Jest = require("@glennsl/bs-jest/lib/js/src/jest.js"); var $$Array = require("bs-platform/lib/js/array.js"); -var Curry = require("bs-platform/lib/js/curry.js"); var ReCrypt = require("../src/ReCrypt.bs.js"); var tests = [ @@ -58,7 +57,7 @@ Jest.describe("MD5", (function (param) { return Jest.describe("make()", (function (param) { return $$Array.iter((function (t) { return Jest.test("\"" + (t.input + "\""), (function (param) { - return Jest.Expect.toBe(t.md5, Jest.Expect.expect(Curry._1(ReCrypt.MD5.make, t.input))); + return Jest.Expect.toBe(t.md5, Jest.Expect.expect(ReCrypt.MD5.make(t.input))); })); }), tests); })); @@ -68,7 +67,7 @@ Jest.describe("Sha1", (function (param) { return Jest.describe("make()", (function (param) { return $$Array.iter((function (t) { return Jest.test("\"" + (t.input + "\""), (function (param) { - return Jest.Expect.toBe(t.sha1, Jest.Expect.expect(Curry._1(ReCrypt.Sha1.make, t.input))); + return Jest.Expect.toBe(t.sha1, Jest.Expect.expect(ReCrypt.Sha1.make(t.input))); })); }), tests); })); @@ -78,7 +77,7 @@ Jest.describe("Sha224", (function (param) { return Jest.describe("make()", (function (param) { return $$Array.iter((function (t) { return Jest.test("\"" + (t.input + "\""), (function (param) { - return Jest.Expect.toBe(t.sha224, Jest.Expect.expect(Curry._1(ReCrypt.Sha224.make, t.input))); + return Jest.Expect.toBe(t.sha224, Jest.Expect.expect(ReCrypt.Sha224.make(t.input))); })); }), tests); })); @@ -88,7 +87,7 @@ Jest.describe("Sha256", (function (param) { return Jest.describe("make()", (function (param) { return $$Array.iter((function (t) { return Jest.test("\"" + (t.input + "\""), (function (param) { - return Jest.Expect.toBe(t.sha256, Jest.Expect.expect(Curry._1(ReCrypt.Sha256.make, t.input))); + return Jest.Expect.toBe(t.sha256, Jest.Expect.expect(ReCrypt.Sha256.make(t.input))); })); }), tests); })); @@ -98,7 +97,7 @@ Jest.describe("Sha384", (function (param) { return Jest.describe("make()", (function (param) { return $$Array.iter((function (t) { return Jest.test("\"" + (t.input + "\""), (function (param) { - return Jest.Expect.toBe(t.sha384, Jest.Expect.expect(Curry._1(ReCrypt.Sha384.make, t.input))); + return Jest.Expect.toBe(t.sha384, Jest.Expect.expect(ReCrypt.Sha384.make(t.input))); })); }), tests); })); @@ -108,7 +107,7 @@ Jest.describe("Sha512", (function (param) { return Jest.describe("make()", (function (param) { return $$Array.iter((function (t) { return Jest.test("\"" + (t.input + "\""), (function (param) { - return Jest.Expect.toBe(t.sha512, Jest.Expect.expect(Curry._1(ReCrypt.Sha512.make, t.input))); + return Jest.Expect.toBe(t.sha512, Jest.Expect.expect(ReCrypt.Sha512.make(t.input))); })); }), tests); })); diff --git a/lib/js/src/ReCrypt.bs.js b/lib/js/src/ReCrypt.bs.js index 5515f77..9a1297a 100644 --- a/lib/js/src/ReCrypt.bs.js +++ b/lib/js/src/ReCrypt.bs.js @@ -8,17 +8,29 @@ var ReCrypt_Sha256 = require("./ReCrypt/ReCrypt_Sha256.bs.js"); var ReCrypt_Sha384 = require("./ReCrypt/ReCrypt_Sha384.bs.js"); var ReCrypt_Sha512 = require("./ReCrypt/ReCrypt_Sha512.bs.js"); -var MD5 = ReCrypt_MD5; +var MD5 = { + make: ReCrypt_MD5.make +}; -var Sha1 = ReCrypt_Sha1; +var Sha1 = { + make: ReCrypt_Sha1.make +}; -var Sha224 = ReCrypt_Sha224; +var Sha224 = { + make: ReCrypt_Sha224.make +}; -var Sha256 = ReCrypt_Sha256; +var Sha256 = { + make: ReCrypt_Sha256.make +}; -var Sha384 = ReCrypt_Sha384; +var Sha384 = { + make: ReCrypt_Sha384.make +}; -var Sha512 = ReCrypt_Sha512; +var Sha512 = { + make: ReCrypt_Sha512.make +}; exports.MD5 = MD5; exports.Sha1 = Sha1; diff --git a/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Constants.bs.js b/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Constants.bs.js new file mode 100644 index 0000000..f31938f --- /dev/null +++ b/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Constants.bs.js @@ -0,0 +1,101 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + + +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 +]; + +var initialHash = [ + 1732584193, + -271733879, + -1732584194, + 271733878 +]; + +exports.k = k; +exports.s = s; +exports.initialHash = initialHash; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.bs.js b/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.bs.js new file mode 100644 index 0000000..0518f1f --- /dev/null +++ b/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.bs.js @@ -0,0 +1,32 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); + +function pad(msgBytes) { + var size = (msgBytes.length + 8 | 0) + 1 | 0; + while(size % 64 !== 0) { + size = size + 1 | 0; + }; + var length = msgBytes.length; + var bytes = Bytes.init(size, (function (index) { + if (index < length) { + return Caml_bytes.get(msgBytes, index); + } else if (index === length) { + return Char.chr(128); + } else { + return Char.chr(0); + } + })); + var va = (length << 3); + for(var i = 0; i <= 7; ++i){ + bytes[i + (size - 8 | 0) | 0] = Char.chr(va & 255); + va = (va >>> 8); + } + return bytes; +} + +exports.pad = pad; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Process.bs.js b/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Process.bs.js new file mode 100644 index 0000000..976ae40 --- /dev/null +++ b/lib/js/src/ReCrypt/MD5/ReCrypt_MD5_Process.bs.js @@ -0,0 +1,60 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Caml_array = require("bs-platform/lib/js/caml_array.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); +var Caml_int32 = require("bs-platform/lib/js/caml_int32.js"); +var Pervasives = require("bs-platform/lib/js/pervasives.js"); +var ReCrypt_Utils = require("../ReCrypt_Utils.bs.js"); +var ReCrypt_Functions_MD = require("../Functions/ReCrypt_Functions_MD.bs.js"); +var ReCrypt_MD5_Constants = require("./ReCrypt_MD5_Constants.bs.js"); + +function make(message) { + var chunks = ((message.length + 8 | 0) >> 6); + var a = Caml_array.caml_array_get(ReCrypt_MD5_Constants.initialHash, 0); + var b = Caml_array.caml_array_get(ReCrypt_MD5_Constants.initialHash, 1); + var c = Caml_array.caml_array_get(ReCrypt_MD5_Constants.initialHash, 2); + var d = Caml_array.caml_array_get(ReCrypt_MD5_Constants.initialHash, 3); + var w = Caml_array.caml_make_vect(16, 0); + for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ + for(var j = 0; j <= 63; ++j){ + Caml_array.caml_array_set(w, (j >>> 2), (Caml_bytes.get(message, (i << 6) + j | 0) << 24) | (Caml_array.caml_array_get(w, (j >>> 2)) >>> 8)); + } + var originalA = a; + var originalB = b; + var originalC = c; + var originalD = d; + for(var j$1 = 0; j$1 <= 63; ++j$1){ + var f = 0 <= j$1 && j$1 <= 15 ? b & c | Pervasives.lnot(b) & d : ( + 16 <= j$1 && j$1 <= 31 ? b & d | c & Pervasives.lnot(d) : ( + 32 <= j$1 && j$1 <= 47 ? b ^ c ^ d : c ^ (b | Pervasives.lnot(d)) + ) + ); + var g = 0 <= j$1 && j$1 <= 15 ? j$1 : ( + 16 <= j$1 && j$1 <= 31 ? (Caml_int32.imul(5, j$1) + 1 | 0) % 16 : ( + 32 <= j$1 && j$1 <= 47 ? (Caml_int32.imul(3, j$1) + 5 | 0) % 16 : Caml_int32.imul(7, j$1) % 16 + ) + ); + var temp = b + ReCrypt_Functions_MD.rotl(((a + f | 0) + Caml_array.caml_array_get(w, g) | 0) + Caml_array.caml_array_get(ReCrypt_MD5_Constants.k, j$1) | 0, Caml_array.caml_array_get(ReCrypt_MD5_Constants.s, ((j$1 >>> 4) << 2) | j$1 & 3)) | 0; + a = d; + d = c; + c = b; + b = temp; + } + a = originalA + a | 0; + b = originalB + b | 0; + c = originalC + c | 0; + d = originalD + d | 0; + } + var md5 = Bytes.make(16, Char.chr(0)); + ReCrypt_Utils.append(md5, a, 0); + ReCrypt_Utils.append(md5, b, 4); + ReCrypt_Utils.append(md5, c, 8); + ReCrypt_Utils.append(md5, d, 12); + return ReCrypt_Utils.stringToHex(Bytes.to_string(md5)); +} + +exports.make = make; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/ReCrypt_MD5.bs.js b/lib/js/src/ReCrypt/ReCrypt_MD5.bs.js index 44b3e43..dfe7e0d 100644 --- a/lib/js/src/ReCrypt/ReCrypt_MD5.bs.js +++ b/lib/js/src/ReCrypt/ReCrypt_MD5.bs.js @@ -1,177 +1,20 @@ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; -var Char = require("bs-platform/lib/js/char.js"); var Bytes = require("bs-platform/lib/js/bytes.js"); -var Caml_array = require("bs-platform/lib/js/caml_array.js"); -var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); -var Caml_int32 = require("bs-platform/lib/js/caml_int32.js"); -var Pervasives = require("bs-platform/lib/js/pervasives.js"); -var ReCrypt_Utils = require("./ReCrypt_Utils.bs.js"); -var ReCrypt_Functions_MD = require("./Functions/ReCrypt_Functions_MD.bs.js"); - -var constants = [ - -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 -]; - -var initialHash = [ - 1732584193, - -271733879, - -1732584194, - 271733878 -]; - -function preprocess(msgBytes) { - var size = (msgBytes.length + 8 | 0) + 1 | 0; - while(size % 64 !== 0) { - size = size + 1 | 0; - }; - var length = msgBytes.length; - var bytes = Bytes.init(size, (function (index) { - if (index < length) { - return Caml_bytes.get(msgBytes, index); - } else if (index === length) { - return Char.chr(128); - } else { - return Char.chr(0); - } - })); - var va = (length << 3); - for(var i = 0; i <= 7; ++i){ - bytes[i + (size - 8 | 0) | 0] = Char.chr(va & 255); - va = (va >>> 8); - } - return bytes; -} +var ReCrypt_MD5_Process = require("./MD5/ReCrypt_MD5_Process.bs.js"); +var ReCrypt_MD5_Preprocess = require("./MD5/ReCrypt_MD5_Preprocess.bs.js"); function make(message) { var messageBytes = Bytes.of_string(message); - var message$1 = preprocess(messageBytes); - var chunks = ((message$1.length + 8 | 0) >> 6); - var a = Caml_array.caml_array_get(initialHash, 0); - var b = Caml_array.caml_array_get(initialHash, 1); - var c = Caml_array.caml_array_get(initialHash, 2); - var d = Caml_array.caml_array_get(initialHash, 3); - var w = Caml_array.caml_make_vect(16, 0); - for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ - for(var j = 0; j <= 63; ++j){ - Caml_array.caml_array_set(w, (j >>> 2), (Caml_bytes.get(message$1, (i << 6) + j | 0) << 24) | (Caml_array.caml_array_get(w, (j >>> 2)) >>> 8)); - } - var originalA = a; - var originalB = b; - var originalC = c; - var originalD = d; - for(var j$1 = 0; j$1 <= 63; ++j$1){ - var f = 0 <= j$1 && j$1 <= 15 ? b & c | Pervasives.lnot(b) & d : ( - 16 <= j$1 && j$1 <= 31 ? b & d | c & Pervasives.lnot(d) : ( - 32 <= j$1 && j$1 <= 47 ? b ^ c ^ d : c ^ (b | Pervasives.lnot(d)) - ) - ); - var g = 0 <= j$1 && j$1 <= 15 ? j$1 : ( - 16 <= j$1 && j$1 <= 31 ? (Caml_int32.imul(5, j$1) + 1 | 0) % 16 : ( - 32 <= j$1 && j$1 <= 47 ? (Caml_int32.imul(3, j$1) + 5 | 0) % 16 : Caml_int32.imul(7, j$1) % 16 - ) - ); - var temp = b + ReCrypt_Functions_MD.rotl(((a + f | 0) + Caml_array.caml_array_get(w, g) | 0) + Caml_array.caml_array_get(constants, j$1) | 0, Caml_array.caml_array_get(s, ((j$1 >>> 4) << 2) | j$1 & 3)) | 0; - a = d; - d = c; - c = b; - b = temp; - } - a = originalA + a | 0; - b = originalB + b | 0; - c = originalC + c | 0; - d = originalD + d | 0; - } - var md5 = Bytes.make(16, Char.chr(0)); - ReCrypt_Utils.append(md5, a, 0); - ReCrypt_Utils.append(md5, b, 4); - ReCrypt_Utils.append(md5, c, 8); - ReCrypt_Utils.append(md5, d, 12); - return ReCrypt_Utils.stringToHex(Bytes.to_string(md5)); + return ReCrypt_MD5_Process.make(ReCrypt_MD5_Preprocess.pad(messageBytes)); } +var Preprocess = /* alias */0; + +var Process = /* alias */0; + +exports.Preprocess = Preprocess; +exports.Process = Process; exports.make = make; /* No side effect */ diff --git a/lib/js/src/ReCrypt/ReCrypt_Sha1.bs.js b/lib/js/src/ReCrypt/ReCrypt_Sha1.bs.js index 2c1ff84..f203c14 100644 --- a/lib/js/src/ReCrypt/ReCrypt_Sha1.bs.js +++ b/lib/js/src/ReCrypt/ReCrypt_Sha1.bs.js @@ -1,82 +1,20 @@ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; -var Char = require("bs-platform/lib/js/char.js"); var Bytes = require("bs-platform/lib/js/bytes.js"); -var Int32 = require("bs-platform/lib/js/int32.js"); -var Caml_array = require("bs-platform/lib/js/caml_array.js"); -var ReCrypt_Utils = require("./ReCrypt_Utils.bs.js"); -var ReCrypt_Preprocess = require("./ReCrypt_Preprocess.bs.js"); -var ReCrypt_Functions_SHA1 = require("./Functions/ReCrypt_Functions_SHA1.bs.js"); - -function constants(t) { - if (t >= 0 && t <= 19) { - return 1518500249; - } else if (t >= 20 && t <= 39) { - return 1859775393; - } else if (t >= 40 && t <= 59) { - return -1894007588; - } else if (t >= 60 && t <= 79) { - return -899497514; - } else { - return 0; - } -} - -var initialHash = [ - 1732584193, - -271733879, - -1732584194, - 271733878, - -1009589776 -]; +var ReCrypt_Sha1_Process = require("./Sha1/ReCrypt_Sha1_Process.bs.js"); +var ReCrypt_Sha1_Preprocess = require("./Sha1/ReCrypt_Sha1_Preprocess.bs.js"); function make(message) { var messageBytes = Bytes.of_string(message); - var message$1 = ReCrypt_Preprocess.Sha1_224_256.pad(messageBytes); - var chunks = ((message$1.length + 8 | 0) >> 6); - var a = Caml_array.caml_array_get(initialHash, 0); - var b = Caml_array.caml_array_get(initialHash, 1); - var c = Caml_array.caml_array_get(initialHash, 2); - var d = Caml_array.caml_array_get(initialHash, 3); - var e = Caml_array.caml_array_get(initialHash, 4); - for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ - var w = Caml_array.caml_make_vect(80, Int32.zero); - for(var t = 0; t <= 15; ++t){ - Caml_array.caml_array_set(w, t, (message$1[(i << 6) + (t << 2) | 0] << 24) & -16777216); - Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message$1[((i << 6) + (t << 2) | 0) + 1 | 0] << 16) & 16711680); - Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message$1[((i << 6) + (t << 2) | 0) + 2 | 0] << 8) & 65280 | message$1[((i << 6) + (t << 2) | 0) + 3 | 0] & 255); - } - for(var t$1 = 16; t$1 <= 79; ++t$1){ - Caml_array.caml_array_set(w, t$1, ReCrypt_Functions_SHA1.rotl(Caml_array.caml_array_get(w, t$1 - 3 | 0) ^ Caml_array.caml_array_get(w, t$1 - 8 | 0) ^ Caml_array.caml_array_get(w, t$1 - 14 | 0) ^ Caml_array.caml_array_get(w, t$1 - 16 | 0), 1)); - } - var originalA = a; - var originalB = b; - var originalC = c; - var originalD = d; - var originalE = e; - for(var t$2 = 0; t$2 <= 79; ++t$2){ - var temp = (((ReCrypt_Functions_SHA1.rotl(a, 5) + ReCrypt_Functions_SHA1.f(t$2, b, c, d) | 0) + e | 0) + constants(t$2) | 0) + Caml_array.caml_array_get(w, t$2) | 0; - e = d; - d = c; - c = ReCrypt_Functions_SHA1.rotl(b, 30); - b = a; - a = temp; - } - a = originalA + a | 0; - b = originalB + b | 0; - c = originalC + c | 0; - d = originalD + d | 0; - e = originalE + e | 0; - } - var sha1raw = Bytes.make(20, Char.chr(0)); - ReCrypt_Utils.append32(sha1raw, a, 0); - ReCrypt_Utils.append32(sha1raw, b, 4); - ReCrypt_Utils.append32(sha1raw, c, 8); - ReCrypt_Utils.append32(sha1raw, d, 12); - ReCrypt_Utils.append32(sha1raw, e, 16); - return ReCrypt_Utils.stringToHex(Bytes.to_string(sha1raw)); + return ReCrypt_Sha1_Process.make(ReCrypt_Sha1_Preprocess.pad(messageBytes)); } +var Preprocess = /* alias */0; + +var Process = /* alias */0; + +exports.Preprocess = Preprocess; +exports.Process = Process; exports.make = make; /* No side effect */ diff --git a/lib/js/src/ReCrypt/ReCrypt_Sha224.bs.js b/lib/js/src/ReCrypt/ReCrypt_Sha224.bs.js index 4c01190..3498847 100644 --- a/lib/js/src/ReCrypt/ReCrypt_Sha224.bs.js +++ b/lib/js/src/ReCrypt/ReCrypt_Sha224.bs.js @@ -1,153 +1,20 @@ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; -var Char = require("bs-platform/lib/js/char.js"); var Bytes = require("bs-platform/lib/js/bytes.js"); -var Int32 = require("bs-platform/lib/js/int32.js"); -var Caml_array = require("bs-platform/lib/js/caml_array.js"); -var ReCrypt_Utils = require("./ReCrypt_Utils.bs.js"); -var ReCrypt_Preprocess = require("./ReCrypt_Preprocess.bs.js"); -var ReCrypt_Functions_SHA2 = require("./Functions/ReCrypt_Functions_SHA2.bs.js"); - -var constants = [ - 1116352408, - 1899447441, - -1245643825, - -373957723, - 961987163, - 1508970993, - -1841331548, - -1424204075, - -670586216, - 310598401, - 607225278, - 1426881987, - 1925078388, - -2132889090, - -1680079193, - -1046744716, - -459576895, - -272742522, - 264347078, - 604807628, - 770255983, - 1249150122, - 1555081692, - 1996064986, - -1740746414, - -1473132947, - -1341970488, - -1084653625, - -958395405, - -710438585, - 113926993, - 338241895, - 666307205, - 773529912, - 1294757372, - 1396182291, - 1695183700, - 1986661051, - -2117940946, - -1838011259, - -1564481375, - -1474664885, - -1035236496, - -949202525, - -778901479, - -694614492, - -200395387, - 275423344, - 430227734, - 506948616, - 659060556, - 883997877, - 958139571, - 1322822218, - 1537002063, - 1747873779, - 1955562222, - 2024104815, - -2067236844, - -1933114872, - -1866530822, - -1538233109, - -1090935817, - -965641998 -]; - -var initialHash = [ - -1056596264, - 914150663, - 812702999, - -150054599, - -4191439, - 1750603025, - 1694076839, - -1090891868 -]; +var ReCrypt_Sha224_Process = require("./Sha224/ReCrypt_Sha224_Process.bs.js"); +var ReCrypt_Sha224_Preprocess = require("./Sha224/ReCrypt_Sha224_Preprocess.bs.js"); function make(message) { var messageBytes = Bytes.of_string(message); - var message$1 = ReCrypt_Preprocess.Sha1_224_256.pad(messageBytes); - var chunks = ((message$1.length + 8 | 0) >> 6); - var a = Caml_array.caml_array_get(initialHash, 0); - var b = Caml_array.caml_array_get(initialHash, 1); - var c = Caml_array.caml_array_get(initialHash, 2); - var d = Caml_array.caml_array_get(initialHash, 3); - var e = Caml_array.caml_array_get(initialHash, 4); - var f = Caml_array.caml_array_get(initialHash, 5); - var g = Caml_array.caml_array_get(initialHash, 6); - var h = Caml_array.caml_array_get(initialHash, 7); - for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ - var w = Caml_array.caml_make_vect(64, Int32.zero); - for(var t = 0; t <= 15; ++t){ - Caml_array.caml_array_set(w, t, (message$1[(i << 6) + (t << 2) | 0] << 24) & -16777216); - Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message$1[((i << 6) + (t << 2) | 0) + 1 | 0] << 16) & 16711680); - Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message$1[((i << 6) + (t << 2) | 0) + 2 | 0] << 8) & 65280 | message$1[((i << 6) + (t << 2) | 0) + 3 | 0] & 255); - } - for(var t$1 = 16; t$1 <= 63; ++t$1){ - Caml_array.caml_array_set(w, t$1, ((ReCrypt_Functions_SHA2.Int32.sigma1(Caml_array.caml_array_get(w, t$1 - 2 | 0)) + Caml_array.caml_array_get(w, t$1 - 7 | 0) | 0) + ReCrypt_Functions_SHA2.Int32.sigma0(Caml_array.caml_array_get(w, t$1 - 15 | 0)) | 0) + Caml_array.caml_array_get(w, t$1 - 16 | 0) | 0); - } - var originalA = a; - var originalB = b; - var originalC = c; - var originalD = d; - var originalE = e; - var originalF = f; - var originalG = g; - var originalH = h; - for(var t$2 = 0; t$2 <= 63; ++t$2){ - var temp1 = (((h + ReCrypt_Functions_SHA2.Int32.sum1(e) | 0) + ReCrypt_Functions_SHA2.Int32.change(e, f, g) | 0) + Caml_array.caml_array_get(constants, t$2) | 0) + Caml_array.caml_array_get(w, t$2) | 0; - var temp2 = ReCrypt_Functions_SHA2.Int32.sum0(a) + ReCrypt_Functions_SHA2.Int32.majority(a, b, c) | 0; - h = g; - g = f; - f = e; - e = d + temp1 | 0; - d = c; - c = b; - b = a; - a = temp1 + temp2 | 0; - } - a = originalA + a | 0; - b = originalB + b | 0; - c = originalC + c | 0; - d = originalD + d | 0; - e = originalE + e | 0; - f = originalF + f | 0; - g = originalG + g | 0; - h = originalH + h | 0; - } - var sha224raw = Bytes.make(28, Char.chr(0)); - ReCrypt_Utils.append32(sha224raw, a, 0); - ReCrypt_Utils.append32(sha224raw, b, 4); - ReCrypt_Utils.append32(sha224raw, c, 8); - ReCrypt_Utils.append32(sha224raw, d, 12); - ReCrypt_Utils.append32(sha224raw, e, 16); - ReCrypt_Utils.append32(sha224raw, f, 20); - ReCrypt_Utils.append32(sha224raw, g, 24); - return ReCrypt_Utils.stringToHex(Bytes.to_string(sha224raw)); + return ReCrypt_Sha224_Process.make(ReCrypt_Sha224_Preprocess.pad(messageBytes)); } +var Preprocess = /* alias */0; + +var Process = /* alias */0; + +exports.Preprocess = Preprocess; +exports.Process = Process; exports.make = make; /* No side effect */ diff --git a/lib/js/src/ReCrypt/ReCrypt_Sha256.bs.js b/lib/js/src/ReCrypt/ReCrypt_Sha256.bs.js index 1e84f67..7463008 100644 --- a/lib/js/src/ReCrypt/ReCrypt_Sha256.bs.js +++ b/lib/js/src/ReCrypt/ReCrypt_Sha256.bs.js @@ -1,154 +1,20 @@ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; -var Char = require("bs-platform/lib/js/char.js"); var Bytes = require("bs-platform/lib/js/bytes.js"); -var Int32 = require("bs-platform/lib/js/int32.js"); -var Caml_array = require("bs-platform/lib/js/caml_array.js"); -var ReCrypt_Utils = require("./ReCrypt_Utils.bs.js"); -var ReCrypt_Preprocess = require("./ReCrypt_Preprocess.bs.js"); -var ReCrypt_Functions_SHA2 = require("./Functions/ReCrypt_Functions_SHA2.bs.js"); - -var constants = [ - 1116352408, - 1899447441, - -1245643825, - -373957723, - 961987163, - 1508970993, - -1841331548, - -1424204075, - -670586216, - 310598401, - 607225278, - 1426881987, - 1925078388, - -2132889090, - -1680079193, - -1046744716, - -459576895, - -272742522, - 264347078, - 604807628, - 770255983, - 1249150122, - 1555081692, - 1996064986, - -1740746414, - -1473132947, - -1341970488, - -1084653625, - -958395405, - -710438585, - 113926993, - 338241895, - 666307205, - 773529912, - 1294757372, - 1396182291, - 1695183700, - 1986661051, - -2117940946, - -1838011259, - -1564481375, - -1474664885, - -1035236496, - -949202525, - -778901479, - -694614492, - -200395387, - 275423344, - 430227734, - 506948616, - 659060556, - 883997877, - 958139571, - 1322822218, - 1537002063, - 1747873779, - 1955562222, - 2024104815, - -2067236844, - -1933114872, - -1866530822, - -1538233109, - -1090935817, - -965641998 -]; - -var initialHash = [ - 1779033703, - -1150833019, - 1013904242, - -1521486534, - 1359893119, - -1694144372, - 528734635, - 1541459225 -]; +var ReCrypt_Sha256_Process = require("./Sha256/ReCrypt_Sha256_Process.bs.js"); +var ReCrypt_Sha256_Preprocess = require("./Sha256/ReCrypt_Sha256_Preprocess.bs.js"); function make(message) { var messageBytes = Bytes.of_string(message); - var message$1 = ReCrypt_Preprocess.Sha1_224_256.pad(messageBytes); - var chunks = ((message$1.length + 8 | 0) >> 6); - var a = Caml_array.caml_array_get(initialHash, 0); - var b = Caml_array.caml_array_get(initialHash, 1); - var c = Caml_array.caml_array_get(initialHash, 2); - var d = Caml_array.caml_array_get(initialHash, 3); - var e = Caml_array.caml_array_get(initialHash, 4); - var f = Caml_array.caml_array_get(initialHash, 5); - var g = Caml_array.caml_array_get(initialHash, 6); - var h = Caml_array.caml_array_get(initialHash, 7); - for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ - var w = Caml_array.caml_make_vect(64, Int32.zero); - for(var t = 0; t <= 15; ++t){ - Caml_array.caml_array_set(w, t, (message$1[(i << 6) + (t << 2) | 0] << 24) & -16777216); - Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message$1[((i << 6) + (t << 2) | 0) + 1 | 0] << 16) & 16711680); - Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message$1[((i << 6) + (t << 2) | 0) + 2 | 0] << 8) & 65280 | message$1[((i << 6) + (t << 2) | 0) + 3 | 0] & 255); - } - for(var t$1 = 16; t$1 <= 63; ++t$1){ - Caml_array.caml_array_set(w, t$1, ((ReCrypt_Functions_SHA2.Int32.sigma1(Caml_array.caml_array_get(w, t$1 - 2 | 0)) + Caml_array.caml_array_get(w, t$1 - 7 | 0) | 0) + ReCrypt_Functions_SHA2.Int32.sigma0(Caml_array.caml_array_get(w, t$1 - 15 | 0)) | 0) + Caml_array.caml_array_get(w, t$1 - 16 | 0) | 0); - } - var originalA = a; - var originalB = b; - var originalC = c; - var originalD = d; - var originalE = e; - var originalF = f; - var originalG = g; - var originalH = h; - for(var t$2 = 0; t$2 <= 63; ++t$2){ - var temp1 = (((h + ReCrypt_Functions_SHA2.Int32.sum1(e) | 0) + ReCrypt_Functions_SHA2.Int32.change(e, f, g) | 0) + Caml_array.caml_array_get(constants, t$2) | 0) + Caml_array.caml_array_get(w, t$2) | 0; - var temp2 = ReCrypt_Functions_SHA2.Int32.sum0(a) + ReCrypt_Functions_SHA2.Int32.majority(a, b, c) | 0; - h = g; - g = f; - f = e; - e = d + temp1 | 0; - d = c; - c = b; - b = a; - a = temp1 + temp2 | 0; - } - a = originalA + a | 0; - b = originalB + b | 0; - c = originalC + c | 0; - d = originalD + d | 0; - e = originalE + e | 0; - f = originalF + f | 0; - g = originalG + g | 0; - h = originalH + h | 0; - } - var sha256raw = Bytes.make(32, Char.chr(0)); - ReCrypt_Utils.append32(sha256raw, a, 0); - ReCrypt_Utils.append32(sha256raw, b, 4); - ReCrypt_Utils.append32(sha256raw, c, 8); - ReCrypt_Utils.append32(sha256raw, d, 12); - ReCrypt_Utils.append32(sha256raw, e, 16); - ReCrypt_Utils.append32(sha256raw, f, 20); - ReCrypt_Utils.append32(sha256raw, g, 24); - ReCrypt_Utils.append32(sha256raw, h, 28); - return ReCrypt_Utils.stringToHex(Bytes.to_string(sha256raw)); + return ReCrypt_Sha256_Process.make(ReCrypt_Sha256_Preprocess.pad(messageBytes)); } +var Preprocess = /* alias */0; + +var Process = /* alias */0; + +exports.Preprocess = Preprocess; +exports.Process = Process; exports.make = make; /* No side effect */ diff --git a/lib/js/src/ReCrypt/ReCrypt_Sha384.bs.js b/lib/js/src/ReCrypt/ReCrypt_Sha384.bs.js index 1616bdd..2d1abfd 100644 --- a/lib/js/src/ReCrypt/ReCrypt_Sha384.bs.js +++ b/lib/js/src/ReCrypt/ReCrypt_Sha384.bs.js @@ -1,447 +1,20 @@ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; -var Char = require("bs-platform/lib/js/char.js"); var Bytes = require("bs-platform/lib/js/bytes.js"); -var Int64 = require("bs-platform/lib/js/int64.js"); -var Caml_array = require("bs-platform/lib/js/caml_array.js"); -var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); -var Caml_int64 = require("bs-platform/lib/js/caml_int64.js"); -var ReCrypt_Utils = require("./ReCrypt_Utils.bs.js"); -var ReCrypt_Preprocess = require("./ReCrypt_Preprocess.bs.js"); -var ReCrypt_Functions_SHA2 = require("./Functions/ReCrypt_Functions_SHA2.bs.js"); - -var constants = [ - /* int64 */[ - /* hi */1116352408, - /* lo */3609767458 - ], - /* int64 */[ - /* hi */1899447441, - /* lo */602891725 - ], - /* int64 */[ - /* hi */-1245643825, - /* lo */3964484399 - ], - /* int64 */[ - /* hi */-373957723, - /* lo */2173295548 - ], - /* int64 */[ - /* hi */961987163, - /* lo */4081628472 - ], - /* int64 */[ - /* hi */1508970993, - /* lo */3053834265 - ], - /* int64 */[ - /* hi */-1841331548, - /* lo */2937671579 - ], - /* int64 */[ - /* hi */-1424204075, - /* lo */3664609560 - ], - /* int64 */[ - /* hi */-670586216, - /* lo */2734883394 - ], - /* int64 */[ - /* hi */310598401, - /* lo */1164996542 - ], - /* int64 */[ - /* hi */607225278, - /* lo */1323610764 - ], - /* int64 */[ - /* hi */1426881987, - /* lo */3590304994 - ], - /* int64 */[ - /* hi */1925078388, - /* lo */4068182383 - ], - /* int64 */[ - /* hi */-2132889090, - /* lo */991336113 - ], - /* int64 */[ - /* hi */-1680079193, - /* lo */633803317 - ], - /* int64 */[ - /* hi */-1046744716, - /* lo */3479774868 - ], - /* int64 */[ - /* hi */-459576895, - /* lo */2666613458 - ], - /* int64 */[ - /* hi */-272742522, - /* lo */944711139 - ], - /* int64 */[ - /* hi */264347078, - /* lo */2341262773 - ], - /* int64 */[ - /* hi */604807628, - /* lo */2007800933 - ], - /* int64 */[ - /* hi */770255983, - /* lo */1495990901 - ], - /* int64 */[ - /* hi */1249150122, - /* lo */1856431235 - ], - /* int64 */[ - /* hi */1555081692, - /* lo */3175218132 - ], - /* int64 */[ - /* hi */1996064986, - /* lo */2198950837 - ], - /* int64 */[ - /* hi */-1740746414, - /* lo */3999719339 - ], - /* int64 */[ - /* hi */-1473132947, - /* lo */766784016 - ], - /* int64 */[ - /* hi */-1341970488, - /* lo */2566594879 - ], - /* int64 */[ - /* hi */-1084653625, - /* lo */3203337956 - ], - /* int64 */[ - /* hi */-958395405, - /* lo */1034457026 - ], - /* int64 */[ - /* hi */-710438585, - /* lo */2466948901 - ], - /* int64 */[ - /* hi */113926993, - /* lo */3758326383 - ], - /* int64 */[ - /* hi */338241895, - /* lo */168717936 - ], - /* int64 */[ - /* hi */666307205, - /* lo */1188179964 - ], - /* int64 */[ - /* hi */773529912, - /* lo */1546045734 - ], - /* int64 */[ - /* hi */1294757372, - /* lo */1522805485 - ], - /* int64 */[ - /* hi */1396182291, - /* lo */2643833823 - ], - /* int64 */[ - /* hi */1695183700, - /* lo */2343527390 - ], - /* int64 */[ - /* hi */1986661051, - /* lo */1014477480 - ], - /* int64 */[ - /* hi */-2117940946, - /* lo */1206759142 - ], - /* int64 */[ - /* hi */-1838011259, - /* lo */344077627 - ], - /* int64 */[ - /* hi */-1564481375, - /* lo */1290863460 - ], - /* int64 */[ - /* hi */-1474664885, - /* lo */3158454273 - ], - /* int64 */[ - /* hi */-1035236496, - /* lo */3505952657 - ], - /* int64 */[ - /* hi */-949202525, - /* lo */106217008 - ], - /* int64 */[ - /* hi */-778901479, - /* lo */3606008344 - ], - /* int64 */[ - /* hi */-694614492, - /* lo */1432725776 - ], - /* int64 */[ - /* hi */-200395387, - /* lo */1467031594 - ], - /* int64 */[ - /* hi */275423344, - /* lo */851169720 - ], - /* int64 */[ - /* hi */430227734, - /* lo */3100823752 - ], - /* int64 */[ - /* hi */506948616, - /* lo */1363258195 - ], - /* int64 */[ - /* hi */659060556, - /* lo */3750685593 - ], - /* int64 */[ - /* hi */883997877, - /* lo */3785050280 - ], - /* int64 */[ - /* hi */958139571, - /* lo */3318307427 - ], - /* int64 */[ - /* hi */1322822218, - /* lo */3812723403 - ], - /* int64 */[ - /* hi */1537002063, - /* lo */2003034995 - ], - /* int64 */[ - /* hi */1747873779, - /* lo */3602036899 - ], - /* int64 */[ - /* hi */1955562222, - /* lo */1575990012 - ], - /* int64 */[ - /* hi */2024104815, - /* lo */1125592928 - ], - /* int64 */[ - /* hi */-2067236844, - /* lo */2716904306 - ], - /* int64 */[ - /* hi */-1933114872, - /* lo */442776044 - ], - /* int64 */[ - /* hi */-1866530822, - /* lo */593698344 - ], - /* int64 */[ - /* hi */-1538233109, - /* lo */3733110249 - ], - /* int64 */[ - /* hi */-1090935817, - /* lo */2999351573 - ], - /* int64 */[ - /* hi */-965641998, - /* lo */3815920427 - ], - /* int64 */[ - /* hi */-903397682, - /* lo */3928383900 - ], - /* int64 */[ - /* hi */-779700025, - /* lo */566280711 - ], - /* int64 */[ - /* hi */-354779690, - /* lo */3454069534 - ], - /* int64 */[ - /* hi */-176337025, - /* lo */4000239992 - ], - /* int64 */[ - /* hi */116418474, - /* lo */1914138554 - ], - /* int64 */[ - /* hi */174292421, - /* lo */2731055270 - ], - /* int64 */[ - /* hi */289380356, - /* lo */3203993006 - ], - /* int64 */[ - /* hi */460393269, - /* lo */320620315 - ], - /* int64 */[ - /* hi */685471733, - /* lo */587496836 - ], - /* int64 */[ - /* hi */852142971, - /* lo */1086792851 - ], - /* int64 */[ - /* hi */1017036298, - /* lo */365543100 - ], - /* int64 */[ - /* hi */1126000580, - /* lo */2618297676 - ], - /* int64 */[ - /* hi */1288033470, - /* lo */3409855158 - ], - /* int64 */[ - /* hi */1501505948, - /* lo */4234509866 - ], - /* int64 */[ - /* hi */1607167915, - /* lo */987167468 - ], - /* int64 */[ - /* hi */1816402316, - /* lo */1246189591 - ] -]; - -var initialHash = [ - /* int64 */[ - /* hi */-876896931, - /* lo */3238371032 - ], - /* int64 */[ - /* hi */1654270250, - /* lo */914150663 - ], - /* int64 */[ - /* hi */-1856437926, - /* lo */812702999 - ], - /* int64 */[ - /* hi */355462360, - /* lo */4144912697 - ], - /* int64 */[ - /* hi */1731405415, - /* lo */4290775857 - ], - /* int64 */[ - /* hi */-1900787065, - /* lo */1750603025 - ], - /* int64 */[ - /* hi */-619958771, - /* lo */1694076839 - ], - /* int64 */[ - /* hi */1203062813, - /* lo */3204075428 - ] -]; +var ReCrypt_Sha384_Process = require("./Sha384/ReCrypt_Sha384_Process.bs.js"); +var ReCrypt_Sha384_Preprocess = require("./Sha384/ReCrypt_Sha384_Preprocess.bs.js"); function make(message) { var messageBytes = Bytes.of_string(message); - var message$1 = ReCrypt_Preprocess.Sha384_512.pad(messageBytes); - var chunks = message$1.length / 128 | 0; - var a = Caml_array.caml_array_get(initialHash, 0); - var b = Caml_array.caml_array_get(initialHash, 1); - var c = Caml_array.caml_array_get(initialHash, 2); - var d = Caml_array.caml_array_get(initialHash, 3); - var e = Caml_array.caml_array_get(initialHash, 4); - var f = Caml_array.caml_array_get(initialHash, 5); - var g = Caml_array.caml_array_get(initialHash, 6); - var h = Caml_array.caml_array_get(initialHash, 7); - for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ - var w = Caml_array.caml_make_vect(80, Int64.zero); - for(var t = 0; t <= 15; ++t){ - for(var j = 0; j <= 7; ++j){ - var tmp; - var exit = 0; - var some; - try { - some = Caml_bytes.get(message$1, j + ((i << 7) + (t << 3) | 0) | 0); - exit = 1; - } - catch (exn){ - tmp = Int64.zero; - } - if (exit === 1) { - tmp = Caml_int64.of_int32(some & 255); - } - Caml_array.caml_array_set(w, t, Caml_int64.add(Caml_int64.lsl_(Caml_array.caml_array_get(w, t), 8), tmp)); - } - } - for(var t$1 = 16; t$1 <= 79; ++t$1){ - Caml_array.caml_array_set(w, t$1, Caml_int64.add(Caml_int64.add(Caml_int64.add(ReCrypt_Functions_SHA2.Int64.sigma1(Caml_array.caml_array_get(w, t$1 - 2 | 0)), Caml_array.caml_array_get(w, t$1 - 7 | 0)), ReCrypt_Functions_SHA2.Int64.sigma0(Caml_array.caml_array_get(w, t$1 - 15 | 0))), Caml_array.caml_array_get(w, t$1 - 16 | 0))); - } - var originalA = a; - var originalB = b; - var originalC = c; - var originalD = d; - var originalE = e; - var originalF = f; - var originalG = g; - var originalH = h; - for(var t$2 = 0; t$2 <= 79; ++t$2){ - var temp1 = Caml_int64.add(Caml_int64.add(Caml_int64.add(Caml_int64.add(h, ReCrypt_Functions_SHA2.Int64.sum1(e)), ReCrypt_Functions_SHA2.Int64.change(e, f, g)), Caml_array.caml_array_get(constants, t$2)), Caml_array.caml_array_get(w, t$2)); - var temp2 = Caml_int64.add(ReCrypt_Functions_SHA2.Int64.sum0(a), ReCrypt_Functions_SHA2.Int64.majority(a, b, c)); - h = g; - g = f; - f = e; - e = Caml_int64.add(d, temp1); - d = c; - c = b; - b = a; - a = Caml_int64.add(temp1, temp2); - } - a = Caml_int64.add(originalA, a); - b = Caml_int64.add(originalB, b); - c = Caml_int64.add(originalC, c); - d = Caml_int64.add(originalD, d); - e = Caml_int64.add(originalE, e); - f = Caml_int64.add(originalF, f); - g = Caml_int64.add(originalG, g); - h = Caml_int64.add(originalH, h); - } - var sha384raw = Bytes.make(48, Char.chr(0)); - ReCrypt_Utils.append64(sha384raw, a, 0); - ReCrypt_Utils.append64(sha384raw, b, 8); - ReCrypt_Utils.append64(sha384raw, c, 16); - ReCrypt_Utils.append64(sha384raw, d, 24); - ReCrypt_Utils.append64(sha384raw, e, 32); - ReCrypt_Utils.append64(sha384raw, f, 40); - return ReCrypt_Utils.stringToHex(Bytes.to_string(sha384raw)); + return ReCrypt_Sha384_Process.make(ReCrypt_Sha384_Preprocess.pad(messageBytes)); } +var Preprocess = /* alias */0; + +var Process = /* alias */0; + +exports.Preprocess = Preprocess; +exports.Process = Process; exports.make = make; /* No side effect */ diff --git a/lib/js/src/ReCrypt/ReCrypt_Sha512.bs.js b/lib/js/src/ReCrypt/ReCrypt_Sha512.bs.js index 1369938..6427e04 100644 --- a/lib/js/src/ReCrypt/ReCrypt_Sha512.bs.js +++ b/lib/js/src/ReCrypt/ReCrypt_Sha512.bs.js @@ -1,449 +1,20 @@ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; -var Char = require("bs-platform/lib/js/char.js"); var Bytes = require("bs-platform/lib/js/bytes.js"); -var Int64 = require("bs-platform/lib/js/int64.js"); -var Caml_array = require("bs-platform/lib/js/caml_array.js"); -var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); -var Caml_int64 = require("bs-platform/lib/js/caml_int64.js"); -var ReCrypt_Utils = require("./ReCrypt_Utils.bs.js"); -var ReCrypt_Preprocess = require("./ReCrypt_Preprocess.bs.js"); -var ReCrypt_Functions_SHA2 = require("./Functions/ReCrypt_Functions_SHA2.bs.js"); - -var constants = [ - /* int64 */[ - /* hi */1116352408, - /* lo */3609767458 - ], - /* int64 */[ - /* hi */1899447441, - /* lo */602891725 - ], - /* int64 */[ - /* hi */-1245643825, - /* lo */3964484399 - ], - /* int64 */[ - /* hi */-373957723, - /* lo */2173295548 - ], - /* int64 */[ - /* hi */961987163, - /* lo */4081628472 - ], - /* int64 */[ - /* hi */1508970993, - /* lo */3053834265 - ], - /* int64 */[ - /* hi */-1841331548, - /* lo */2937671579 - ], - /* int64 */[ - /* hi */-1424204075, - /* lo */3664609560 - ], - /* int64 */[ - /* hi */-670586216, - /* lo */2734883394 - ], - /* int64 */[ - /* hi */310598401, - /* lo */1164996542 - ], - /* int64 */[ - /* hi */607225278, - /* lo */1323610764 - ], - /* int64 */[ - /* hi */1426881987, - /* lo */3590304994 - ], - /* int64 */[ - /* hi */1925078388, - /* lo */4068182383 - ], - /* int64 */[ - /* hi */-2132889090, - /* lo */991336113 - ], - /* int64 */[ - /* hi */-1680079193, - /* lo */633803317 - ], - /* int64 */[ - /* hi */-1046744716, - /* lo */3479774868 - ], - /* int64 */[ - /* hi */-459576895, - /* lo */2666613458 - ], - /* int64 */[ - /* hi */-272742522, - /* lo */944711139 - ], - /* int64 */[ - /* hi */264347078, - /* lo */2341262773 - ], - /* int64 */[ - /* hi */604807628, - /* lo */2007800933 - ], - /* int64 */[ - /* hi */770255983, - /* lo */1495990901 - ], - /* int64 */[ - /* hi */1249150122, - /* lo */1856431235 - ], - /* int64 */[ - /* hi */1555081692, - /* lo */3175218132 - ], - /* int64 */[ - /* hi */1996064986, - /* lo */2198950837 - ], - /* int64 */[ - /* hi */-1740746414, - /* lo */3999719339 - ], - /* int64 */[ - /* hi */-1473132947, - /* lo */766784016 - ], - /* int64 */[ - /* hi */-1341970488, - /* lo */2566594879 - ], - /* int64 */[ - /* hi */-1084653625, - /* lo */3203337956 - ], - /* int64 */[ - /* hi */-958395405, - /* lo */1034457026 - ], - /* int64 */[ - /* hi */-710438585, - /* lo */2466948901 - ], - /* int64 */[ - /* hi */113926993, - /* lo */3758326383 - ], - /* int64 */[ - /* hi */338241895, - /* lo */168717936 - ], - /* int64 */[ - /* hi */666307205, - /* lo */1188179964 - ], - /* int64 */[ - /* hi */773529912, - /* lo */1546045734 - ], - /* int64 */[ - /* hi */1294757372, - /* lo */1522805485 - ], - /* int64 */[ - /* hi */1396182291, - /* lo */2643833823 - ], - /* int64 */[ - /* hi */1695183700, - /* lo */2343527390 - ], - /* int64 */[ - /* hi */1986661051, - /* lo */1014477480 - ], - /* int64 */[ - /* hi */-2117940946, - /* lo */1206759142 - ], - /* int64 */[ - /* hi */-1838011259, - /* lo */344077627 - ], - /* int64 */[ - /* hi */-1564481375, - /* lo */1290863460 - ], - /* int64 */[ - /* hi */-1474664885, - /* lo */3158454273 - ], - /* int64 */[ - /* hi */-1035236496, - /* lo */3505952657 - ], - /* int64 */[ - /* hi */-949202525, - /* lo */106217008 - ], - /* int64 */[ - /* hi */-778901479, - /* lo */3606008344 - ], - /* int64 */[ - /* hi */-694614492, - /* lo */1432725776 - ], - /* int64 */[ - /* hi */-200395387, - /* lo */1467031594 - ], - /* int64 */[ - /* hi */275423344, - /* lo */851169720 - ], - /* int64 */[ - /* hi */430227734, - /* lo */3100823752 - ], - /* int64 */[ - /* hi */506948616, - /* lo */1363258195 - ], - /* int64 */[ - /* hi */659060556, - /* lo */3750685593 - ], - /* int64 */[ - /* hi */883997877, - /* lo */3785050280 - ], - /* int64 */[ - /* hi */958139571, - /* lo */3318307427 - ], - /* int64 */[ - /* hi */1322822218, - /* lo */3812723403 - ], - /* int64 */[ - /* hi */1537002063, - /* lo */2003034995 - ], - /* int64 */[ - /* hi */1747873779, - /* lo */3602036899 - ], - /* int64 */[ - /* hi */1955562222, - /* lo */1575990012 - ], - /* int64 */[ - /* hi */2024104815, - /* lo */1125592928 - ], - /* int64 */[ - /* hi */-2067236844, - /* lo */2716904306 - ], - /* int64 */[ - /* hi */-1933114872, - /* lo */442776044 - ], - /* int64 */[ - /* hi */-1866530822, - /* lo */593698344 - ], - /* int64 */[ - /* hi */-1538233109, - /* lo */3733110249 - ], - /* int64 */[ - /* hi */-1090935817, - /* lo */2999351573 - ], - /* int64 */[ - /* hi */-965641998, - /* lo */3815920427 - ], - /* int64 */[ - /* hi */-903397682, - /* lo */3928383900 - ], - /* int64 */[ - /* hi */-779700025, - /* lo */566280711 - ], - /* int64 */[ - /* hi */-354779690, - /* lo */3454069534 - ], - /* int64 */[ - /* hi */-176337025, - /* lo */4000239992 - ], - /* int64 */[ - /* hi */116418474, - /* lo */1914138554 - ], - /* int64 */[ - /* hi */174292421, - /* lo */2731055270 - ], - /* int64 */[ - /* hi */289380356, - /* lo */3203993006 - ], - /* int64 */[ - /* hi */460393269, - /* lo */320620315 - ], - /* int64 */[ - /* hi */685471733, - /* lo */587496836 - ], - /* int64 */[ - /* hi */852142971, - /* lo */1086792851 - ], - /* int64 */[ - /* hi */1017036298, - /* lo */365543100 - ], - /* int64 */[ - /* hi */1126000580, - /* lo */2618297676 - ], - /* int64 */[ - /* hi */1288033470, - /* lo */3409855158 - ], - /* int64 */[ - /* hi */1501505948, - /* lo */4234509866 - ], - /* int64 */[ - /* hi */1607167915, - /* lo */987167468 - ], - /* int64 */[ - /* hi */1816402316, - /* lo */1246189591 - ] -]; - -var initialHash = [ - /* int64 */[ - /* hi */1779033703, - /* lo */4089235720 - ], - /* int64 */[ - /* hi */-1150833019, - /* lo */2227873595 - ], - /* int64 */[ - /* hi */1013904242, - /* lo */4271175723 - ], - /* int64 */[ - /* hi */-1521486534, - /* lo */1595750129 - ], - /* int64 */[ - /* hi */1359893119, - /* lo */2917565137 - ], - /* int64 */[ - /* hi */-1694144372, - /* lo */725511199 - ], - /* int64 */[ - /* hi */528734635, - /* lo */4215389547 - ], - /* int64 */[ - /* hi */1541459225, - /* lo */327033209 - ] -]; +var ReCrypt_Sha512_Process = require("./Sha512/ReCrypt_Sha512_Process.bs.js"); +var ReCrypt_Sha512_Preprocess = require("./Sha512/ReCrypt_Sha512_Preprocess.bs.js"); function make(message) { var messageBytes = Bytes.of_string(message); - var message$1 = ReCrypt_Preprocess.Sha384_512.pad(messageBytes); - var chunks = message$1.length / 128 | 0; - var a = Caml_array.caml_array_get(initialHash, 0); - var b = Caml_array.caml_array_get(initialHash, 1); - var c = Caml_array.caml_array_get(initialHash, 2); - var d = Caml_array.caml_array_get(initialHash, 3); - var e = Caml_array.caml_array_get(initialHash, 4); - var f = Caml_array.caml_array_get(initialHash, 5); - var g = Caml_array.caml_array_get(initialHash, 6); - var h = Caml_array.caml_array_get(initialHash, 7); - for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ - var w = Caml_array.caml_make_vect(80, Int64.zero); - for(var t = 0; t <= 15; ++t){ - for(var j = 0; j <= 7; ++j){ - var tmp; - var exit = 0; - var some; - try { - some = Caml_bytes.get(message$1, j + ((i << 7) + (t << 3) | 0) | 0); - exit = 1; - } - catch (exn){ - tmp = Int64.zero; - } - if (exit === 1) { - tmp = Caml_int64.of_int32(some & 255); - } - Caml_array.caml_array_set(w, t, Caml_int64.add(Caml_int64.lsl_(Caml_array.caml_array_get(w, t), 8), tmp)); - } - } - for(var t$1 = 16; t$1 <= 79; ++t$1){ - Caml_array.caml_array_set(w, t$1, Caml_int64.add(Caml_int64.add(Caml_int64.add(ReCrypt_Functions_SHA2.Int64.sigma1(Caml_array.caml_array_get(w, t$1 - 2 | 0)), Caml_array.caml_array_get(w, t$1 - 7 | 0)), ReCrypt_Functions_SHA2.Int64.sigma0(Caml_array.caml_array_get(w, t$1 - 15 | 0))), Caml_array.caml_array_get(w, t$1 - 16 | 0))); - } - var originalA = a; - var originalB = b; - var originalC = c; - var originalD = d; - var originalE = e; - var originalF = f; - var originalG = g; - var originalH = h; - for(var t$2 = 0; t$2 <= 79; ++t$2){ - var temp1 = Caml_int64.add(Caml_int64.add(Caml_int64.add(Caml_int64.add(h, ReCrypt_Functions_SHA2.Int64.sum1(e)), ReCrypt_Functions_SHA2.Int64.change(e, f, g)), Caml_array.caml_array_get(constants, t$2)), Caml_array.caml_array_get(w, t$2)); - var temp2 = Caml_int64.add(ReCrypt_Functions_SHA2.Int64.sum0(a), ReCrypt_Functions_SHA2.Int64.majority(a, b, c)); - h = g; - g = f; - f = e; - e = Caml_int64.add(d, temp1); - d = c; - c = b; - b = a; - a = Caml_int64.add(temp1, temp2); - } - a = Caml_int64.add(originalA, a); - b = Caml_int64.add(originalB, b); - c = Caml_int64.add(originalC, c); - d = Caml_int64.add(originalD, d); - e = Caml_int64.add(originalE, e); - f = Caml_int64.add(originalF, f); - g = Caml_int64.add(originalG, g); - h = Caml_int64.add(originalH, h); - } - var sha512raw = Bytes.make(64, Char.chr(0)); - ReCrypt_Utils.append64(sha512raw, a, 0); - ReCrypt_Utils.append64(sha512raw, b, 8); - ReCrypt_Utils.append64(sha512raw, c, 16); - ReCrypt_Utils.append64(sha512raw, d, 24); - ReCrypt_Utils.append64(sha512raw, e, 32); - ReCrypt_Utils.append64(sha512raw, f, 40); - ReCrypt_Utils.append64(sha512raw, g, 48); - ReCrypt_Utils.append64(sha512raw, h, 56); - return ReCrypt_Utils.stringToHex(Bytes.to_string(sha512raw)); + return ReCrypt_Sha512_Process.make(ReCrypt_Sha512_Preprocess.pad(messageBytes)); } +var Preprocess = /* alias */0; + +var Process = /* alias */0; + +exports.Preprocess = Preprocess; +exports.Process = Process; exports.make = make; /* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.bs.js b/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.bs.js new file mode 100644 index 0000000..9519a12 --- /dev/null +++ b/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.bs.js @@ -0,0 +1,29 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + + +function k(t) { + if (t >= 0 && t <= 19) { + return 1518500249; + } else if (t >= 20 && t <= 39) { + return 1859775393; + } else if (t >= 40 && t <= 59) { + return -1894007588; + } else if (t >= 60 && t <= 79) { + return -899497514; + } else { + return 0; + } +} + +var initialHash = [ + 1732584193, + -271733879, + -1732584194, + 271733878, + -1009589776 +]; + +exports.k = k; +exports.initialHash = initialHash; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.bs.js b/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.bs.js new file mode 100644 index 0000000..da36e0a --- /dev/null +++ b/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.bs.js @@ -0,0 +1,32 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); + +function pad(msgBytes) { + var size = (msgBytes.length + 8 | 0) + 1 | 0; + while(size % 64 !== 0) { + size = size + 1 | 0; + }; + var length = msgBytes.length; + var bytes = Bytes.init(size, (function (index) { + if (index < length) { + return Caml_bytes.get(msgBytes, index); + } else if (index === length) { + return Char.chr(128); + } else { + return Char.chr(0); + } + })); + var va = (length << 3); + for(var i = 1; i <= 15; ++i){ + bytes[bytes.length - i | 0] = Char.chr(va & 255); + va = (va >> 8); + } + return bytes; +} + +exports.pad = pad; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Process.bs.js b/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Process.bs.js new file mode 100644 index 0000000..86dfd1e --- /dev/null +++ b/lib/js/src/ReCrypt/Sha1/ReCrypt_Sha1_Process.bs.js @@ -0,0 +1,58 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Int32 = require("bs-platform/lib/js/int32.js"); +var Caml_array = require("bs-platform/lib/js/caml_array.js"); +var ReCrypt_Utils = require("../ReCrypt_Utils.bs.js"); +var ReCrypt_Functions_SHA1 = require("../Functions/ReCrypt_Functions_SHA1.bs.js"); +var ReCrypt_Sha1_Constants = require("./ReCrypt_Sha1_Constants.bs.js"); + +function make(message) { + var chunks = ((message.length + 8 | 0) >> 6); + var a = Caml_array.caml_array_get(ReCrypt_Sha1_Constants.initialHash, 0); + var b = Caml_array.caml_array_get(ReCrypt_Sha1_Constants.initialHash, 1); + var c = Caml_array.caml_array_get(ReCrypt_Sha1_Constants.initialHash, 2); + var d = Caml_array.caml_array_get(ReCrypt_Sha1_Constants.initialHash, 3); + var e = Caml_array.caml_array_get(ReCrypt_Sha1_Constants.initialHash, 4); + for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ + var w = Caml_array.caml_make_vect(80, Int32.zero); + for(var t = 0; t <= 15; ++t){ + Caml_array.caml_array_set(w, t, (message[(i << 6) + (t << 2) | 0] << 24) & -16777216); + Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message[((i << 6) + (t << 2) | 0) + 1 | 0] << 16) & 16711680); + Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message[((i << 6) + (t << 2) | 0) + 2 | 0] << 8) & 65280 | message[((i << 6) + (t << 2) | 0) + 3 | 0] & 255); + } + for(var t$1 = 16; t$1 <= 79; ++t$1){ + Caml_array.caml_array_set(w, t$1, ReCrypt_Functions_SHA1.rotl(Caml_array.caml_array_get(w, t$1 - 3 | 0) ^ Caml_array.caml_array_get(w, t$1 - 8 | 0) ^ Caml_array.caml_array_get(w, t$1 - 14 | 0) ^ Caml_array.caml_array_get(w, t$1 - 16 | 0), 1)); + } + var originalA = a; + var originalB = b; + var originalC = c; + var originalD = d; + var originalE = e; + for(var t$2 = 0; t$2 <= 79; ++t$2){ + var temp = (((ReCrypt_Functions_SHA1.rotl(a, 5) + ReCrypt_Functions_SHA1.f(t$2, b, c, d) | 0) + e | 0) + ReCrypt_Sha1_Constants.k(t$2) | 0) + Caml_array.caml_array_get(w, t$2) | 0; + e = d; + d = c; + c = ReCrypt_Functions_SHA1.rotl(b, 30); + b = a; + a = temp; + } + a = originalA + a | 0; + b = originalB + b | 0; + c = originalC + c | 0; + d = originalD + d | 0; + e = originalE + e | 0; + } + var sha1raw = Bytes.make(20, Char.chr(0)); + ReCrypt_Utils.append32(sha1raw, a, 0); + ReCrypt_Utils.append32(sha1raw, b, 4); + ReCrypt_Utils.append32(sha1raw, c, 8); + ReCrypt_Utils.append32(sha1raw, d, 12); + ReCrypt_Utils.append32(sha1raw, e, 16); + return ReCrypt_Utils.stringToHex(Bytes.to_string(sha1raw)); +} + +exports.make = make; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Constants.bs.js b/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Constants.bs.js new file mode 100644 index 0000000..62223b3 --- /dev/null +++ b/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Constants.bs.js @@ -0,0 +1,85 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + + +var k = [ + 1116352408, + 1899447441, + -1245643825, + -373957723, + 961987163, + 1508970993, + -1841331548, + -1424204075, + -670586216, + 310598401, + 607225278, + 1426881987, + 1925078388, + -2132889090, + -1680079193, + -1046744716, + -459576895, + -272742522, + 264347078, + 604807628, + 770255983, + 1249150122, + 1555081692, + 1996064986, + -1740746414, + -1473132947, + -1341970488, + -1084653625, + -958395405, + -710438585, + 113926993, + 338241895, + 666307205, + 773529912, + 1294757372, + 1396182291, + 1695183700, + 1986661051, + -2117940946, + -1838011259, + -1564481375, + -1474664885, + -1035236496, + -949202525, + -778901479, + -694614492, + -200395387, + 275423344, + 430227734, + 506948616, + 659060556, + 883997877, + 958139571, + 1322822218, + 1537002063, + 1747873779, + 1955562222, + 2024104815, + -2067236844, + -1933114872, + -1866530822, + -1538233109, + -1090935817, + -965641998 +]; + +var initialHash = [ + -1056596264, + 914150663, + 812702999, + -150054599, + -4191439, + 1750603025, + 1694076839, + -1090891868 +]; + +exports.k = k; +exports.initialHash = initialHash; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Preprocess.bs.js b/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Preprocess.bs.js new file mode 100644 index 0000000..da36e0a --- /dev/null +++ b/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Preprocess.bs.js @@ -0,0 +1,32 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); + +function pad(msgBytes) { + var size = (msgBytes.length + 8 | 0) + 1 | 0; + while(size % 64 !== 0) { + size = size + 1 | 0; + }; + var length = msgBytes.length; + var bytes = Bytes.init(size, (function (index) { + if (index < length) { + return Caml_bytes.get(msgBytes, index); + } else if (index === length) { + return Char.chr(128); + } else { + return Char.chr(0); + } + })); + var va = (length << 3); + for(var i = 1; i <= 15; ++i){ + bytes[bytes.length - i | 0] = Char.chr(va & 255); + va = (va >> 8); + } + return bytes; +} + +exports.pad = pad; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Process.bs.js b/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Process.bs.js new file mode 100644 index 0000000..abfaa9c --- /dev/null +++ b/lib/js/src/ReCrypt/Sha224/ReCrypt_Sha224_Process.bs.js @@ -0,0 +1,73 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Int32 = require("bs-platform/lib/js/int32.js"); +var Caml_array = require("bs-platform/lib/js/caml_array.js"); +var ReCrypt_Utils = require("../ReCrypt_Utils.bs.js"); +var ReCrypt_Functions_SHA2 = require("../Functions/ReCrypt_Functions_SHA2.bs.js"); +var ReCrypt_Sha224_Constants = require("./ReCrypt_Sha224_Constants.bs.js"); + +function make(message) { + var chunks = ((message.length + 8 | 0) >> 6); + var a = Caml_array.caml_array_get(ReCrypt_Sha224_Constants.initialHash, 0); + var b = Caml_array.caml_array_get(ReCrypt_Sha224_Constants.initialHash, 1); + var c = Caml_array.caml_array_get(ReCrypt_Sha224_Constants.initialHash, 2); + var d = Caml_array.caml_array_get(ReCrypt_Sha224_Constants.initialHash, 3); + var e = Caml_array.caml_array_get(ReCrypt_Sha224_Constants.initialHash, 4); + var f = Caml_array.caml_array_get(ReCrypt_Sha224_Constants.initialHash, 5); + var g = Caml_array.caml_array_get(ReCrypt_Sha224_Constants.initialHash, 6); + var h = Caml_array.caml_array_get(ReCrypt_Sha224_Constants.initialHash, 7); + for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ + var w = Caml_array.caml_make_vect(64, Int32.zero); + for(var t = 0; t <= 15; ++t){ + Caml_array.caml_array_set(w, t, (message[(i << 6) + (t << 2) | 0] << 24) & -16777216); + Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message[((i << 6) + (t << 2) | 0) + 1 | 0] << 16) & 16711680); + Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message[((i << 6) + (t << 2) | 0) + 2 | 0] << 8) & 65280 | message[((i << 6) + (t << 2) | 0) + 3 | 0] & 255); + } + for(var t$1 = 16; t$1 <= 63; ++t$1){ + Caml_array.caml_array_set(w, t$1, ((ReCrypt_Functions_SHA2.Int32.sigma1(Caml_array.caml_array_get(w, t$1 - 2 | 0)) + Caml_array.caml_array_get(w, t$1 - 7 | 0) | 0) + ReCrypt_Functions_SHA2.Int32.sigma0(Caml_array.caml_array_get(w, t$1 - 15 | 0)) | 0) + Caml_array.caml_array_get(w, t$1 - 16 | 0) | 0); + } + var originalA = a; + var originalB = b; + var originalC = c; + var originalD = d; + var originalE = e; + var originalF = f; + var originalG = g; + var originalH = h; + for(var t$2 = 0; t$2 <= 63; ++t$2){ + var temp1 = (((h + ReCrypt_Functions_SHA2.Int32.sum1(e) | 0) + ReCrypt_Functions_SHA2.Int32.change(e, f, g) | 0) + Caml_array.caml_array_get(ReCrypt_Sha224_Constants.k, t$2) | 0) + Caml_array.caml_array_get(w, t$2) | 0; + var temp2 = ReCrypt_Functions_SHA2.Int32.sum0(a) + ReCrypt_Functions_SHA2.Int32.majority(a, b, c) | 0; + h = g; + g = f; + f = e; + e = d + temp1 | 0; + d = c; + c = b; + b = a; + a = temp1 + temp2 | 0; + } + a = originalA + a | 0; + b = originalB + b | 0; + c = originalC + c | 0; + d = originalD + d | 0; + e = originalE + e | 0; + f = originalF + f | 0; + g = originalG + g | 0; + h = originalH + h | 0; + } + var sha224raw = Bytes.make(28, Char.chr(0)); + ReCrypt_Utils.append32(sha224raw, a, 0); + ReCrypt_Utils.append32(sha224raw, b, 4); + ReCrypt_Utils.append32(sha224raw, c, 8); + ReCrypt_Utils.append32(sha224raw, d, 12); + ReCrypt_Utils.append32(sha224raw, e, 16); + ReCrypt_Utils.append32(sha224raw, f, 20); + ReCrypt_Utils.append32(sha224raw, g, 24); + return ReCrypt_Utils.stringToHex(Bytes.to_string(sha224raw)); +} + +exports.make = make; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Constants.bs.js b/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Constants.bs.js new file mode 100644 index 0000000..74a5720 --- /dev/null +++ b/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Constants.bs.js @@ -0,0 +1,85 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + + +var k = [ + 1116352408, + 1899447441, + -1245643825, + -373957723, + 961987163, + 1508970993, + -1841331548, + -1424204075, + -670586216, + 310598401, + 607225278, + 1426881987, + 1925078388, + -2132889090, + -1680079193, + -1046744716, + -459576895, + -272742522, + 264347078, + 604807628, + 770255983, + 1249150122, + 1555081692, + 1996064986, + -1740746414, + -1473132947, + -1341970488, + -1084653625, + -958395405, + -710438585, + 113926993, + 338241895, + 666307205, + 773529912, + 1294757372, + 1396182291, + 1695183700, + 1986661051, + -2117940946, + -1838011259, + -1564481375, + -1474664885, + -1035236496, + -949202525, + -778901479, + -694614492, + -200395387, + 275423344, + 430227734, + 506948616, + 659060556, + 883997877, + 958139571, + 1322822218, + 1537002063, + 1747873779, + 1955562222, + 2024104815, + -2067236844, + -1933114872, + -1866530822, + -1538233109, + -1090935817, + -965641998 +]; + +var initialHash = [ + 1779033703, + -1150833019, + 1013904242, + -1521486534, + 1359893119, + -1694144372, + 528734635, + 1541459225 +]; + +exports.k = k; +exports.initialHash = initialHash; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Preprocess.bs.js b/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Preprocess.bs.js new file mode 100644 index 0000000..da36e0a --- /dev/null +++ b/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Preprocess.bs.js @@ -0,0 +1,32 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); + +function pad(msgBytes) { + var size = (msgBytes.length + 8 | 0) + 1 | 0; + while(size % 64 !== 0) { + size = size + 1 | 0; + }; + var length = msgBytes.length; + var bytes = Bytes.init(size, (function (index) { + if (index < length) { + return Caml_bytes.get(msgBytes, index); + } else if (index === length) { + return Char.chr(128); + } else { + return Char.chr(0); + } + })); + var va = (length << 3); + for(var i = 1; i <= 15; ++i){ + bytes[bytes.length - i | 0] = Char.chr(va & 255); + va = (va >> 8); + } + return bytes; +} + +exports.pad = pad; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Process.bs.js b/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Process.bs.js new file mode 100644 index 0000000..6f0f11b --- /dev/null +++ b/lib/js/src/ReCrypt/Sha256/ReCrypt_Sha256_Process.bs.js @@ -0,0 +1,74 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Int32 = require("bs-platform/lib/js/int32.js"); +var Caml_array = require("bs-platform/lib/js/caml_array.js"); +var ReCrypt_Utils = require("../ReCrypt_Utils.bs.js"); +var ReCrypt_Functions_SHA2 = require("../Functions/ReCrypt_Functions_SHA2.bs.js"); +var ReCrypt_Sha256_Constants = require("./ReCrypt_Sha256_Constants.bs.js"); + +function make(message) { + var chunks = ((message.length + 8 | 0) >> 6); + var a = Caml_array.caml_array_get(ReCrypt_Sha256_Constants.initialHash, 0); + var b = Caml_array.caml_array_get(ReCrypt_Sha256_Constants.initialHash, 1); + var c = Caml_array.caml_array_get(ReCrypt_Sha256_Constants.initialHash, 2); + var d = Caml_array.caml_array_get(ReCrypt_Sha256_Constants.initialHash, 3); + var e = Caml_array.caml_array_get(ReCrypt_Sha256_Constants.initialHash, 4); + var f = Caml_array.caml_array_get(ReCrypt_Sha256_Constants.initialHash, 5); + var g = Caml_array.caml_array_get(ReCrypt_Sha256_Constants.initialHash, 6); + var h = Caml_array.caml_array_get(ReCrypt_Sha256_Constants.initialHash, 7); + for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ + var w = Caml_array.caml_make_vect(64, Int32.zero); + for(var t = 0; t <= 15; ++t){ + Caml_array.caml_array_set(w, t, (message[(i << 6) + (t << 2) | 0] << 24) & -16777216); + Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message[((i << 6) + (t << 2) | 0) + 1 | 0] << 16) & 16711680); + Caml_array.caml_array_set(w, t, Caml_array.caml_array_get(w, t) | (message[((i << 6) + (t << 2) | 0) + 2 | 0] << 8) & 65280 | message[((i << 6) + (t << 2) | 0) + 3 | 0] & 255); + } + for(var t$1 = 16; t$1 <= 63; ++t$1){ + Caml_array.caml_array_set(w, t$1, ((ReCrypt_Functions_SHA2.Int32.sigma1(Caml_array.caml_array_get(w, t$1 - 2 | 0)) + Caml_array.caml_array_get(w, t$1 - 7 | 0) | 0) + ReCrypt_Functions_SHA2.Int32.sigma0(Caml_array.caml_array_get(w, t$1 - 15 | 0)) | 0) + Caml_array.caml_array_get(w, t$1 - 16 | 0) | 0); + } + var originalA = a; + var originalB = b; + var originalC = c; + var originalD = d; + var originalE = e; + var originalF = f; + var originalG = g; + var originalH = h; + for(var t$2 = 0; t$2 <= 63; ++t$2){ + var temp1 = (((h + ReCrypt_Functions_SHA2.Int32.sum1(e) | 0) + ReCrypt_Functions_SHA2.Int32.change(e, f, g) | 0) + Caml_array.caml_array_get(ReCrypt_Sha256_Constants.k, t$2) | 0) + Caml_array.caml_array_get(w, t$2) | 0; + var temp2 = ReCrypt_Functions_SHA2.Int32.sum0(a) + ReCrypt_Functions_SHA2.Int32.majority(a, b, c) | 0; + h = g; + g = f; + f = e; + e = d + temp1 | 0; + d = c; + c = b; + b = a; + a = temp1 + temp2 | 0; + } + a = originalA + a | 0; + b = originalB + b | 0; + c = originalC + c | 0; + d = originalD + d | 0; + e = originalE + e | 0; + f = originalF + f | 0; + g = originalG + g | 0; + h = originalH + h | 0; + } + var sha256raw = Bytes.make(32, Char.chr(0)); + ReCrypt_Utils.append32(sha256raw, a, 0); + ReCrypt_Utils.append32(sha256raw, b, 4); + ReCrypt_Utils.append32(sha256raw, c, 8); + ReCrypt_Utils.append32(sha256raw, d, 12); + ReCrypt_Utils.append32(sha256raw, e, 16); + ReCrypt_Utils.append32(sha256raw, f, 20); + ReCrypt_Utils.append32(sha256raw, g, 24); + ReCrypt_Utils.append32(sha256raw, h, 28); + return ReCrypt_Utils.stringToHex(Bytes.to_string(sha256raw)); +} + +exports.make = make; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Constants.bs.js b/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Constants.bs.js new file mode 100644 index 0000000..03faad7 --- /dev/null +++ b/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Constants.bs.js @@ -0,0 +1,365 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + + +var k = [ + /* int64 */[ + /* hi */1116352408, + /* lo */3609767458 + ], + /* int64 */[ + /* hi */1899447441, + /* lo */602891725 + ], + /* int64 */[ + /* hi */-1245643825, + /* lo */3964484399 + ], + /* int64 */[ + /* hi */-373957723, + /* lo */2173295548 + ], + /* int64 */[ + /* hi */961987163, + /* lo */4081628472 + ], + /* int64 */[ + /* hi */1508970993, + /* lo */3053834265 + ], + /* int64 */[ + /* hi */-1841331548, + /* lo */2937671579 + ], + /* int64 */[ + /* hi */-1424204075, + /* lo */3664609560 + ], + /* int64 */[ + /* hi */-670586216, + /* lo */2734883394 + ], + /* int64 */[ + /* hi */310598401, + /* lo */1164996542 + ], + /* int64 */[ + /* hi */607225278, + /* lo */1323610764 + ], + /* int64 */[ + /* hi */1426881987, + /* lo */3590304994 + ], + /* int64 */[ + /* hi */1925078388, + /* lo */4068182383 + ], + /* int64 */[ + /* hi */-2132889090, + /* lo */991336113 + ], + /* int64 */[ + /* hi */-1680079193, + /* lo */633803317 + ], + /* int64 */[ + /* hi */-1046744716, + /* lo */3479774868 + ], + /* int64 */[ + /* hi */-459576895, + /* lo */2666613458 + ], + /* int64 */[ + /* hi */-272742522, + /* lo */944711139 + ], + /* int64 */[ + /* hi */264347078, + /* lo */2341262773 + ], + /* int64 */[ + /* hi */604807628, + /* lo */2007800933 + ], + /* int64 */[ + /* hi */770255983, + /* lo */1495990901 + ], + /* int64 */[ + /* hi */1249150122, + /* lo */1856431235 + ], + /* int64 */[ + /* hi */1555081692, + /* lo */3175218132 + ], + /* int64 */[ + /* hi */1996064986, + /* lo */2198950837 + ], + /* int64 */[ + /* hi */-1740746414, + /* lo */3999719339 + ], + /* int64 */[ + /* hi */-1473132947, + /* lo */766784016 + ], + /* int64 */[ + /* hi */-1341970488, + /* lo */2566594879 + ], + /* int64 */[ + /* hi */-1084653625, + /* lo */3203337956 + ], + /* int64 */[ + /* hi */-958395405, + /* lo */1034457026 + ], + /* int64 */[ + /* hi */-710438585, + /* lo */2466948901 + ], + /* int64 */[ + /* hi */113926993, + /* lo */3758326383 + ], + /* int64 */[ + /* hi */338241895, + /* lo */168717936 + ], + /* int64 */[ + /* hi */666307205, + /* lo */1188179964 + ], + /* int64 */[ + /* hi */773529912, + /* lo */1546045734 + ], + /* int64 */[ + /* hi */1294757372, + /* lo */1522805485 + ], + /* int64 */[ + /* hi */1396182291, + /* lo */2643833823 + ], + /* int64 */[ + /* hi */1695183700, + /* lo */2343527390 + ], + /* int64 */[ + /* hi */1986661051, + /* lo */1014477480 + ], + /* int64 */[ + /* hi */-2117940946, + /* lo */1206759142 + ], + /* int64 */[ + /* hi */-1838011259, + /* lo */344077627 + ], + /* int64 */[ + /* hi */-1564481375, + /* lo */1290863460 + ], + /* int64 */[ + /* hi */-1474664885, + /* lo */3158454273 + ], + /* int64 */[ + /* hi */-1035236496, + /* lo */3505952657 + ], + /* int64 */[ + /* hi */-949202525, + /* lo */106217008 + ], + /* int64 */[ + /* hi */-778901479, + /* lo */3606008344 + ], + /* int64 */[ + /* hi */-694614492, + /* lo */1432725776 + ], + /* int64 */[ + /* hi */-200395387, + /* lo */1467031594 + ], + /* int64 */[ + /* hi */275423344, + /* lo */851169720 + ], + /* int64 */[ + /* hi */430227734, + /* lo */3100823752 + ], + /* int64 */[ + /* hi */506948616, + /* lo */1363258195 + ], + /* int64 */[ + /* hi */659060556, + /* lo */3750685593 + ], + /* int64 */[ + /* hi */883997877, + /* lo */3785050280 + ], + /* int64 */[ + /* hi */958139571, + /* lo */3318307427 + ], + /* int64 */[ + /* hi */1322822218, + /* lo */3812723403 + ], + /* int64 */[ + /* hi */1537002063, + /* lo */2003034995 + ], + /* int64 */[ + /* hi */1747873779, + /* lo */3602036899 + ], + /* int64 */[ + /* hi */1955562222, + /* lo */1575990012 + ], + /* int64 */[ + /* hi */2024104815, + /* lo */1125592928 + ], + /* int64 */[ + /* hi */-2067236844, + /* lo */2716904306 + ], + /* int64 */[ + /* hi */-1933114872, + /* lo */442776044 + ], + /* int64 */[ + /* hi */-1866530822, + /* lo */593698344 + ], + /* int64 */[ + /* hi */-1538233109, + /* lo */3733110249 + ], + /* int64 */[ + /* hi */-1090935817, + /* lo */2999351573 + ], + /* int64 */[ + /* hi */-965641998, + /* lo */3815920427 + ], + /* int64 */[ + /* hi */-903397682, + /* lo */3928383900 + ], + /* int64 */[ + /* hi */-779700025, + /* lo */566280711 + ], + /* int64 */[ + /* hi */-354779690, + /* lo */3454069534 + ], + /* int64 */[ + /* hi */-176337025, + /* lo */4000239992 + ], + /* int64 */[ + /* hi */116418474, + /* lo */1914138554 + ], + /* int64 */[ + /* hi */174292421, + /* lo */2731055270 + ], + /* int64 */[ + /* hi */289380356, + /* lo */3203993006 + ], + /* int64 */[ + /* hi */460393269, + /* lo */320620315 + ], + /* int64 */[ + /* hi */685471733, + /* lo */587496836 + ], + /* int64 */[ + /* hi */852142971, + /* lo */1086792851 + ], + /* int64 */[ + /* hi */1017036298, + /* lo */365543100 + ], + /* int64 */[ + /* hi */1126000580, + /* lo */2618297676 + ], + /* int64 */[ + /* hi */1288033470, + /* lo */3409855158 + ], + /* int64 */[ + /* hi */1501505948, + /* lo */4234509866 + ], + /* int64 */[ + /* hi */1607167915, + /* lo */987167468 + ], + /* int64 */[ + /* hi */1816402316, + /* lo */1246189591 + ] +]; + +var initialHash = [ + /* int64 */[ + /* hi */-876896931, + /* lo */3238371032 + ], + /* int64 */[ + /* hi */1654270250, + /* lo */914150663 + ], + /* int64 */[ + /* hi */-1856437926, + /* lo */812702999 + ], + /* int64 */[ + /* hi */355462360, + /* lo */4144912697 + ], + /* int64 */[ + /* hi */1731405415, + /* lo */4290775857 + ], + /* int64 */[ + /* hi */-1900787065, + /* lo */1750603025 + ], + /* int64 */[ + /* hi */-619958771, + /* lo */1694076839 + ], + /* int64 */[ + /* hi */1203062813, + /* lo */3204075428 + ] +]; + +exports.k = k; +exports.initialHash = initialHash; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Preprocess.bs.js b/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Preprocess.bs.js new file mode 100644 index 0000000..a053f92 --- /dev/null +++ b/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Preprocess.bs.js @@ -0,0 +1,32 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); + +function pad(msgBytes) { + var size = (msgBytes.length + 16 | 0) + 1 | 0; + while(size % 128 !== 0) { + size = size + 1 | 0; + }; + var length = msgBytes.length; + var bytes = Bytes.init(size, (function (index) { + if (index < length) { + return Caml_bytes.get(msgBytes, index); + } else if (index === length) { + return Char.chr(128); + } else { + return Char.chr(0); + } + })); + var va = (length << 3); + for(var i = 1; i <= 15; ++i){ + bytes[bytes.length - i | 0] = Char.chr(va & 255); + va = (va >> 8); + } + return bytes; +} + +exports.pad = pad; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Process.bs.js b/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Process.bs.js new file mode 100644 index 0000000..47ebde0 --- /dev/null +++ b/lib/js/src/ReCrypt/Sha384/ReCrypt_Sha384_Process.bs.js @@ -0,0 +1,87 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Int64 = require("bs-platform/lib/js/int64.js"); +var Caml_array = require("bs-platform/lib/js/caml_array.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); +var Caml_int64 = require("bs-platform/lib/js/caml_int64.js"); +var ReCrypt_Utils = require("../ReCrypt_Utils.bs.js"); +var ReCrypt_Functions_SHA2 = require("../Functions/ReCrypt_Functions_SHA2.bs.js"); +var ReCrypt_Sha384_Constants = require("./ReCrypt_Sha384_Constants.bs.js"); + +function make(message) { + var chunks = message.length / 128 | 0; + var a = Caml_array.caml_array_get(ReCrypt_Sha384_Constants.initialHash, 0); + var b = Caml_array.caml_array_get(ReCrypt_Sha384_Constants.initialHash, 1); + var c = Caml_array.caml_array_get(ReCrypt_Sha384_Constants.initialHash, 2); + var d = Caml_array.caml_array_get(ReCrypt_Sha384_Constants.initialHash, 3); + var e = Caml_array.caml_array_get(ReCrypt_Sha384_Constants.initialHash, 4); + var f = Caml_array.caml_array_get(ReCrypt_Sha384_Constants.initialHash, 5); + var g = Caml_array.caml_array_get(ReCrypt_Sha384_Constants.initialHash, 6); + var h = Caml_array.caml_array_get(ReCrypt_Sha384_Constants.initialHash, 7); + for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ + var w = Caml_array.caml_make_vect(80, Int64.zero); + for(var t = 0; t <= 15; ++t){ + for(var j = 0; j <= 7; ++j){ + var tmp; + var exit = 0; + var some; + try { + some = Caml_bytes.get(message, j + ((i << 7) + (t << 3) | 0) | 0); + exit = 1; + } + catch (exn){ + tmp = Int64.zero; + } + if (exit === 1) { + tmp = Caml_int64.of_int32(some & 255); + } + Caml_array.caml_array_set(w, t, Caml_int64.add(Caml_int64.lsl_(Caml_array.caml_array_get(w, t), 8), tmp)); + } + } + for(var t$1 = 16; t$1 <= 79; ++t$1){ + Caml_array.caml_array_set(w, t$1, Caml_int64.add(Caml_int64.add(Caml_int64.add(ReCrypt_Functions_SHA2.Int64.sigma1(Caml_array.caml_array_get(w, t$1 - 2 | 0)), Caml_array.caml_array_get(w, t$1 - 7 | 0)), ReCrypt_Functions_SHA2.Int64.sigma0(Caml_array.caml_array_get(w, t$1 - 15 | 0))), Caml_array.caml_array_get(w, t$1 - 16 | 0))); + } + var originalA = a; + var originalB = b; + var originalC = c; + var originalD = d; + var originalE = e; + var originalF = f; + var originalG = g; + var originalH = h; + for(var t$2 = 0; t$2 <= 79; ++t$2){ + var temp1 = Caml_int64.add(Caml_int64.add(Caml_int64.add(Caml_int64.add(h, ReCrypt_Functions_SHA2.Int64.sum1(e)), ReCrypt_Functions_SHA2.Int64.change(e, f, g)), Caml_array.caml_array_get(ReCrypt_Sha384_Constants.k, t$2)), Caml_array.caml_array_get(w, t$2)); + var temp2 = Caml_int64.add(ReCrypt_Functions_SHA2.Int64.sum0(a), ReCrypt_Functions_SHA2.Int64.majority(a, b, c)); + h = g; + g = f; + f = e; + e = Caml_int64.add(d, temp1); + d = c; + c = b; + b = a; + a = Caml_int64.add(temp1, temp2); + } + a = Caml_int64.add(originalA, a); + b = Caml_int64.add(originalB, b); + c = Caml_int64.add(originalC, c); + d = Caml_int64.add(originalD, d); + e = Caml_int64.add(originalE, e); + f = Caml_int64.add(originalF, f); + g = Caml_int64.add(originalG, g); + h = Caml_int64.add(originalH, h); + } + var sha384raw = Bytes.make(48, Char.chr(0)); + ReCrypt_Utils.append64(sha384raw, a, 0); + ReCrypt_Utils.append64(sha384raw, b, 8); + ReCrypt_Utils.append64(sha384raw, c, 16); + ReCrypt_Utils.append64(sha384raw, d, 24); + ReCrypt_Utils.append64(sha384raw, e, 32); + ReCrypt_Utils.append64(sha384raw, f, 40); + return ReCrypt_Utils.stringToHex(Bytes.to_string(sha384raw)); +} + +exports.make = make; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Constants.bs.js b/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Constants.bs.js new file mode 100644 index 0000000..272573c --- /dev/null +++ b/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Constants.bs.js @@ -0,0 +1,365 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + + +var k = [ + /* int64 */[ + /* hi */1116352408, + /* lo */3609767458 + ], + /* int64 */[ + /* hi */1899447441, + /* lo */602891725 + ], + /* int64 */[ + /* hi */-1245643825, + /* lo */3964484399 + ], + /* int64 */[ + /* hi */-373957723, + /* lo */2173295548 + ], + /* int64 */[ + /* hi */961987163, + /* lo */4081628472 + ], + /* int64 */[ + /* hi */1508970993, + /* lo */3053834265 + ], + /* int64 */[ + /* hi */-1841331548, + /* lo */2937671579 + ], + /* int64 */[ + /* hi */-1424204075, + /* lo */3664609560 + ], + /* int64 */[ + /* hi */-670586216, + /* lo */2734883394 + ], + /* int64 */[ + /* hi */310598401, + /* lo */1164996542 + ], + /* int64 */[ + /* hi */607225278, + /* lo */1323610764 + ], + /* int64 */[ + /* hi */1426881987, + /* lo */3590304994 + ], + /* int64 */[ + /* hi */1925078388, + /* lo */4068182383 + ], + /* int64 */[ + /* hi */-2132889090, + /* lo */991336113 + ], + /* int64 */[ + /* hi */-1680079193, + /* lo */633803317 + ], + /* int64 */[ + /* hi */-1046744716, + /* lo */3479774868 + ], + /* int64 */[ + /* hi */-459576895, + /* lo */2666613458 + ], + /* int64 */[ + /* hi */-272742522, + /* lo */944711139 + ], + /* int64 */[ + /* hi */264347078, + /* lo */2341262773 + ], + /* int64 */[ + /* hi */604807628, + /* lo */2007800933 + ], + /* int64 */[ + /* hi */770255983, + /* lo */1495990901 + ], + /* int64 */[ + /* hi */1249150122, + /* lo */1856431235 + ], + /* int64 */[ + /* hi */1555081692, + /* lo */3175218132 + ], + /* int64 */[ + /* hi */1996064986, + /* lo */2198950837 + ], + /* int64 */[ + /* hi */-1740746414, + /* lo */3999719339 + ], + /* int64 */[ + /* hi */-1473132947, + /* lo */766784016 + ], + /* int64 */[ + /* hi */-1341970488, + /* lo */2566594879 + ], + /* int64 */[ + /* hi */-1084653625, + /* lo */3203337956 + ], + /* int64 */[ + /* hi */-958395405, + /* lo */1034457026 + ], + /* int64 */[ + /* hi */-710438585, + /* lo */2466948901 + ], + /* int64 */[ + /* hi */113926993, + /* lo */3758326383 + ], + /* int64 */[ + /* hi */338241895, + /* lo */168717936 + ], + /* int64 */[ + /* hi */666307205, + /* lo */1188179964 + ], + /* int64 */[ + /* hi */773529912, + /* lo */1546045734 + ], + /* int64 */[ + /* hi */1294757372, + /* lo */1522805485 + ], + /* int64 */[ + /* hi */1396182291, + /* lo */2643833823 + ], + /* int64 */[ + /* hi */1695183700, + /* lo */2343527390 + ], + /* int64 */[ + /* hi */1986661051, + /* lo */1014477480 + ], + /* int64 */[ + /* hi */-2117940946, + /* lo */1206759142 + ], + /* int64 */[ + /* hi */-1838011259, + /* lo */344077627 + ], + /* int64 */[ + /* hi */-1564481375, + /* lo */1290863460 + ], + /* int64 */[ + /* hi */-1474664885, + /* lo */3158454273 + ], + /* int64 */[ + /* hi */-1035236496, + /* lo */3505952657 + ], + /* int64 */[ + /* hi */-949202525, + /* lo */106217008 + ], + /* int64 */[ + /* hi */-778901479, + /* lo */3606008344 + ], + /* int64 */[ + /* hi */-694614492, + /* lo */1432725776 + ], + /* int64 */[ + /* hi */-200395387, + /* lo */1467031594 + ], + /* int64 */[ + /* hi */275423344, + /* lo */851169720 + ], + /* int64 */[ + /* hi */430227734, + /* lo */3100823752 + ], + /* int64 */[ + /* hi */506948616, + /* lo */1363258195 + ], + /* int64 */[ + /* hi */659060556, + /* lo */3750685593 + ], + /* int64 */[ + /* hi */883997877, + /* lo */3785050280 + ], + /* int64 */[ + /* hi */958139571, + /* lo */3318307427 + ], + /* int64 */[ + /* hi */1322822218, + /* lo */3812723403 + ], + /* int64 */[ + /* hi */1537002063, + /* lo */2003034995 + ], + /* int64 */[ + /* hi */1747873779, + /* lo */3602036899 + ], + /* int64 */[ + /* hi */1955562222, + /* lo */1575990012 + ], + /* int64 */[ + /* hi */2024104815, + /* lo */1125592928 + ], + /* int64 */[ + /* hi */-2067236844, + /* lo */2716904306 + ], + /* int64 */[ + /* hi */-1933114872, + /* lo */442776044 + ], + /* int64 */[ + /* hi */-1866530822, + /* lo */593698344 + ], + /* int64 */[ + /* hi */-1538233109, + /* lo */3733110249 + ], + /* int64 */[ + /* hi */-1090935817, + /* lo */2999351573 + ], + /* int64 */[ + /* hi */-965641998, + /* lo */3815920427 + ], + /* int64 */[ + /* hi */-903397682, + /* lo */3928383900 + ], + /* int64 */[ + /* hi */-779700025, + /* lo */566280711 + ], + /* int64 */[ + /* hi */-354779690, + /* lo */3454069534 + ], + /* int64 */[ + /* hi */-176337025, + /* lo */4000239992 + ], + /* int64 */[ + /* hi */116418474, + /* lo */1914138554 + ], + /* int64 */[ + /* hi */174292421, + /* lo */2731055270 + ], + /* int64 */[ + /* hi */289380356, + /* lo */3203993006 + ], + /* int64 */[ + /* hi */460393269, + /* lo */320620315 + ], + /* int64 */[ + /* hi */685471733, + /* lo */587496836 + ], + /* int64 */[ + /* hi */852142971, + /* lo */1086792851 + ], + /* int64 */[ + /* hi */1017036298, + /* lo */365543100 + ], + /* int64 */[ + /* hi */1126000580, + /* lo */2618297676 + ], + /* int64 */[ + /* hi */1288033470, + /* lo */3409855158 + ], + /* int64 */[ + /* hi */1501505948, + /* lo */4234509866 + ], + /* int64 */[ + /* hi */1607167915, + /* lo */987167468 + ], + /* int64 */[ + /* hi */1816402316, + /* lo */1246189591 + ] +]; + +var initialHash = [ + /* int64 */[ + /* hi */1779033703, + /* lo */4089235720 + ], + /* int64 */[ + /* hi */-1150833019, + /* lo */2227873595 + ], + /* int64 */[ + /* hi */1013904242, + /* lo */4271175723 + ], + /* int64 */[ + /* hi */-1521486534, + /* lo */1595750129 + ], + /* int64 */[ + /* hi */1359893119, + /* lo */2917565137 + ], + /* int64 */[ + /* hi */-1694144372, + /* lo */725511199 + ], + /* int64 */[ + /* hi */528734635, + /* lo */4215389547 + ], + /* int64 */[ + /* hi */1541459225, + /* lo */327033209 + ] +]; + +exports.k = k; +exports.initialHash = initialHash; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Preprocess.bs.js b/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Preprocess.bs.js new file mode 100644 index 0000000..a053f92 --- /dev/null +++ b/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Preprocess.bs.js @@ -0,0 +1,32 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); + +function pad(msgBytes) { + var size = (msgBytes.length + 16 | 0) + 1 | 0; + while(size % 128 !== 0) { + size = size + 1 | 0; + }; + var length = msgBytes.length; + var bytes = Bytes.init(size, (function (index) { + if (index < length) { + return Caml_bytes.get(msgBytes, index); + } else if (index === length) { + return Char.chr(128); + } else { + return Char.chr(0); + } + })); + var va = (length << 3); + for(var i = 1; i <= 15; ++i){ + bytes[bytes.length - i | 0] = Char.chr(va & 255); + va = (va >> 8); + } + return bytes; +} + +exports.pad = pad; +/* No side effect */ diff --git a/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Process.bs.js b/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Process.bs.js new file mode 100644 index 0000000..321a241 --- /dev/null +++ b/lib/js/src/ReCrypt/Sha512/ReCrypt_Sha512_Process.bs.js @@ -0,0 +1,89 @@ +// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE +'use strict'; + +var Char = require("bs-platform/lib/js/char.js"); +var Bytes = require("bs-platform/lib/js/bytes.js"); +var Int64 = require("bs-platform/lib/js/int64.js"); +var Caml_array = require("bs-platform/lib/js/caml_array.js"); +var Caml_bytes = require("bs-platform/lib/js/caml_bytes.js"); +var Caml_int64 = require("bs-platform/lib/js/caml_int64.js"); +var ReCrypt_Utils = require("../ReCrypt_Utils.bs.js"); +var ReCrypt_Functions_SHA2 = require("../Functions/ReCrypt_Functions_SHA2.bs.js"); +var ReCrypt_Sha512_Constants = require("./ReCrypt_Sha512_Constants.bs.js"); + +function make(message) { + var chunks = message.length / 128 | 0; + var a = Caml_array.caml_array_get(ReCrypt_Sha512_Constants.initialHash, 0); + var b = Caml_array.caml_array_get(ReCrypt_Sha512_Constants.initialHash, 1); + var c = Caml_array.caml_array_get(ReCrypt_Sha512_Constants.initialHash, 2); + var d = Caml_array.caml_array_get(ReCrypt_Sha512_Constants.initialHash, 3); + var e = Caml_array.caml_array_get(ReCrypt_Sha512_Constants.initialHash, 4); + var f = Caml_array.caml_array_get(ReCrypt_Sha512_Constants.initialHash, 5); + var g = Caml_array.caml_array_get(ReCrypt_Sha512_Constants.initialHash, 6); + var h = Caml_array.caml_array_get(ReCrypt_Sha512_Constants.initialHash, 7); + for(var i = 0 ,i_finish = chunks - 1 | 0; i <= i_finish; ++i){ + var w = Caml_array.caml_make_vect(80, Int64.zero); + for(var t = 0; t <= 15; ++t){ + for(var j = 0; j <= 7; ++j){ + var tmp; + var exit = 0; + var some; + try { + some = Caml_bytes.get(message, j + ((i << 7) + (t << 3) | 0) | 0); + exit = 1; + } + catch (exn){ + tmp = Int64.zero; + } + if (exit === 1) { + tmp = Caml_int64.of_int32(some & 255); + } + Caml_array.caml_array_set(w, t, Caml_int64.add(Caml_int64.lsl_(Caml_array.caml_array_get(w, t), 8), tmp)); + } + } + for(var t$1 = 16; t$1 <= 79; ++t$1){ + Caml_array.caml_array_set(w, t$1, Caml_int64.add(Caml_int64.add(Caml_int64.add(ReCrypt_Functions_SHA2.Int64.sigma1(Caml_array.caml_array_get(w, t$1 - 2 | 0)), Caml_array.caml_array_get(w, t$1 - 7 | 0)), ReCrypt_Functions_SHA2.Int64.sigma0(Caml_array.caml_array_get(w, t$1 - 15 | 0))), Caml_array.caml_array_get(w, t$1 - 16 | 0))); + } + var originalA = a; + var originalB = b; + var originalC = c; + var originalD = d; + var originalE = e; + var originalF = f; + var originalG = g; + var originalH = h; + for(var t$2 = 0; t$2 <= 79; ++t$2){ + var temp1 = Caml_int64.add(Caml_int64.add(Caml_int64.add(Caml_int64.add(h, ReCrypt_Functions_SHA2.Int64.sum1(e)), ReCrypt_Functions_SHA2.Int64.change(e, f, g)), Caml_array.caml_array_get(ReCrypt_Sha512_Constants.k, t$2)), Caml_array.caml_array_get(w, t$2)); + var temp2 = Caml_int64.add(ReCrypt_Functions_SHA2.Int64.sum0(a), ReCrypt_Functions_SHA2.Int64.majority(a, b, c)); + h = g; + g = f; + f = e; + e = Caml_int64.add(d, temp1); + d = c; + c = b; + b = a; + a = Caml_int64.add(temp1, temp2); + } + a = Caml_int64.add(originalA, a); + b = Caml_int64.add(originalB, b); + c = Caml_int64.add(originalC, c); + d = Caml_int64.add(originalD, d); + e = Caml_int64.add(originalE, e); + f = Caml_int64.add(originalF, f); + g = Caml_int64.add(originalG, g); + h = Caml_int64.add(originalH, h); + } + var sha512raw = Bytes.make(64, Char.chr(0)); + ReCrypt_Utils.append64(sha512raw, a, 0); + ReCrypt_Utils.append64(sha512raw, b, 8); + ReCrypt_Utils.append64(sha512raw, c, 16); + ReCrypt_Utils.append64(sha512raw, d, 24); + ReCrypt_Utils.append64(sha512raw, e, 32); + ReCrypt_Utils.append64(sha512raw, f, 40); + ReCrypt_Utils.append64(sha512raw, g, 48); + ReCrypt_Utils.append64(sha512raw, h, 56); + return ReCrypt_Utils.stringToHex(Bytes.to_string(sha512raw)); +} + +exports.make = make; +/* No side effect */ diff --git a/src/ReCrypt.rei b/src/ReCrypt.rei index bf8016d..0d53345 100644 --- a/src/ReCrypt.rei +++ b/src/ReCrypt.rei @@ -1,5 +1,3 @@ -/* BASED ON: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf */ - /** Module for creating MD5 hashes */ diff --git a/src/ReCrypt/MD5/ReCrypt_MD5_Constants.re b/src/ReCrypt/MD5/ReCrypt_MD5_Constants.re new file mode 100644 index 0000000..ffa5f6c --- /dev/null +++ b/src/ReCrypt/MD5/ReCrypt_MD5_Constants.re @@ -0,0 +1,70 @@ +let k = [| + 0xd76aa478, + 0xe8c7b756, + 0x242070db, + 0xc1bdceee, + 0xf57c0faf, + 0x4787c62a, + 0xa8304613, + 0xfd469501, + 0x698098d8, + 0x8b44f7af, + 0xffff5bb1, + 0x895cd7be, + 0x6b901122, + 0xfd987193, + 0xa679438e, + 0x49b40821, + 0xf61e2562, + 0xc040b340, + 0x265e5a51, + 0xe9b6c7aa, + 0xd62f105d, + 0x02441453, + 0xd8a1e681, + 0xe7d3fbc8, + 0x21e1cde6, + 0xc33707d6, + 0xf4d50d87, + 0x455a14ed, + 0xa9e3e905, + 0xfcefa3f8, + 0x676f02d9, + 0x8d2a4c8a, + 0xfffa3942, + 0x8771f681, + 0x6d9d6122, + 0xfde5380c, + 0xa4beea44, + 0x4bdecfa9, + 0xf6bb4b60, + 0xbebfbc70, + 0x289b7ec6, + 0xeaa127fa, + 0xd4ef3085, + 0x04881d05, + 0xd9d4d039, + 0xe6db99e5, + 0x1fa27cf8, + 0xc4ac5665, + 0xf4292244, + 0x432aff97, + 0xab9423a7, + 0xfc93a039, + 0x655b59c3, + 0x8f0ccc92, + 0xffeff47d, + 0x85845dd1, + 0x6fa87e4f, + 0xfe2ce6e0, + 0xa3014314, + 0x4e0811a1, + 0xf7537e82, + 0xbd3af235, + 0x2ad7d2bb, + 0xeb86d391, +|]; + +let s = [|7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21|]; + +let initialHash = [|0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476|]; \ No newline at end of file diff --git a/src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.re b/src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.re new file mode 100644 index 0000000..2c7fcf4 --- /dev/null +++ b/src/ReCrypt/MD5/ReCrypt_MD5_Preprocess.re @@ -0,0 +1,25 @@ +let pad = (msgBytes: Bytes.t) => { + let size = ref(Bytes.length(msgBytes) + 8 + 1); + while (size^ mod 64 != 0) { + size := size^ + 1; + }; + + let length = Bytes.length(msgBytes); + + let bytes = + Bytes.init(size^, index => { + switch (index) { + | i when i < length => Bytes.get(msgBytes, i) + | i when i == length => Char.chr(0x80) + | _ => Char.chr(0x00) + } + }); + + let va = ref(length * 8); + for (i in 0 to 7) { + Bytes.set(bytes, i + (size^ - 8), Char.chr(va^ land 0xFF)); + va := va^ lsr 8; + }; + + bytes; +}; \ No newline at end of file diff --git a/src/ReCrypt/MD5/ReCrypt_MD5_Process.re b/src/ReCrypt/MD5/ReCrypt_MD5_Process.re new file mode 100644 index 0000000..371d60e --- /dev/null +++ b/src/ReCrypt/MD5/ReCrypt_MD5_Process.re @@ -0,0 +1,72 @@ +let make = (message: Bytes.t) => { + let chunks = (Bytes.length(message) + 8) asr 6; + + let a = ref(ReCrypt_MD5_Constants.initialHash[0]); + let b = ref(ReCrypt_MD5_Constants.initialHash[1]); + let c = ref(ReCrypt_MD5_Constants.initialHash[2]); + let d = ref(ReCrypt_MD5_Constants.initialHash[3]); + + let w = Array.make(16, 0); + + for (i in 0 to chunks - 1) { + for (j in 0 to 63) { + w[j lsr 2] = + Bytes.get(message, i lsl 6 + j)->Char.code lsl 24 lor w[j lsr 2] lsr 8; + }; + + let originalA = a^; + let originalB = b^; + let originalC = c^; + let originalD = d^; + + for (j in 0 to 63) { + let f = + if (0 <= j && j <= 15) { + b^ land c^ lor (lnot(b^) land d^); + } else if (16 <= j && j <= 31) { + b^ land d^ lor (c^ land lnot(d^)); + } else if (32 <= j && j <= 47) { + b^ lxor c^ lxor d^; + } else { + c^ lxor (b^ lor lnot(d^)); + }; + + let g = + if (0 <= j && j <= 15) { + j; + } else if (16 <= j && j <= 31) { + (5 * j + 1) mod 16; + } else if (32 <= j && j <= 47) { + (3 * j + 5) mod 16; + } else { + 7 * j mod 16; + }; + + let temp = + b^ + + ReCrypt_Functions.MD.rotl( + a^ + f + w[g] + ReCrypt_MD5_Constants.k[j], + ReCrypt_MD5_Constants.s[(j lsr 4) lsl 2 lor (j land 3)], + ); + + a := d^; + d := c^; + c := b^; + b := temp; + }; + + a := originalA + a^; + b := originalB + b^; + c := originalC + c^; + d := originalD + d^; + }; + + let md5 = Bytes.make(16, Char.chr(0)); + + ReCrypt_Utils.append(md5, a^, 0); + ReCrypt_Utils.append(md5, b^, 4); + ReCrypt_Utils.append(md5, c^, 8); + ReCrypt_Utils.append(md5, d^, 12); + + Bytes.to_string(md5)->ReCrypt_Utils.stringToHex; +}; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_MD5.re b/src/ReCrypt/ReCrypt_MD5.re index 58d56c4..2165b09 100644 --- a/src/ReCrypt/ReCrypt_MD5.re +++ b/src/ReCrypt/ReCrypt_MD5.re @@ -1,175 +1,8 @@ -let constants = [| - 0xd76aa478, - 0xe8c7b756, - 0x242070db, - 0xc1bdceee, - 0xf57c0faf, - 0x4787c62a, - 0xa8304613, - 0xfd469501, - 0x698098d8, - 0x8b44f7af, - 0xffff5bb1, - 0x895cd7be, - 0x6b901122, - 0xfd987193, - 0xa679438e, - 0x49b40821, - 0xf61e2562, - 0xc040b340, - 0x265e5a51, - 0xe9b6c7aa, - 0xd62f105d, - 0x02441453, - 0xd8a1e681, - 0xe7d3fbc8, - 0x21e1cde6, - 0xc33707d6, - 0xf4d50d87, - 0x455a14ed, - 0xa9e3e905, - 0xfcefa3f8, - 0x676f02d9, - 0x8d2a4c8a, - 0xfffa3942, - 0x8771f681, - 0x6d9d6122, - 0xfde5380c, - 0xa4beea44, - 0x4bdecfa9, - 0xf6bb4b60, - 0xbebfbc70, - 0x289b7ec6, - 0xeaa127fa, - 0xd4ef3085, - 0x04881d05, - 0xd9d4d039, - 0xe6db99e5, - 0x1fa27cf8, - 0xc4ac5665, - 0xf4292244, - 0x432aff97, - 0xab9423a7, - 0xfc93a039, - 0x655b59c3, - 0x8f0ccc92, - 0xffeff47d, - 0x85845dd1, - 0x6fa87e4f, - 0xfe2ce6e0, - 0xa3014314, - 0x4e0811a1, - 0xf7537e82, - 0xbd3af235, - 0x2ad7d2bb, - 0xeb86d391, -|]; - -let s = [|7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21|]; - -let initialHash = [|0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476|]; - -let preprocess = (msgBytes: Bytes.t) => { - let size = ref(Bytes.length(msgBytes) + 8 + 1); - while (size^ mod 64 != 0) { - size := size^ + 1; - }; - - let length = Bytes.length(msgBytes); - - let bytes = - Bytes.init(size^, index => { - switch (index) { - | i when i < length => Bytes.get(msgBytes, i) - | i when i == length => Char.chr(0x80) - | _ => Char.chr(0x00) - } - }); - - let va = ref(length * 8); - for (i in 0 to 7) { - Bytes.set(bytes, i + (size^ - 8), Char.chr(va^ land 0xFF)); - va := va^ lsr 8; - }; - - bytes; -}; - -let processMessage = (message: Bytes.t) => { - let chunks = (Bytes.length(message) + 8) asr 6; - - let a = ref(initialHash[0]); - let b = ref(initialHash[1]); - let c = ref(initialHash[2]); - let d = ref(initialHash[3]); - - let w = Array.make(16, 0); - - for (i in 0 to chunks - 1) { - for (j in 0 to 63) { - w[j lsr 2] = - Bytes.get(message, i lsl 6 + j)->Char.code lsl 24 lor w[j lsr 2] lsr 8; - }; - - let originalA = a^; - let originalB = b^; - let originalC = c^; - let originalD = d^; - - for (j in 0 to 63) { - let f = - if (0 <= j && j <= 15) { - b^ land c^ lor (lnot(b^) land d^); - } else if (16 <= j && j <= 31) { - b^ land d^ lor (c^ land lnot(d^)); - } else if (32 <= j && j <= 47) { - b^ lxor c^ lxor d^; - } else { - c^ lxor (b^ lor lnot(d^)); - }; - - let g = - if (0 <= j && j <= 15) { - j; - } else if (16 <= j && j <= 31) { - (5 * j + 1) mod 16; - } else if (32 <= j && j <= 47) { - (3 * j + 5) mod 16; - } else { - 7 * j mod 16; - }; - - let temp = - b^ - + ReCrypt_Functions.MD.rotl( - a^ + f + w[g] + constants[j], - s[(j lsr 4) lsl 2 lor (j land 3)], - ); - - a := d^; - d := c^; - c := b^; - b := temp; - }; - - a := originalA + a^; - b := originalB + b^; - c := originalC + c^; - d := originalD + d^; - }; - - let md5 = Bytes.make(16, Char.chr(0)); - - ReCrypt_Utils.append(md5, a^, 0); - ReCrypt_Utils.append(md5, b^, 4); - ReCrypt_Utils.append(md5, c^, 8); - ReCrypt_Utils.append(md5, d^, 12); - - Bytes.to_string(md5)->ReCrypt_Utils.stringToHex; -}; +module Preprocess = ReCrypt_MD5_Preprocess; +module Process = ReCrypt_MD5_Process; let make = message => { let messageBytes = Bytes.of_string(message); - let paddedMessage = preprocess(messageBytes); - processMessage(paddedMessage); + let paddedMessage = Preprocess.pad(messageBytes); + Process.make(paddedMessage); }; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_MD5.rei b/src/ReCrypt/ReCrypt_MD5.rei deleted file mode 100644 index b753ff1..0000000 --- a/src/ReCrypt/ReCrypt_MD5.rei +++ /dev/null @@ -1,4 +0,0 @@ -/** - Compute a MD5 hash based on the given string - */ -let make: string => string; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Preprocess.re b/src/ReCrypt/ReCrypt_Preprocess.re deleted file mode 100644 index 35843f1..0000000 --- a/src/ReCrypt/ReCrypt_Preprocess.re +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Preprocessing [§5] - */ -module Sha1_224_256 = { - let pad = (msgBytes: Bytes.t) => { - let size = ref(Bytes.length(msgBytes) + 8 + 1); - while (size^ mod 64 != 0) { - size := size^ + 1; - }; - - let length = Bytes.length(msgBytes); - - let bytes = - Bytes.init(size^, index => { - switch (index) { - | i when i < length => Bytes.get(msgBytes, i) - | i when i == length => Char.chr(0x80) - | _ => Char.chr(0x00) - } - }); - - let va = ref(length * 8); - for (i in 1 to 15) { - Bytes.set( - bytes, - Bytes.length(bytes) - i, - Char.chr(va^ land 0x000000FF), - ); - va := va^ asr 8; - }; - bytes; - }; -}; - -module Sha384_512 = { - let pad = (msgBytes: Bytes.t) => { - let size = ref(Bytes.length(msgBytes) + 16 + 1); - while (size^ mod 128 != 0) { - size := size^ + 1; - }; - - let length = Bytes.length(msgBytes); - - let bytes = - Bytes.init(size^, index => { - switch (index) { - | i when i < length => Bytes.get(msgBytes, i) - | i when i == length => Char.chr(0x80) - | _ => Char.chr(0x00) - } - }); - - let va = ref(length * 8); - for (i in 1 to 15) { - Bytes.set( - bytes, - Bytes.length(bytes) - i, - Char.chr(va^ land 0x000000FF), - ); - va := va^ asr 8; - }; - bytes; - }; -}; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Preprocess.rei b/src/ReCrypt/ReCrypt_Preprocess.rei deleted file mode 100644 index cba3fa8..0000000 --- a/src/ReCrypt/ReCrypt_Preprocess.rei +++ /dev/null @@ -1,2 +0,0 @@ -module Sha1_224_256: {let pad: Bytes.t => bytes;}; -module Sha384_512: {let pad: Bytes.t => bytes;}; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha1.re b/src/ReCrypt/ReCrypt_Sha1.re index c189b3d..739c5aa 100644 --- a/src/ReCrypt/ReCrypt_Sha1.re +++ b/src/ReCrypt/ReCrypt_Sha1.re @@ -1,119 +1,8 @@ -/* constants [§4.2.3] */ -let constants = t => { - switch (t) { - | t when t >= 0 && t <= 19 => 0x5A827999l - | t when t >= 20 && t <= 39 => 0x6ED9EBA1l - | t when t >= 40 && t <= 59 => 0x8F1BBCDCl - | t when t >= 60 && t <= 79 => 0xCA62C1D6l - | _ => 0x00l - }; -}; - -let initialHash = [| - 0x67452301l, - 0xEFCDAB89l, - 0x98BADCFEl, - 0x10325476l, - 0xC3D2E1F0l, -|]; - -let processMessage = (message: Bytes.t) => { - let chunks = (Bytes.length(message) + 8) asr 6; - - let a = ref(initialHash[0]); - let b = ref(initialHash[1]); - let c = ref(initialHash[2]); - let d = ref(initialHash[3]); - let e = ref(initialHash[4]); - - for (i in 0 to chunks - 1) { - let w = Array.make(80, Int32.zero); - - for (t in 0 to 15) { - w[t] = - Bytes.unsafe_get(message, i * 64 + 4 * t) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(24) - ->Int32.logand(-0x1000000l); - - w[t] = - w[t] - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 1) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(16) - ->Int32.logand(0x00FF0000l), - ); - w[t] = - w[t] - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 2) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(8) - ->Int32.logand(0xFF00l) - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 3) - ->Char.code - ->Int32.of_int - ->Int32.logand(0xFFl), - ), - ); - }; - - for (t in 16 to 79) { - w[t] = - ReCrypt_Functions.SHA1.rotl( - w[t - 3] - ->Int32.logxor(w[t - 8]) - ->Int32.logxor(w[t - 14]) - ->Int32.logxor(w[t - 16]), - 1, - ); - }; - - let originalA = a^; - let originalB = b^; - let originalC = c^; - let originalD = d^; - let originalE = e^; - - for (t in 0 to 79) { - let temp = - ReCrypt_Functions.SHA1.rotl(a^, 5) - ->Int32.add(ReCrypt_Functions.SHA1.f(t, b^, c^, d^)) - ->Int32.add(e^) - ->Int32.add(constants(t)) - ->Int32.add(w[t]); - - e := d^; - d := c^; - c := ReCrypt_Functions.SHA1.rotl(b^, 30); - b := a^; - a := temp; - }; - - a := Int32.add(originalA, a^); - b := Int32.add(originalB, b^); - c := Int32.add(originalC, c^); - d := Int32.add(originalD, d^); - e := Int32.add(originalE, e^); - }; - - let sha1raw = Bytes.make(20, Char.chr(0)); - ReCrypt_Utils.append32(sha1raw, a^, 0); - ReCrypt_Utils.append32(sha1raw, b^, 4); - ReCrypt_Utils.append32(sha1raw, c^, 8); - ReCrypt_Utils.append32(sha1raw, d^, 12); - ReCrypt_Utils.append32(sha1raw, e^, 16); - - Bytes.to_string(sha1raw)->ReCrypt_Utils.stringToHex; -}; +module Preprocess = ReCrypt_Sha1_Preprocess; +module Process = ReCrypt_Sha1_Process; let make = message => { let messageBytes = Bytes.of_string(message); - let paddedMessage = ReCrypt_Preprocess.Sha1_224_256.pad(messageBytes); - processMessage(paddedMessage); + let paddedMessage = Preprocess.pad(messageBytes); + Process.make(paddedMessage); }; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha1.rei b/src/ReCrypt/ReCrypt_Sha1.rei deleted file mode 100644 index 546362e..0000000 --- a/src/ReCrypt/ReCrypt_Sha1.rei +++ /dev/null @@ -1,4 +0,0 @@ -/** - Compute a SHA1 hash based on the given string - */ -let make: string => string; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha224.re b/src/ReCrypt/ReCrypt_Sha224.re index e9494ad..9f2ffad 100644 --- a/src/ReCrypt/ReCrypt_Sha224.re +++ b/src/ReCrypt/ReCrypt_Sha224.re @@ -1,196 +1,8 @@ -/* constants [§4.2.3] */ -let constants = [| - 0x428a2f98l, - 0x71374491l, - (-0x4a3f0431l), - (-0x164a245bl), - 0x3956c25bl, - 0x59f111f1l, - (-0x6dc07d5cl), - (-0x54e3a12bl), - (-0x27f85568l), - 0x12835b01l, - 0x243185bel, - 0x550c7dc3l, - 0x72be5d74l, - (-0x7f214e02l), - (-0x6423f959l), - (-0x3e640e8cl), - (-0x1b64963fl), - (-0x1041b87al), - 0x0fc19dc6l, - 0x240ca1ccl, - 0x2de92c6fl, - 0x4a7484aal, - 0x5cb0a9dcl, - 0x76f988dal, - (-0x67c1aeael), - (-0x57ce3993l), - (-0x4ffcd838l), - (-0x40a68039l), - (-0x391ff40dl), - (-0x2a586eb9l), - 0x06ca6351l, - 0x14292967l, - 0x27b70a85l, - 0x2e1b2138l, - 0x4d2c6dfcl, - 0x53380d13l, - 0x650a7354l, - 0x766a0abbl, - (-0x7e3d36d2l), - (-0x6d8dd37bl), - (-0x5d40175fl), - (-0x57e599b5l), - (-0x3db47490l), - (-0x3893ae5dl), - (-0x2e6d17e7l), - (-0x2966f9dcl), - (-0xbf1ca7bl), - 0x106aa070l, - 0x19a4c116l, - 0x1e376c08l, - 0x2748774cl, - 0x34b0bcb5l, - 0x391c0cb3l, - 0x4ed8aa4al, - 0x5b9cca4fl, - 0x682e6ff3l, - 0x748f82eel, - 0x78a5636fl, - (-0x7b3787ecl), - (-0x7338fdf8l), - (-0x6f410006l), - (-0x5baf9315l), - (-0x41065c09l), - (-0x398e870el), -|]; - -let initialHash = [| - (-0x3efa6128l), - 0x367cd507l, - 0x3070dd17l, - (-0x8f1a6c7l), - (-0x3ff4cfl), - 0x68581511l, - 0x64f98fa7l, - (-0x4105b05cl), -|]; - -let processMessage = (message: Bytes.t) => { - let chunks = (Bytes.length(message) + 8) asr 6; - - let a = ref(initialHash[0]); - let b = ref(initialHash[1]); - let c = ref(initialHash[2]); - let d = ref(initialHash[3]); - let e = ref(initialHash[4]); - let f = ref(initialHash[5]); - let g = ref(initialHash[6]); - let h = ref(initialHash[7]); - - for (i in 0 to chunks - 1) { - let w = Array.make(64, Int32.zero); - - for (t in 0 to 15) { - w[t] = - Bytes.unsafe_get(message, i * 64 + 4 * t) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(24) - ->Int32.logand(-0x1000000l); - - w[t] = - w[t] - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 1) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(16) - ->Int32.logand(0x00FF0000l), - ); - w[t] = - w[t] - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 2) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(8) - ->Int32.logand(0xFF00l) - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 3) - ->Char.code - ->Int32.of_int - ->Int32.logand(0xFFl), - ), - ); - }; - - for (t in 16 to 63) { - w[t] = - ReCrypt_Functions.SHA2.Int32.sigma1(w[t - 2]) - ->Int32.add(w[t - 7]) - ->Int32.add(ReCrypt_Functions.SHA2.Int32.sigma0(w[t - 15])) - ->Int32.add(w[t - 16]); - }; - - let originalA = a^; - let originalB = b^; - let originalC = c^; - let originalD = d^; - let originalE = e^; - let originalF = f^; - let originalG = g^; - let originalH = h^; - - for (t in 0 to 63) { - let temp1 = - (h^) - ->Int32.add(ReCrypt_Functions.SHA2.Int32.sum1(e^)) - ->Int32.add(ReCrypt_Functions.SHA2.Int32.change(e^, f^, g^)) - ->Int32.add(constants[t]) - ->Int32.add(w[t]); - - let temp2 = - Int32.add( - ReCrypt_Functions.SHA2.Int32.sum0(a^), - ReCrypt_Functions.SHA2.Int32.majority(a^, b^, c^), - ); - - h := g^; - g := f^; - f := e^; - e := Int32.add(d^, temp1); - d := c^; - c := b^; - b := a^; - a := Int32.add(temp1, temp2); - }; - - a := Int32.add(originalA, a^); - b := Int32.add(originalB, b^); - c := Int32.add(originalC, c^); - d := Int32.add(originalD, d^); - e := Int32.add(originalE, e^); - f := Int32.add(originalF, f^); - g := Int32.add(originalG, g^); - h := Int32.add(originalH, h^); - }; - - let sha224raw = Bytes.make(28, Char.chr(0)); - ReCrypt_Utils.append32(sha224raw, a^, 0); - ReCrypt_Utils.append32(sha224raw, b^, 4); - ReCrypt_Utils.append32(sha224raw, c^, 8); - ReCrypt_Utils.append32(sha224raw, d^, 12); - ReCrypt_Utils.append32(sha224raw, e^, 16); - ReCrypt_Utils.append32(sha224raw, f^, 20); - ReCrypt_Utils.append32(sha224raw, g^, 24); - - Bytes.to_string(sha224raw)->ReCrypt_Utils.stringToHex; -}; +module Preprocess = ReCrypt_Sha224_Preprocess; +module Process = ReCrypt_Sha224_Process; let make = message => { let messageBytes = Bytes.of_string(message); - let paddedMessage = ReCrypt_Preprocess.Sha1_224_256.pad(messageBytes); - processMessage(paddedMessage); + let paddedMessage = Preprocess.pad(messageBytes); + Process.make(paddedMessage); }; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha224.rei b/src/ReCrypt/ReCrypt_Sha224.rei deleted file mode 100644 index ef4dd52..0000000 --- a/src/ReCrypt/ReCrypt_Sha224.rei +++ /dev/null @@ -1,4 +0,0 @@ -/** - Compute a SHA224 hash based on the given string - */ -let make: string => string; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha256.re b/src/ReCrypt/ReCrypt_Sha256.re index dd97336..403f7a7 100644 --- a/src/ReCrypt/ReCrypt_Sha256.re +++ b/src/ReCrypt/ReCrypt_Sha256.re @@ -1,196 +1,8 @@ -/* constants [§4.2.3] */ -let constants = [| - 0x428a2f98l, - 0x71374491l, - (-0x4a3f0431l), - (-0x164a245bl), - 0x3956c25bl, - 0x59f111f1l, - (-0x6dc07d5cl), - (-0x54e3a12bl), - (-0x27f85568l), - 0x12835b01l, - 0x243185bel, - 0x550c7dc3l, - 0x72be5d74l, - (-0x7f214e02l), - (-0x6423f959l), - (-0x3e640e8cl), - (-0x1b64963fl), - (-0x1041b87al), - 0x0fc19dc6l, - 0x240ca1ccl, - 0x2de92c6fl, - 0x4a7484aal, - 0x5cb0a9dcl, - 0x76f988dal, - (-0x67c1aeael), - (-0x57ce3993l), - (-0x4ffcd838l), - (-0x40a68039l), - (-0x391ff40dl), - (-0x2a586eb9l), - 0x06ca6351l, - 0x14292967l, - 0x27b70a85l, - 0x2e1b2138l, - 0x4d2c6dfcl, - 0x53380d13l, - 0x650a7354l, - 0x766a0abbl, - (-0x7e3d36d2l), - (-0x6d8dd37bl), - (-0x5d40175fl), - (-0x57e599b5l), - (-0x3db47490l), - (-0x3893ae5dl), - (-0x2e6d17e7l), - (-0x2966f9dcl), - (-0xbf1ca7bl), - 0x106aa070l, - 0x19a4c116l, - 0x1e376c08l, - 0x2748774cl, - 0x34b0bcb5l, - 0x391c0cb3l, - 0x4ed8aa4al, - 0x5b9cca4fl, - 0x682e6ff3l, - 0x748f82eel, - 0x78a5636fl, - (-0x7b3787ecl), - (-0x7338fdf8l), - (-0x6f410006l), - (-0x5baf9315l), - (-0x41065c09l), - (-0x398e870el), -|]; -let initialHash = [| - 0x6a09e667l, - (-0x4498517bl), - 0x3c6ef372l, - (-0x5ab00ac6l), - 0x510e527fl, - (-0x64fa9774l), - 0x1f83d9abl, - 0x5be0cd19l, -|]; - -let processMessage = (message: Bytes.t) => { - let chunks = (Bytes.length(message) + 8) asr 6; - - let a = ref(initialHash[0]); - let b = ref(initialHash[1]); - let c = ref(initialHash[2]); - let d = ref(initialHash[3]); - let e = ref(initialHash[4]); - let f = ref(initialHash[5]); - let g = ref(initialHash[6]); - let h = ref(initialHash[7]); - - for (i in 0 to chunks - 1) { - let w = Array.make(64, Int32.zero); - - for (t in 0 to 15) { - w[t] = - Bytes.unsafe_get(message, i * 64 + 4 * t) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(24) - ->Int32.logand(-0x1000000l); - - w[t] = - w[t] - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 1) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(16) - ->Int32.logand(0x00FF0000l), - ); - w[t] = - w[t] - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 2) - ->Char.code - ->Int32.of_int - ->Int32.shift_left(8) - ->Int32.logand(0xFF00l) - ->Int32.logor( - Bytes.unsafe_get(message, i * 64 + 4 * t + 3) - ->Char.code - ->Int32.of_int - ->Int32.logand(0xFFl), - ), - ); - }; - - for (t in 16 to 63) { - w[t] = - ReCrypt_Functions.SHA2.Int32.sigma1(w[t - 2]) - ->Int32.add(w[t - 7]) - ->Int32.add(ReCrypt_Functions.SHA2.Int32.sigma0(w[t - 15])) - ->Int32.add(w[t - 16]); - }; - - let originalA = a^; - let originalB = b^; - let originalC = c^; - let originalD = d^; - let originalE = e^; - let originalF = f^; - let originalG = g^; - let originalH = h^; - - for (t in 0 to 63) { - let temp1 = - (h^) - ->Int32.add(ReCrypt_Functions.SHA2.Int32.sum1(e^)) - ->Int32.add(ReCrypt_Functions.SHA2.Int32.change(e^, f^, g^)) - ->Int32.add(constants[t]) - ->Int32.add(w[t]); - - let temp2 = - Int32.add( - ReCrypt_Functions.SHA2.Int32.sum0(a^), - ReCrypt_Functions.SHA2.Int32.majority(a^, b^, c^), - ); - - h := g^; - g := f^; - f := e^; - e := Int32.add(d^, temp1); - d := c^; - c := b^; - b := a^; - a := Int32.add(temp1, temp2); - }; - - a := Int32.add(originalA, a^); - b := Int32.add(originalB, b^); - c := Int32.add(originalC, c^); - d := Int32.add(originalD, d^); - e := Int32.add(originalE, e^); - f := Int32.add(originalF, f^); - g := Int32.add(originalG, g^); - h := Int32.add(originalH, h^); - }; - - let sha256raw = Bytes.make(32, Char.chr(0)); - ReCrypt_Utils.append32(sha256raw, a^, 0); - ReCrypt_Utils.append32(sha256raw, b^, 4); - ReCrypt_Utils.append32(sha256raw, c^, 8); - ReCrypt_Utils.append32(sha256raw, d^, 12); - ReCrypt_Utils.append32(sha256raw, e^, 16); - ReCrypt_Utils.append32(sha256raw, f^, 20); - ReCrypt_Utils.append32(sha256raw, g^, 24); - ReCrypt_Utils.append32(sha256raw, h^, 28); - - Bytes.to_string(sha256raw)->ReCrypt_Utils.stringToHex; -}; +module Preprocess = ReCrypt_Sha256_Preprocess; +module Process = ReCrypt_Sha256_Process; let make = message => { let messageBytes = Bytes.of_string(message); - let paddedMessage = ReCrypt_Preprocess.Sha1_224_256.pad(messageBytes); - processMessage(paddedMessage); + let paddedMessage = Preprocess.pad(messageBytes); + Process.make(paddedMessage); }; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha256.rei b/src/ReCrypt/ReCrypt_Sha256.rei deleted file mode 100644 index d4e51ef..0000000 --- a/src/ReCrypt/ReCrypt_Sha256.rei +++ /dev/null @@ -1,4 +0,0 @@ -/** - Compute a SHA256 hash based on the given string - */ -let make: string => string; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha384.re b/src/ReCrypt/ReCrypt_Sha384.re index 2e51c24..0b4636d 100644 --- a/src/ReCrypt/ReCrypt_Sha384.re +++ b/src/ReCrypt/ReCrypt_Sha384.re @@ -1,190 +1,8 @@ -/* constants [§4.2.3] */ -let constants = [| - 0x428A2F98D728AE22L, - 0x7137449123EF65CDL, - (-0x4a3f043013b2c4d1L), - (-0x164a245a7e762444L), - 0x3956C25BF348B538L, - 0x59F111F1B605D019L, - (-0x6dc07d5b50e6b065L), - (-0x54e3a12a25927ee8L), - (-0x27f855675cfcfdbeL), - 0x12835B0145706FBEL, - 0x243185BE4EE4B28CL, - 0x550C7DC3D5FFB4E2L, - 0x72BE5D74F27B896FL, - (-0x7f214e01c4e9694fL), - (-0x6423f958da38edcbL), - (-0x3e640e8b3096d96cL), - (-0x1b64963e610eb52eL), - (-0x1041b879c7b0da1dL), - 0x0FC19DC68B8CD5B5L, - 0x240CA1CC77AC9C65L, - 0x2DE92C6F592B0275L, - 0x4A7484AA6EA6E483L, - 0x5CB0A9DCBD41FBD4L, - 0x76F988DA831153B5L, - (-0x67c1aead11992055L), - (-0x57ce3992d24bcdf0L), - (-0x4ffcd8376704dec1L), - (-0x40a680384110f11cL), - (-0x391ff40cc257703eL), - (-0x2a586eb86cf558dbL), - 0x06CA6351E003826FL, - 0x142929670A0E6E70L, - 0x27B70A8546D22FFCL, - 0x2E1B21385C26C926L, - 0x4D2C6DFC5AC42AEDL, - 0x53380D139D95B3DFL, - 0x650A73548BAF63DEL, - 0x766A0ABB3C77B2A8L, - (-0x7e3d36d1b812511aL), - (-0x6d8dd37aeb7dcac5L), - (-0x5d40175eb30efc9cL), - (-0x57e599b443bdcfffL), - (-0x3db4748f2f07686fL), - (-0x3893ae5cf9ab41d0L), - (-0x2e6d17e62910ade8L), - (-0x2966f9dbaa9a56f0L), - (-0xbf1ca7aa88edfd6L), - 0x106AA07032BBD1B8L, - 0x19A4C116B8D2D0C8L, - 0x1E376C085141AB53L, - 0x2748774CDF8EEB99L, - 0x34B0BCB5E19B48A8L, - 0x391C0CB3C5C95A63L, - 0x4ED8AA4AE3418ACBL, - 0x5B9CCA4F7763E373L, - 0x682E6FF3D6B2B8A3L, - 0x748F82EE5DEFB2FCL, - 0x78A5636F43172F60L, - (-0x7b3787eb5e0f548eL), - (-0x7338fdf7e59bc614L), - (-0x6f410005dc9ce1d8L), - (-0x5baf9314217d4217L), - (-0x41065c084d3986ebL), - (-0x398e870d1c8dacd5L), - (-0x35d8c13115d99e64L), - (-0x2e794738de3f3df9L), - (-0x15258229321f14e2L), - (-0xa82b08011912e88L), - 0x06F067AA72176FBAL, - 0x0A637DC5A2C898A6L, - 0x113F9804BEF90DAEL, - 0x1B710B35131C471BL, - 0x28DB77F523047D84L, - 0x32CAAB7B40C72493L, - 0x3C9EBE0A15C9BEBCL, - 0x431D67C49C100D4CL, - 0x4CC5D4BECB3E42B6L, - 0x597F299CFC657E2AL, - 0x5FCB6FAB3AD6FAECL, - 0x6C44198C4A475817L, -|]; - -let initialHash = [| - (-0x344462a23efa6128L), - 0x629a292a367cd507L, - (-0x6ea6fea5cf8f22e9L), - 0x152fecd8f70e5939L, - 0x67332667ffc00b31L, - (-0x714bb57897a7eaefL), - (-0x24f3d1f29b067059L), - 0x47b5481dbefa4fa4L, -|]; - -let processMessage = (message: Bytes.t) => { - let chunks = Bytes.length(message) / 128; - - let a = ref(initialHash[0]); - let b = ref(initialHash[1]); - let c = ref(initialHash[2]); - let d = ref(initialHash[3]); - let e = ref(initialHash[4]); - let f = ref(initialHash[5]); - let g = ref(initialHash[6]); - let h = ref(initialHash[7]); - - for (i in 0 to chunks - 1) { - let w = Array.make(80, Int64.zero); - - for (t in 0 to 15) { - for (j in 0 to 7) { - w[t] = - Int64.shift_left(w[t], 8) - ->Int64.add( - switch (Bytes.get(message, j + (i * 128 + 8 * t))) { - | exception _ => Int64.zero - | some => Int64.of_int(Char.code(some) land 0xff) - }, - ); - }; - }; - - for (t in 16 to 79) { - w[t] = - ReCrypt_Functions.SHA2.Int64.sigma1(w[t - 2]) - ->Int64.add(w[t - 7]) - ->Int64.add(ReCrypt_Functions.SHA2.Int64.sigma0(w[t - 15])) - ->Int64.add(w[t - 16]); - }; - - let originalA = a^; - let originalB = b^; - let originalC = c^; - let originalD = d^; - let originalE = e^; - let originalF = f^; - let originalG = g^; - let originalH = h^; - - for (t in 0 to 79) { - let temp1 = - (h^) - ->Int64.add(ReCrypt_Functions.SHA2.Int64.sum1(e^)) - ->Int64.add(ReCrypt_Functions.SHA2.Int64.change(e^, f^, g^)) - ->Int64.add(constants[t]) - ->Int64.add(w[t]); - - let temp2 = - Int64.add( - ReCrypt_Functions.SHA2.Int64.sum0(a^), - ReCrypt_Functions.SHA2.Int64.majority(a^, b^, c^), - ); - - h := g^; - g := f^; - f := e^; - e := Int64.add(d^, temp1); - d := c^; - c := b^; - b := a^; - a := Int64.add(temp1, temp2); - }; - - a := Int64.add(originalA, a^); - b := Int64.add(originalB, b^); - c := Int64.add(originalC, c^); - d := Int64.add(originalD, d^); - e := Int64.add(originalE, e^); - f := Int64.add(originalF, f^); - g := Int64.add(originalG, g^); - h := Int64.add(originalH, h^); - }; - - let sha384raw = Bytes.make(48, Char.chr(0)); - ReCrypt_Utils.append64(sha384raw, a^, 0); - ReCrypt_Utils.append64(sha384raw, b^, 8); - ReCrypt_Utils.append64(sha384raw, c^, 16); - ReCrypt_Utils.append64(sha384raw, d^, 24); - ReCrypt_Utils.append64(sha384raw, e^, 32); - ReCrypt_Utils.append64(sha384raw, f^, 40); - - Bytes.to_string(sha384raw)->ReCrypt_Utils.stringToHex; -}; +module Preprocess = ReCrypt_Sha384_Preprocess; +module Process = ReCrypt_Sha384_Process; let make = message => { let messageBytes = Bytes.of_string(message); - let paddedMessage = ReCrypt_Preprocess.Sha384_512.pad(messageBytes); - processMessage(paddedMessage); + let paddedMessage = Preprocess.pad(messageBytes); + Process.make(paddedMessage); }; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha384.rei b/src/ReCrypt/ReCrypt_Sha384.rei deleted file mode 100644 index b3b9831..0000000 --- a/src/ReCrypt/ReCrypt_Sha384.rei +++ /dev/null @@ -1,4 +0,0 @@ -/** - Compute a SHA384 hash based on the given string - */ -let make: string => string; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha512.re b/src/ReCrypt/ReCrypt_Sha512.re index 1e82c81..ebfb1bb 100644 --- a/src/ReCrypt/ReCrypt_Sha512.re +++ b/src/ReCrypt/ReCrypt_Sha512.re @@ -1,192 +1,8 @@ -/* constants [§4.2.3] */ -let constants = [| - 0x428a2f98d728ae22L, - 0x7137449123ef65cdL, - 0xb5c0fbcfec4d3b2fL, - 0xe9b5dba58189dbbcL, - 0x3956c25bf348b538L, - 0x59f111f1b605d019L, - 0x923f82a4af194f9bL, - 0xab1c5ed5da6d8118L, - 0xd807aa98a3030242L, - 0x12835b0145706fbeL, - 0x243185be4ee4b28cL, - 0x550c7dc3d5ffb4e2L, - 0x72be5d74f27b896fL, - 0x80deb1fe3b1696b1L, - 0x9bdc06a725c71235L, - 0xc19bf174cf692694L, - 0xe49b69c19ef14ad2L, - 0xefbe4786384f25e3L, - 0x0fc19dc68b8cd5b5L, - 0x240ca1cc77ac9c65L, - 0x2de92c6f592b0275L, - 0x4a7484aa6ea6e483L, - 0x5cb0a9dcbd41fbd4L, - 0x76f988da831153b5L, - 0x983e5152ee66dfabL, - 0xa831c66d2db43210L, - 0xb00327c898fb213fL, - 0xbf597fc7beef0ee4L, - 0xc6e00bf33da88fc2L, - 0xd5a79147930aa725L, - 0x06ca6351e003826fL, - 0x142929670a0e6e70L, - 0x27b70a8546d22ffcL, - 0x2e1b21385c26c926L, - 0x4d2c6dfc5ac42aedL, - 0x53380d139d95b3dfL, - 0x650a73548baf63deL, - 0x766a0abb3c77b2a8L, - 0x81c2c92e47edaee6L, - 0x92722c851482353bL, - 0xa2bfe8a14cf10364L, - 0xa81a664bbc423001L, - 0xc24b8b70d0f89791L, - 0xc76c51a30654be30L, - 0xd192e819d6ef5218L, - 0xd69906245565a910L, - 0xf40e35855771202aL, - 0x106aa07032bbd1b8L, - 0x19a4c116b8d2d0c8L, - 0x1e376c085141ab53L, - 0x2748774cdf8eeb99L, - 0x34b0bcb5e19b48a8L, - 0x391c0cb3c5c95a63L, - 0x4ed8aa4ae3418acbL, - 0x5b9cca4f7763e373L, - 0x682e6ff3d6b2b8a3L, - 0x748f82ee5defb2fcL, - 0x78a5636f43172f60L, - 0x84c87814a1f0ab72L, - 0x8cc702081a6439ecL, - 0x90befffa23631e28L, - 0xa4506cebde82bde9L, - 0xbef9a3f7b2c67915L, - 0xc67178f2e372532bL, - 0xca273eceea26619cL, - 0xd186b8c721c0c207L, - 0xeada7dd6cde0eb1eL, - 0xf57d4f7fee6ed178L, - 0x06f067aa72176fbaL, - 0x0a637dc5a2c898a6L, - 0x113f9804bef90daeL, - 0x1b710b35131c471bL, - 0x28db77f523047d84L, - 0x32caab7b40c72493L, - 0x3c9ebe0a15c9bebcL, - 0x431d67c49c100d4cL, - 0x4cc5d4becb3e42b6L, - 0x597f299cfc657e2aL, - 0x5fcb6fab3ad6faecL, - 0x6c44198c4a475817L, -|]; - -let initialHash = [| - 0x6a09e667f3bcc908L, - 0xbb67ae8584caa73bL, - 0x3c6ef372fe94f82bL, - 0xa54ff53a5f1d36f1L, - 0x510e527fade682d1L, - 0x9b05688c2b3e6c1fL, - 0x1f83d9abfb41bd6bL, - 0x5be0cd19137e2179L, -|]; - -let processMessage = (message: Bytes.t) => { - let chunks = Bytes.length(message) / 128; - - let a = ref(initialHash[0]); - let b = ref(initialHash[1]); - let c = ref(initialHash[2]); - let d = ref(initialHash[3]); - let e = ref(initialHash[4]); - let f = ref(initialHash[5]); - let g = ref(initialHash[6]); - let h = ref(initialHash[7]); - - for (i in 0 to chunks - 1) { - let w = Array.make(80, Int64.zero); - - for (t in 0 to 15) { - for (j in 0 to 7) { - w[t] = - Int64.shift_left(w[t], 8) - ->Int64.add( - switch (Bytes.get(message, j + (i * 128 + 8 * t))) { - | exception _ => Int64.zero - | some => Int64.of_int(Char.code(some) land 0xff) - }, - ); - }; - }; - - for (t in 16 to 79) { - w[t] = - ReCrypt_Functions.SHA2.Int64.sigma1(w[t - 2]) - ->Int64.add(w[t - 7]) - ->Int64.add(ReCrypt_Functions.SHA2.Int64.sigma0(w[t - 15])) - ->Int64.add(w[t - 16]); - }; - - let originalA = a^; - let originalB = b^; - let originalC = c^; - let originalD = d^; - let originalE = e^; - let originalF = f^; - let originalG = g^; - let originalH = h^; - - for (t in 0 to 79) { - let temp1 = - (h^) - ->Int64.add(ReCrypt_Functions.SHA2.Int64.sum1(e^)) - ->Int64.add(ReCrypt_Functions.SHA2.Int64.change(e^, f^, g^)) - ->Int64.add(constants[t]) - ->Int64.add(w[t]); - - let temp2 = - Int64.add( - ReCrypt_Functions.SHA2.Int64.sum0(a^), - ReCrypt_Functions.SHA2.Int64.majority(a^, b^, c^), - ); - - h := g^; - g := f^; - f := e^; - e := Int64.add(d^, temp1); - d := c^; - c := b^; - b := a^; - a := Int64.add(temp1, temp2); - }; - - a := Int64.add(originalA, a^); - b := Int64.add(originalB, b^); - c := Int64.add(originalC, c^); - d := Int64.add(originalD, d^); - e := Int64.add(originalE, e^); - f := Int64.add(originalF, f^); - g := Int64.add(originalG, g^); - h := Int64.add(originalH, h^); - }; - - let sha512raw = Bytes.make(64, Char.chr(0)); - ReCrypt_Utils.append64(sha512raw, a^, 0); - ReCrypt_Utils.append64(sha512raw, b^, 8); - ReCrypt_Utils.append64(sha512raw, c^, 16); - ReCrypt_Utils.append64(sha512raw, d^, 24); - ReCrypt_Utils.append64(sha512raw, e^, 32); - ReCrypt_Utils.append64(sha512raw, f^, 40); - ReCrypt_Utils.append64(sha512raw, g^, 48); - ReCrypt_Utils.append64(sha512raw, h^, 56); - - Bytes.to_string(sha512raw)->ReCrypt_Utils.stringToHex; -}; +module Preprocess = ReCrypt_Sha512_Preprocess; +module Process = ReCrypt_Sha512_Process; let make = message => { let messageBytes = Bytes.of_string(message); - let paddedMessage = ReCrypt_Preprocess.Sha384_512.pad(messageBytes); - processMessage(paddedMessage); + let paddedMessage = Preprocess.pad(messageBytes); + Process.make(paddedMessage); }; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Sha512.rei b/src/ReCrypt/ReCrypt_Sha512.rei deleted file mode 100644 index cd8ae7b..0000000 --- a/src/ReCrypt/ReCrypt_Sha512.rei +++ /dev/null @@ -1,4 +0,0 @@ -/** - Compute a SHA512 hash based on the given string - */ -let make: string => string; \ No newline at end of file diff --git a/src/ReCrypt/ReCrypt_Utils.rei b/src/ReCrypt/ReCrypt_Utils.rei deleted file mode 100644 index 2ee9398..0000000 --- a/src/ReCrypt/ReCrypt_Utils.rei +++ /dev/null @@ -1,16 +0,0 @@ -/** - */ -let append: (bytes, int, int) => unit; - -/** - */ -let append32: (bytes, int32, int) => unit; - -/** - */ -let append64: (bytes, int64, int) => unit; - -/** - Convert the given string into a hex representation - */ -let stringToHex: string => string; \ No newline at end of file diff --git a/src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.re b/src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.re new file mode 100644 index 0000000..084fcd2 --- /dev/null +++ b/src/ReCrypt/Sha1/ReCrypt_Sha1_Constants.re @@ -0,0 +1,17 @@ +let k = t => { + switch (t) { + | t when t >= 0 && t <= 19 => 0x5A827999l + | t when t >= 20 && t <= 39 => 0x6ED9EBA1l + | t when t >= 40 && t <= 59 => 0x8F1BBCDCl + | t when t >= 60 && t <= 79 => 0xCA62C1D6l + | _ => 0x00l + }; +}; + +let initialHash = [| + 0x67452301l, + 0xEFCDAB89l, + 0x98BADCFEl, + 0x10325476l, + 0xC3D2E1F0l, +|]; \ No newline at end of file diff --git a/src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.re b/src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.re new file mode 100644 index 0000000..e4997a7 --- /dev/null +++ b/src/ReCrypt/Sha1/ReCrypt_Sha1_Preprocess.re @@ -0,0 +1,28 @@ +let pad = (msgBytes: Bytes.t) => { + let size = ref(Bytes.length(msgBytes) + 8 + 1); + while (size^ mod 64 != 0) { + size := size^ + 1; + }; + + let length = Bytes.length(msgBytes); + + let bytes = + Bytes.init(size^, index => { + switch (index) { + | i when i < length => Bytes.get(msgBytes, i) + | i when i == length => Char.chr(0x80) + | _ => Char.chr(0x00) + } + }); + + let va = ref(length * 8); + for (i in 1 to 15) { + Bytes.set( + bytes, + Bytes.length(bytes) - i, + Char.chr(va^ land 0x000000FF), + ); + va := va^ asr 8; + }; + bytes; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha1/ReCrypt_Sha1_Process.re b/src/ReCrypt/Sha1/ReCrypt_Sha1_Process.re new file mode 100644 index 0000000..05ff2a9 --- /dev/null +++ b/src/ReCrypt/Sha1/ReCrypt_Sha1_Process.re @@ -0,0 +1,94 @@ +let make = (message: Bytes.t) => { + let chunks = (Bytes.length(message) + 8) asr 6; + + let a = ref(ReCrypt_Sha1_Constants.initialHash[0]); + let b = ref(ReCrypt_Sha1_Constants.initialHash[1]); + let c = ref(ReCrypt_Sha1_Constants.initialHash[2]); + let d = ref(ReCrypt_Sha1_Constants.initialHash[3]); + let e = ref(ReCrypt_Sha1_Constants.initialHash[4]); + + for (i in 0 to chunks - 1) { + let w = Array.make(80, Int32.zero); + + for (t in 0 to 15) { + w[t] = + Bytes.unsafe_get(message, i * 64 + 4 * t) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(24) + ->Int32.logand(-0x1000000l); + + w[t] = + w[t] + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 1) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(16) + ->Int32.logand(0x00FF0000l), + ); + w[t] = + w[t] + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 2) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(8) + ->Int32.logand(0xFF00l) + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 3) + ->Char.code + ->Int32.of_int + ->Int32.logand(0xFFl), + ), + ); + }; + + for (t in 16 to 79) { + w[t] = + ReCrypt_Functions.SHA1.rotl( + w[t - 3] + ->Int32.logxor(w[t - 8]) + ->Int32.logxor(w[t - 14]) + ->Int32.logxor(w[t - 16]), + 1, + ); + }; + + let originalA = a^; + let originalB = b^; + let originalC = c^; + let originalD = d^; + let originalE = e^; + + for (t in 0 to 79) { + let temp = + ReCrypt_Functions.SHA1.rotl(a^, 5) + ->Int32.add(ReCrypt_Functions.SHA1.f(t, b^, c^, d^)) + ->Int32.add(e^) + ->Int32.add(ReCrypt_Sha1_Constants.k(t)) + ->Int32.add(w[t]); + + e := d^; + d := c^; + c := ReCrypt_Functions.SHA1.rotl(b^, 30); + b := a^; + a := temp; + }; + + a := Int32.add(originalA, a^); + b := Int32.add(originalB, b^); + c := Int32.add(originalC, c^); + d := Int32.add(originalD, d^); + e := Int32.add(originalE, e^); + }; + + let sha1raw = Bytes.make(20, Char.chr(0)); + ReCrypt_Utils.append32(sha1raw, a^, 0); + ReCrypt_Utils.append32(sha1raw, b^, 4); + ReCrypt_Utils.append32(sha1raw, c^, 8); + ReCrypt_Utils.append32(sha1raw, d^, 12); + ReCrypt_Utils.append32(sha1raw, e^, 16); + + Bytes.to_string(sha1raw)->ReCrypt_Utils.stringToHex; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha224/ReCrypt_Sha224_Constants.re b/src/ReCrypt/Sha224/ReCrypt_Sha224_Constants.re new file mode 100644 index 0000000..ff019fe --- /dev/null +++ b/src/ReCrypt/Sha224/ReCrypt_Sha224_Constants.re @@ -0,0 +1,77 @@ +let k = [| + 0x428a2f98l, + 0x71374491l, + (-0x4a3f0431l), + (-0x164a245bl), + 0x3956c25bl, + 0x59f111f1l, + (-0x6dc07d5cl), + (-0x54e3a12bl), + (-0x27f85568l), + 0x12835b01l, + 0x243185bel, + 0x550c7dc3l, + 0x72be5d74l, + (-0x7f214e02l), + (-0x6423f959l), + (-0x3e640e8cl), + (-0x1b64963fl), + (-0x1041b87al), + 0x0fc19dc6l, + 0x240ca1ccl, + 0x2de92c6fl, + 0x4a7484aal, + 0x5cb0a9dcl, + 0x76f988dal, + (-0x67c1aeael), + (-0x57ce3993l), + (-0x4ffcd838l), + (-0x40a68039l), + (-0x391ff40dl), + (-0x2a586eb9l), + 0x06ca6351l, + 0x14292967l, + 0x27b70a85l, + 0x2e1b2138l, + 0x4d2c6dfcl, + 0x53380d13l, + 0x650a7354l, + 0x766a0abbl, + (-0x7e3d36d2l), + (-0x6d8dd37bl), + (-0x5d40175fl), + (-0x57e599b5l), + (-0x3db47490l), + (-0x3893ae5dl), + (-0x2e6d17e7l), + (-0x2966f9dcl), + (-0xbf1ca7bl), + 0x106aa070l, + 0x19a4c116l, + 0x1e376c08l, + 0x2748774cl, + 0x34b0bcb5l, + 0x391c0cb3l, + 0x4ed8aa4al, + 0x5b9cca4fl, + 0x682e6ff3l, + 0x748f82eel, + 0x78a5636fl, + (-0x7b3787ecl), + (-0x7338fdf8l), + (-0x6f410006l), + (-0x5baf9315l), + (-0x41065c09l), + (-0x398e870el), +|]; + +let initialHash = [| + (-0x3efa6128l), + 0x367cd507l, + 0x3070dd17l, + (-0x8f1a6c7l), + (-0x3ff4cfl), + 0x68581511l, + 0x64f98fa7l, + (-0x4105b05cl), +|]; \ No newline at end of file diff --git a/src/ReCrypt/Sha224/ReCrypt_Sha224_Preprocess.re b/src/ReCrypt/Sha224/ReCrypt_Sha224_Preprocess.re new file mode 100644 index 0000000..e4997a7 --- /dev/null +++ b/src/ReCrypt/Sha224/ReCrypt_Sha224_Preprocess.re @@ -0,0 +1,28 @@ +let pad = (msgBytes: Bytes.t) => { + let size = ref(Bytes.length(msgBytes) + 8 + 1); + while (size^ mod 64 != 0) { + size := size^ + 1; + }; + + let length = Bytes.length(msgBytes); + + let bytes = + Bytes.init(size^, index => { + switch (index) { + | i when i < length => Bytes.get(msgBytes, i) + | i when i == length => Char.chr(0x80) + | _ => Char.chr(0x00) + } + }); + + let va = ref(length * 8); + for (i in 1 to 15) { + Bytes.set( + bytes, + Bytes.length(bytes) - i, + Char.chr(va^ land 0x000000FF), + ); + va := va^ asr 8; + }; + bytes; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha224/ReCrypt_Sha224_Process.re b/src/ReCrypt/Sha224/ReCrypt_Sha224_Process.re new file mode 100644 index 0000000..f9fd93e --- /dev/null +++ b/src/ReCrypt/Sha224/ReCrypt_Sha224_Process.re @@ -0,0 +1,111 @@ +let make = (message: Bytes.t) => { + let chunks = (Bytes.length(message) + 8) asr 6; + + let a = ref(ReCrypt_Sha224_Constants.initialHash[0]); + let b = ref(ReCrypt_Sha224_Constants.initialHash[1]); + let c = ref(ReCrypt_Sha224_Constants.initialHash[2]); + let d = ref(ReCrypt_Sha224_Constants.initialHash[3]); + let e = ref(ReCrypt_Sha224_Constants.initialHash[4]); + let f = ref(ReCrypt_Sha224_Constants.initialHash[5]); + let g = ref(ReCrypt_Sha224_Constants.initialHash[6]); + let h = ref(ReCrypt_Sha224_Constants.initialHash[7]); + + for (i in 0 to chunks - 1) { + let w = Array.make(64, Int32.zero); + + for (t in 0 to 15) { + w[t] = + Bytes.unsafe_get(message, i * 64 + 4 * t) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(24) + ->Int32.logand(-0x1000000l); + + w[t] = + w[t] + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 1) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(16) + ->Int32.logand(0x00FF0000l), + ); + w[t] = + w[t] + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 2) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(8) + ->Int32.logand(0xFF00l) + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 3) + ->Char.code + ->Int32.of_int + ->Int32.logand(0xFFl), + ), + ); + }; + + for (t in 16 to 63) { + w[t] = + ReCrypt_Functions.SHA2.Int32.sigma1(w[t - 2]) + ->Int32.add(w[t - 7]) + ->Int32.add(ReCrypt_Functions.SHA2.Int32.sigma0(w[t - 15])) + ->Int32.add(w[t - 16]); + }; + + let originalA = a^; + let originalB = b^; + let originalC = c^; + let originalD = d^; + let originalE = e^; + let originalF = f^; + let originalG = g^; + let originalH = h^; + + for (t in 0 to 63) { + let temp1 = + (h^) + ->Int32.add(ReCrypt_Functions.SHA2.Int32.sum1(e^)) + ->Int32.add(ReCrypt_Functions.SHA2.Int32.change(e^, f^, g^)) + ->Int32.add(ReCrypt_Sha224_Constants.k[t]) + ->Int32.add(w[t]); + + let temp2 = + Int32.add( + ReCrypt_Functions.SHA2.Int32.sum0(a^), + ReCrypt_Functions.SHA2.Int32.majority(a^, b^, c^), + ); + + h := g^; + g := f^; + f := e^; + e := Int32.add(d^, temp1); + d := c^; + c := b^; + b := a^; + a := Int32.add(temp1, temp2); + }; + + a := Int32.add(originalA, a^); + b := Int32.add(originalB, b^); + c := Int32.add(originalC, c^); + d := Int32.add(originalD, d^); + e := Int32.add(originalE, e^); + f := Int32.add(originalF, f^); + g := Int32.add(originalG, g^); + h := Int32.add(originalH, h^); + }; + + let sha224raw = Bytes.make(28, Char.chr(0)); + ReCrypt_Utils.append32(sha224raw, a^, 0); + ReCrypt_Utils.append32(sha224raw, b^, 4); + ReCrypt_Utils.append32(sha224raw, c^, 8); + ReCrypt_Utils.append32(sha224raw, d^, 12); + ReCrypt_Utils.append32(sha224raw, e^, 16); + ReCrypt_Utils.append32(sha224raw, f^, 20); + ReCrypt_Utils.append32(sha224raw, g^, 24); + + Bytes.to_string(sha224raw)->ReCrypt_Utils.stringToHex; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha256/ReCrypt_Sha256_Constants.re b/src/ReCrypt/Sha256/ReCrypt_Sha256_Constants.re new file mode 100644 index 0000000..7ae2973 --- /dev/null +++ b/src/ReCrypt/Sha256/ReCrypt_Sha256_Constants.re @@ -0,0 +1,76 @@ +let k = [| + 0x428a2f98l, + 0x71374491l, + (-0x4a3f0431l), + (-0x164a245bl), + 0x3956c25bl, + 0x59f111f1l, + (-0x6dc07d5cl), + (-0x54e3a12bl), + (-0x27f85568l), + 0x12835b01l, + 0x243185bel, + 0x550c7dc3l, + 0x72be5d74l, + (-0x7f214e02l), + (-0x6423f959l), + (-0x3e640e8cl), + (-0x1b64963fl), + (-0x1041b87al), + 0x0fc19dc6l, + 0x240ca1ccl, + 0x2de92c6fl, + 0x4a7484aal, + 0x5cb0a9dcl, + 0x76f988dal, + (-0x67c1aeael), + (-0x57ce3993l), + (-0x4ffcd838l), + (-0x40a68039l), + (-0x391ff40dl), + (-0x2a586eb9l), + 0x06ca6351l, + 0x14292967l, + 0x27b70a85l, + 0x2e1b2138l, + 0x4d2c6dfcl, + 0x53380d13l, + 0x650a7354l, + 0x766a0abbl, + (-0x7e3d36d2l), + (-0x6d8dd37bl), + (-0x5d40175fl), + (-0x57e599b5l), + (-0x3db47490l), + (-0x3893ae5dl), + (-0x2e6d17e7l), + (-0x2966f9dcl), + (-0xbf1ca7bl), + 0x106aa070l, + 0x19a4c116l, + 0x1e376c08l, + 0x2748774cl, + 0x34b0bcb5l, + 0x391c0cb3l, + 0x4ed8aa4al, + 0x5b9cca4fl, + 0x682e6ff3l, + 0x748f82eel, + 0x78a5636fl, + (-0x7b3787ecl), + (-0x7338fdf8l), + (-0x6f410006l), + (-0x5baf9315l), + (-0x41065c09l), + (-0x398e870el), +|]; +let initialHash = [| + 0x6a09e667l, + (-0x4498517bl), + 0x3c6ef372l, + (-0x5ab00ac6l), + 0x510e527fl, + (-0x64fa9774l), + 0x1f83d9abl, + 0x5be0cd19l, +|]; \ No newline at end of file diff --git a/src/ReCrypt/Sha256/ReCrypt_Sha256_Preprocess.re b/src/ReCrypt/Sha256/ReCrypt_Sha256_Preprocess.re new file mode 100644 index 0000000..e4997a7 --- /dev/null +++ b/src/ReCrypt/Sha256/ReCrypt_Sha256_Preprocess.re @@ -0,0 +1,28 @@ +let pad = (msgBytes: Bytes.t) => { + let size = ref(Bytes.length(msgBytes) + 8 + 1); + while (size^ mod 64 != 0) { + size := size^ + 1; + }; + + let length = Bytes.length(msgBytes); + + let bytes = + Bytes.init(size^, index => { + switch (index) { + | i when i < length => Bytes.get(msgBytes, i) + | i when i == length => Char.chr(0x80) + | _ => Char.chr(0x00) + } + }); + + let va = ref(length * 8); + for (i in 1 to 15) { + Bytes.set( + bytes, + Bytes.length(bytes) - i, + Char.chr(va^ land 0x000000FF), + ); + va := va^ asr 8; + }; + bytes; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha256/ReCrypt_Sha256_Process.re b/src/ReCrypt/Sha256/ReCrypt_Sha256_Process.re new file mode 100644 index 0000000..7d8bfef --- /dev/null +++ b/src/ReCrypt/Sha256/ReCrypt_Sha256_Process.re @@ -0,0 +1,112 @@ +let make = (message: Bytes.t) => { + let chunks = (Bytes.length(message) + 8) asr 6; + + let a = ref(ReCrypt_Sha256_Constants.initialHash[0]); + let b = ref(ReCrypt_Sha256_Constants.initialHash[1]); + let c = ref(ReCrypt_Sha256_Constants.initialHash[2]); + let d = ref(ReCrypt_Sha256_Constants.initialHash[3]); + let e = ref(ReCrypt_Sha256_Constants.initialHash[4]); + let f = ref(ReCrypt_Sha256_Constants.initialHash[5]); + let g = ref(ReCrypt_Sha256_Constants.initialHash[6]); + let h = ref(ReCrypt_Sha256_Constants.initialHash[7]); + + for (i in 0 to chunks - 1) { + let w = Array.make(64, Int32.zero); + + for (t in 0 to 15) { + w[t] = + Bytes.unsafe_get(message, i * 64 + 4 * t) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(24) + ->Int32.logand(-0x1000000l); + + w[t] = + w[t] + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 1) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(16) + ->Int32.logand(0x00FF0000l), + ); + w[t] = + w[t] + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 2) + ->Char.code + ->Int32.of_int + ->Int32.shift_left(8) + ->Int32.logand(0xFF00l) + ->Int32.logor( + Bytes.unsafe_get(message, i * 64 + 4 * t + 3) + ->Char.code + ->Int32.of_int + ->Int32.logand(0xFFl), + ), + ); + }; + + for (t in 16 to 63) { + w[t] = + ReCrypt_Functions.SHA2.Int32.sigma1(w[t - 2]) + ->Int32.add(w[t - 7]) + ->Int32.add(ReCrypt_Functions.SHA2.Int32.sigma0(w[t - 15])) + ->Int32.add(w[t - 16]); + }; + + let originalA = a^; + let originalB = b^; + let originalC = c^; + let originalD = d^; + let originalE = e^; + let originalF = f^; + let originalG = g^; + let originalH = h^; + + for (t in 0 to 63) { + let temp1 = + (h^) + ->Int32.add(ReCrypt_Functions.SHA2.Int32.sum1(e^)) + ->Int32.add(ReCrypt_Functions.SHA2.Int32.change(e^, f^, g^)) + ->Int32.add(ReCrypt_Sha256_Constants.k[t]) + ->Int32.add(w[t]); + + let temp2 = + Int32.add( + ReCrypt_Functions.SHA2.Int32.sum0(a^), + ReCrypt_Functions.SHA2.Int32.majority(a^, b^, c^), + ); + + h := g^; + g := f^; + f := e^; + e := Int32.add(d^, temp1); + d := c^; + c := b^; + b := a^; + a := Int32.add(temp1, temp2); + }; + + a := Int32.add(originalA, a^); + b := Int32.add(originalB, b^); + c := Int32.add(originalC, c^); + d := Int32.add(originalD, d^); + e := Int32.add(originalE, e^); + f := Int32.add(originalF, f^); + g := Int32.add(originalG, g^); + h := Int32.add(originalH, h^); + }; + + let sha256raw = Bytes.make(32, Char.chr(0)); + ReCrypt_Utils.append32(sha256raw, a^, 0); + ReCrypt_Utils.append32(sha256raw, b^, 4); + ReCrypt_Utils.append32(sha256raw, c^, 8); + ReCrypt_Utils.append32(sha256raw, d^, 12); + ReCrypt_Utils.append32(sha256raw, e^, 16); + ReCrypt_Utils.append32(sha256raw, f^, 20); + ReCrypt_Utils.append32(sha256raw, g^, 24); + ReCrypt_Utils.append32(sha256raw, h^, 28); + + Bytes.to_string(sha256raw)->ReCrypt_Utils.stringToHex; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha384/ReCrypt_Sha384_Constants.re b/src/ReCrypt/Sha384/ReCrypt_Sha384_Constants.re new file mode 100644 index 0000000..71a00e8 --- /dev/null +++ b/src/ReCrypt/Sha384/ReCrypt_Sha384_Constants.re @@ -0,0 +1,93 @@ +let k = [| + 0x428A2F98D728AE22L, + 0x7137449123EF65CDL, + (-0x4a3f043013b2c4d1L), + (-0x164a245a7e762444L), + 0x3956C25BF348B538L, + 0x59F111F1B605D019L, + (-0x6dc07d5b50e6b065L), + (-0x54e3a12a25927ee8L), + (-0x27f855675cfcfdbeL), + 0x12835B0145706FBEL, + 0x243185BE4EE4B28CL, + 0x550C7DC3D5FFB4E2L, + 0x72BE5D74F27B896FL, + (-0x7f214e01c4e9694fL), + (-0x6423f958da38edcbL), + (-0x3e640e8b3096d96cL), + (-0x1b64963e610eb52eL), + (-0x1041b879c7b0da1dL), + 0x0FC19DC68B8CD5B5L, + 0x240CA1CC77AC9C65L, + 0x2DE92C6F592B0275L, + 0x4A7484AA6EA6E483L, + 0x5CB0A9DCBD41FBD4L, + 0x76F988DA831153B5L, + (-0x67c1aead11992055L), + (-0x57ce3992d24bcdf0L), + (-0x4ffcd8376704dec1L), + (-0x40a680384110f11cL), + (-0x391ff40cc257703eL), + (-0x2a586eb86cf558dbL), + 0x06CA6351E003826FL, + 0x142929670A0E6E70L, + 0x27B70A8546D22FFCL, + 0x2E1B21385C26C926L, + 0x4D2C6DFC5AC42AEDL, + 0x53380D139D95B3DFL, + 0x650A73548BAF63DEL, + 0x766A0ABB3C77B2A8L, + (-0x7e3d36d1b812511aL), + (-0x6d8dd37aeb7dcac5L), + (-0x5d40175eb30efc9cL), + (-0x57e599b443bdcfffL), + (-0x3db4748f2f07686fL), + (-0x3893ae5cf9ab41d0L), + (-0x2e6d17e62910ade8L), + (-0x2966f9dbaa9a56f0L), + (-0xbf1ca7aa88edfd6L), + 0x106AA07032BBD1B8L, + 0x19A4C116B8D2D0C8L, + 0x1E376C085141AB53L, + 0x2748774CDF8EEB99L, + 0x34B0BCB5E19B48A8L, + 0x391C0CB3C5C95A63L, + 0x4ED8AA4AE3418ACBL, + 0x5B9CCA4F7763E373L, + 0x682E6FF3D6B2B8A3L, + 0x748F82EE5DEFB2FCL, + 0x78A5636F43172F60L, + (-0x7b3787eb5e0f548eL), + (-0x7338fdf7e59bc614L), + (-0x6f410005dc9ce1d8L), + (-0x5baf9314217d4217L), + (-0x41065c084d3986ebL), + (-0x398e870d1c8dacd5L), + (-0x35d8c13115d99e64L), + (-0x2e794738de3f3df9L), + (-0x15258229321f14e2L), + (-0xa82b08011912e88L), + 0x06F067AA72176FBAL, + 0x0A637DC5A2C898A6L, + 0x113F9804BEF90DAEL, + 0x1B710B35131C471BL, + 0x28DB77F523047D84L, + 0x32CAAB7B40C72493L, + 0x3C9EBE0A15C9BEBCL, + 0x431D67C49C100D4CL, + 0x4CC5D4BECB3E42B6L, + 0x597F299CFC657E2AL, + 0x5FCB6FAB3AD6FAECL, + 0x6C44198C4A475817L, +|]; + +let initialHash = [| + (-0x344462a23efa6128L), + 0x629a292a367cd507L, + (-0x6ea6fea5cf8f22e9L), + 0x152fecd8f70e5939L, + 0x67332667ffc00b31L, + (-0x714bb57897a7eaefL), + (-0x24f3d1f29b067059L), + 0x47b5481dbefa4fa4L, +|]; \ No newline at end of file diff --git a/src/ReCrypt/Sha384/ReCrypt_Sha384_Preprocess.re b/src/ReCrypt/Sha384/ReCrypt_Sha384_Preprocess.re new file mode 100644 index 0000000..4f64bfb --- /dev/null +++ b/src/ReCrypt/Sha384/ReCrypt_Sha384_Preprocess.re @@ -0,0 +1,28 @@ +let pad = (msgBytes: Bytes.t) => { + let size = ref(Bytes.length(msgBytes) + 16 + 1); + while (size^ mod 128 != 0) { + size := size^ + 1; + }; + + let length = Bytes.length(msgBytes); + + let bytes = + Bytes.init(size^, index => { + switch (index) { + | i when i < length => Bytes.get(msgBytes, i) + | i when i == length => Char.chr(0x80) + | _ => Char.chr(0x00) + } + }); + + let va = ref(length * 8); + for (i in 1 to 15) { + Bytes.set( + bytes, + Bytes.length(bytes) - i, + Char.chr(va^ land 0x000000FF), + ); + va := va^ asr 8; + }; + bytes; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha384/ReCrypt_Sha384_Process.re b/src/ReCrypt/Sha384/ReCrypt_Sha384_Process.re new file mode 100644 index 0000000..1aa15af --- /dev/null +++ b/src/ReCrypt/Sha384/ReCrypt_Sha384_Process.re @@ -0,0 +1,89 @@ +let make = (message: Bytes.t) => { + let chunks = Bytes.length(message) / 128; + + let a = ref(ReCrypt_Sha384_Constants.initialHash[0]); + let b = ref(ReCrypt_Sha384_Constants.initialHash[1]); + let c = ref(ReCrypt_Sha384_Constants.initialHash[2]); + let d = ref(ReCrypt_Sha384_Constants.initialHash[3]); + let e = ref(ReCrypt_Sha384_Constants.initialHash[4]); + let f = ref(ReCrypt_Sha384_Constants.initialHash[5]); + let g = ref(ReCrypt_Sha384_Constants.initialHash[6]); + let h = ref(ReCrypt_Sha384_Constants.initialHash[7]); + + for (i in 0 to chunks - 1) { + let w = Array.make(80, Int64.zero); + + for (t in 0 to 15) { + for (j in 0 to 7) { + w[t] = + Int64.shift_left(w[t], 8) + ->Int64.add( + switch (Bytes.get(message, j + (i * 128 + 8 * t))) { + | exception _ => Int64.zero + | some => Int64.of_int(Char.code(some) land 0xff) + }, + ); + }; + }; + + for (t in 16 to 79) { + w[t] = + ReCrypt_Functions.SHA2.Int64.sigma1(w[t - 2]) + ->Int64.add(w[t - 7]) + ->Int64.add(ReCrypt_Functions.SHA2.Int64.sigma0(w[t - 15])) + ->Int64.add(w[t - 16]); + }; + + let originalA = a^; + let originalB = b^; + let originalC = c^; + let originalD = d^; + let originalE = e^; + let originalF = f^; + let originalG = g^; + let originalH = h^; + + for (t in 0 to 79) { + let temp1 = + (h^) + ->Int64.add(ReCrypt_Functions.SHA2.Int64.sum1(e^)) + ->Int64.add(ReCrypt_Functions.SHA2.Int64.change(e^, f^, g^)) + ->Int64.add(ReCrypt_Sha384_Constants.k[t]) + ->Int64.add(w[t]); + + let temp2 = + Int64.add( + ReCrypt_Functions.SHA2.Int64.sum0(a^), + ReCrypt_Functions.SHA2.Int64.majority(a^, b^, c^), + ); + + h := g^; + g := f^; + f := e^; + e := Int64.add(d^, temp1); + d := c^; + c := b^; + b := a^; + a := Int64.add(temp1, temp2); + }; + + a := Int64.add(originalA, a^); + b := Int64.add(originalB, b^); + c := Int64.add(originalC, c^); + d := Int64.add(originalD, d^); + e := Int64.add(originalE, e^); + f := Int64.add(originalF, f^); + g := Int64.add(originalG, g^); + h := Int64.add(originalH, h^); + }; + + let sha384raw = Bytes.make(48, Char.chr(0)); + ReCrypt_Utils.append64(sha384raw, a^, 0); + ReCrypt_Utils.append64(sha384raw, b^, 8); + ReCrypt_Utils.append64(sha384raw, c^, 16); + ReCrypt_Utils.append64(sha384raw, d^, 24); + ReCrypt_Utils.append64(sha384raw, e^, 32); + ReCrypt_Utils.append64(sha384raw, f^, 40); + + Bytes.to_string(sha384raw)->ReCrypt_Utils.stringToHex; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha512/ReCrypt_Sha512_Constants.re b/src/ReCrypt/Sha512/ReCrypt_Sha512_Constants.re new file mode 100644 index 0000000..5fbaa90 --- /dev/null +++ b/src/ReCrypt/Sha512/ReCrypt_Sha512_Constants.re @@ -0,0 +1,93 @@ +let k = [| + 0x428a2f98d728ae22L, + 0x7137449123ef65cdL, + 0xb5c0fbcfec4d3b2fL, + 0xe9b5dba58189dbbcL, + 0x3956c25bf348b538L, + 0x59f111f1b605d019L, + 0x923f82a4af194f9bL, + 0xab1c5ed5da6d8118L, + 0xd807aa98a3030242L, + 0x12835b0145706fbeL, + 0x243185be4ee4b28cL, + 0x550c7dc3d5ffb4e2L, + 0x72be5d74f27b896fL, + 0x80deb1fe3b1696b1L, + 0x9bdc06a725c71235L, + 0xc19bf174cf692694L, + 0xe49b69c19ef14ad2L, + 0xefbe4786384f25e3L, + 0x0fc19dc68b8cd5b5L, + 0x240ca1cc77ac9c65L, + 0x2de92c6f592b0275L, + 0x4a7484aa6ea6e483L, + 0x5cb0a9dcbd41fbd4L, + 0x76f988da831153b5L, + 0x983e5152ee66dfabL, + 0xa831c66d2db43210L, + 0xb00327c898fb213fL, + 0xbf597fc7beef0ee4L, + 0xc6e00bf33da88fc2L, + 0xd5a79147930aa725L, + 0x06ca6351e003826fL, + 0x142929670a0e6e70L, + 0x27b70a8546d22ffcL, + 0x2e1b21385c26c926L, + 0x4d2c6dfc5ac42aedL, + 0x53380d139d95b3dfL, + 0x650a73548baf63deL, + 0x766a0abb3c77b2a8L, + 0x81c2c92e47edaee6L, + 0x92722c851482353bL, + 0xa2bfe8a14cf10364L, + 0xa81a664bbc423001L, + 0xc24b8b70d0f89791L, + 0xc76c51a30654be30L, + 0xd192e819d6ef5218L, + 0xd69906245565a910L, + 0xf40e35855771202aL, + 0x106aa07032bbd1b8L, + 0x19a4c116b8d2d0c8L, + 0x1e376c085141ab53L, + 0x2748774cdf8eeb99L, + 0x34b0bcb5e19b48a8L, + 0x391c0cb3c5c95a63L, + 0x4ed8aa4ae3418acbL, + 0x5b9cca4f7763e373L, + 0x682e6ff3d6b2b8a3L, + 0x748f82ee5defb2fcL, + 0x78a5636f43172f60L, + 0x84c87814a1f0ab72L, + 0x8cc702081a6439ecL, + 0x90befffa23631e28L, + 0xa4506cebde82bde9L, + 0xbef9a3f7b2c67915L, + 0xc67178f2e372532bL, + 0xca273eceea26619cL, + 0xd186b8c721c0c207L, + 0xeada7dd6cde0eb1eL, + 0xf57d4f7fee6ed178L, + 0x06f067aa72176fbaL, + 0x0a637dc5a2c898a6L, + 0x113f9804bef90daeL, + 0x1b710b35131c471bL, + 0x28db77f523047d84L, + 0x32caab7b40c72493L, + 0x3c9ebe0a15c9bebcL, + 0x431d67c49c100d4cL, + 0x4cc5d4becb3e42b6L, + 0x597f299cfc657e2aL, + 0x5fcb6fab3ad6faecL, + 0x6c44198c4a475817L, +|]; + +let initialHash = [| + 0x6a09e667f3bcc908L, + 0xbb67ae8584caa73bL, + 0x3c6ef372fe94f82bL, + 0xa54ff53a5f1d36f1L, + 0x510e527fade682d1L, + 0x9b05688c2b3e6c1fL, + 0x1f83d9abfb41bd6bL, + 0x5be0cd19137e2179L, +|]; \ No newline at end of file diff --git a/src/ReCrypt/Sha512/ReCrypt_Sha512_Preprocess.re b/src/ReCrypt/Sha512/ReCrypt_Sha512_Preprocess.re new file mode 100644 index 0000000..4f64bfb --- /dev/null +++ b/src/ReCrypt/Sha512/ReCrypt_Sha512_Preprocess.re @@ -0,0 +1,28 @@ +let pad = (msgBytes: Bytes.t) => { + let size = ref(Bytes.length(msgBytes) + 16 + 1); + while (size^ mod 128 != 0) { + size := size^ + 1; + }; + + let length = Bytes.length(msgBytes); + + let bytes = + Bytes.init(size^, index => { + switch (index) { + | i when i < length => Bytes.get(msgBytes, i) + | i when i == length => Char.chr(0x80) + | _ => Char.chr(0x00) + } + }); + + let va = ref(length * 8); + for (i in 1 to 15) { + Bytes.set( + bytes, + Bytes.length(bytes) - i, + Char.chr(va^ land 0x000000FF), + ); + va := va^ asr 8; + }; + bytes; +}; \ No newline at end of file diff --git a/src/ReCrypt/Sha512/ReCrypt_Sha512_Process.re b/src/ReCrypt/Sha512/ReCrypt_Sha512_Process.re new file mode 100644 index 0000000..74c0e04 --- /dev/null +++ b/src/ReCrypt/Sha512/ReCrypt_Sha512_Process.re @@ -0,0 +1,91 @@ +let make = (message: Bytes.t) => { + let chunks = Bytes.length(message) / 128; + + let a = ref(ReCrypt_Sha512_Constants.initialHash[0]); + let b = ref(ReCrypt_Sha512_Constants.initialHash[1]); + let c = ref(ReCrypt_Sha512_Constants.initialHash[2]); + let d = ref(ReCrypt_Sha512_Constants.initialHash[3]); + let e = ref(ReCrypt_Sha512_Constants.initialHash[4]); + let f = ref(ReCrypt_Sha512_Constants.initialHash[5]); + let g = ref(ReCrypt_Sha512_Constants.initialHash[6]); + let h = ref(ReCrypt_Sha512_Constants.initialHash[7]); + + for (i in 0 to chunks - 1) { + let w = Array.make(80, Int64.zero); + + for (t in 0 to 15) { + for (j in 0 to 7) { + w[t] = + Int64.shift_left(w[t], 8) + ->Int64.add( + switch (Bytes.get(message, j + (i * 128 + 8 * t))) { + | exception _ => Int64.zero + | some => Int64.of_int(Char.code(some) land 0xff) + }, + ); + }; + }; + + for (t in 16 to 79) { + w[t] = + ReCrypt_Functions.SHA2.Int64.sigma1(w[t - 2]) + ->Int64.add(w[t - 7]) + ->Int64.add(ReCrypt_Functions.SHA2.Int64.sigma0(w[t - 15])) + ->Int64.add(w[t - 16]); + }; + + let originalA = a^; + let originalB = b^; + let originalC = c^; + let originalD = d^; + let originalE = e^; + let originalF = f^; + let originalG = g^; + let originalH = h^; + + for (t in 0 to 79) { + let temp1 = + (h^) + ->Int64.add(ReCrypt_Functions.SHA2.Int64.sum1(e^)) + ->Int64.add(ReCrypt_Functions.SHA2.Int64.change(e^, f^, g^)) + ->Int64.add(ReCrypt_Sha512_Constants.k[t]) + ->Int64.add(w[t]); + + let temp2 = + Int64.add( + ReCrypt_Functions.SHA2.Int64.sum0(a^), + ReCrypt_Functions.SHA2.Int64.majority(a^, b^, c^), + ); + + h := g^; + g := f^; + f := e^; + e := Int64.add(d^, temp1); + d := c^; + c := b^; + b := a^; + a := Int64.add(temp1, temp2); + }; + + a := Int64.add(originalA, a^); + b := Int64.add(originalB, b^); + c := Int64.add(originalC, c^); + d := Int64.add(originalD, d^); + e := Int64.add(originalE, e^); + f := Int64.add(originalF, f^); + g := Int64.add(originalG, g^); + h := Int64.add(originalH, h^); + }; + + let sha512raw = Bytes.make(64, Char.chr(0)); + ReCrypt_Utils.append64(sha512raw, a^, 0); + ReCrypt_Utils.append64(sha512raw, b^, 8); + ReCrypt_Utils.append64(sha512raw, c^, 16); + ReCrypt_Utils.append64(sha512raw, d^, 24); + ReCrypt_Utils.append64(sha512raw, e^, 32); + ReCrypt_Utils.append64(sha512raw, f^, 40); + ReCrypt_Utils.append64(sha512raw, g^, 48); + ReCrypt_Utils.append64(sha512raw, h^, 56); + + Bytes.to_string(sha512raw)->ReCrypt_Utils.stringToHex; +}; \ No newline at end of file -- 2.51.2