-- Lua-hashings @89879fe79b6f3dc495c607494126ec9c3912b8e9 | /hashings/md5.lua | https://github.com/user-none/lua-hashings | License: MIT License | Minified using https://www.npmjs.com/package/luamin/v/1.0.4
-- Copyright (c) 2016 John Schember
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local a=require("string")local b=require("nums.uintn").u32;local c={}local d={__metatable={},__index=c}c.digest_size=16;c.block_size=64;local function e(f,g,h)return f&g|(~f&h)end;local function i(f,g,h)return f&h|(g&~h)end;local function j(f,g,h)return f~g~h end;local function k(f,g,h)return g~(f|~h)end;local function l(m,n)return m<<n|(m>>32-n)end;local function o(p,q,r,s,t,m,u,v)return l(q+p(r,s,t)+m+v,u)+r end;local function w(x,y,z,A,f)local q=x;local r=y;local s=z;local t=A;q=o(e,q,r,s,t,f[1],7,0xD76AA478)t=o(e,t,q,r,s,f[2],12,0xE8C7B756)s=o(e,s,t,q,r,f[3],17,0x242070DB)r=o(e,r,s,t,q,f[4],22,0xC1BDCEEE)q=o(e,q,r,s,t,f[5],7,0xF57C0FAF)t=o(e,t,q,r,s,f[6],12,0x4787C62A)s=o(e,s,t,q,r,f[7],17,0xA8304613)r=o(e,r,s,t,q,f[8],22,0xFD469501)q=o(e,q,r,s,t,f[9],7,0x698098D8)t=o(e,t,q,r,s,f[10],12,0x8B44F7AF)s=o(e,s,t,q,r,f[11],17,0xFFFF5BB1)r=o(e,r,s,t,q,f[12],22,0x895CD7BE)q=o(e,q,r,s,t,f[13],7,0x6B901122)t=o(e,t,q,r,s,f[14],12,0xFD987193)s=o(e,s,t,q,r,f[15],17,0xA679438E)r=o(e,r,s,t,q,f[16],22,0x49B40821)q=o(i,q,r,s,t,f[2],5,0xF61E2562)t=o(i,t,q,r,s,f[7],9,0xC040B340)s=o(i,s,t,q,r,f[12],14,0x265E5A51)r=o(i,r,s,t,q,f[1],20,0xE9B6C7AA)q=o(i,q,r,s,t,f[6],5,0xD62F105D)t=o(i,t,q,r,s,f[11],9,0x2441453)s=o(i,s,t,q,r,f[16],14,0xD8A1E681)r=o(i,r,s,t,q,f[5],20,0xE7D3FBC8)q=o(i,q,r,s,t,f[10],5,0x21E1CDE6)t=o(i,t,q,r,s,f[15],9,0xC33707D6)s=o(i,s,t,q,r,f[4],14,0xF4D50D87)r=o(i,r,s,t,q,f[9],20,0x455A14ED)q=o(i,q,r,s,t,f[14],5,0xA9E3E905)t=o(i,t,q,r,s,f[3],9,0xFCEFA3F8)s=o(i,s,t,q,r,f[8],14,0x676F02D9)r=o(i,r,s,t,q,f[13],20,0x8D2A4C8A)q=o(j,q,r,s,t,f[6],4,0xFFFA3942)t=o(j,t,q,r,s,f[9],11,0x8771F681)s=o(j,s,t,q,r,f[12],16,0x6D9D6122)r=o(j,r,s,t,q,f[15],23,0xFDE5380C)q=o(j,q,r,s,t,f[2],4,0xA4BEEA44)t=o(j,t,q,r,s,f[5],11,0x4BDECFA9)s=o(j,s,t,q,r,f[8],16,0xF6BB4B60)r=o(j,r,s,t,q,f[11],23,0xBEBFBC70)q=o(j,q,r,s,t,f[14],4,0x289B7EC6)t=o(j,t,q,r,s,f[1],11,0xEAA127FA)s=o(j,s,t,q,r,f[4],16,0xD4EF3085)r=o(j,r,s,t,q,f[7],23,0x4881D05)q=o(j,q,r,s,t,f[10],4,0xD9D4D039)t=o(j,t,q,r,s,f[13],11,0xE6DB99E5)s=o(j,s,t,q,r,f[16],16,0x1FA27CF8)r=o(j,r,s,t,q,f[3],23,0xC4AC5665)q=o(k,q,r,s,t,f[1],6,0xF4292244)t=o(k,t,q,r,s,f[8],10,0x432AFF97)s=o(k,s,t,q,r,f[15],15,0xAB9423A7)r=o(k,r,s,t,q,f[6],21,0xFC93A039)q=o(k,q,r,s,t,f[13],6,0x655B59C3)t=o(k,t,q,r,s,f[4],10,0x8F0CCC92)s=o(k,s,t,q,r,f[11],15,0xFFEFF47D)r=o(k,r,s,t,q,f[2],21,0x85845DD1)q=o(k,q,r,s,t,f[9],6,0x6FA87E4F)t=o(k,t,q,r,s,f[16],10,0xFE2CE6E0)s=o(k,s,t,q,r,f[7],15,0xA3014314)r=o(k,r,s,t,q,f[14],21,0x4E0811A1)q=o(k,q,r,s,t,f[5],6,0xF7537E82)t=o(k,t,q,r,s,f[12],10,0xBD3AF235)s=o(k,s,t,q,r,f[3],15,0x2AD7D2BB)r=o(k,r,s,t,q,f[10],21,0xEB86D391)return q+x,r+y,s+z,t+A end;function c:new(B)if self~=c then return nil,"First argument must be self"end;local C=setmetatable({},d)C._A=b(0x67452301)C._B=b(0xEFCDAB89)C._C=b(0x98BADCFE)C._D=b(0x10325476)C._len=0;C._data=""if B~=nil then C:update(B)end;return C end;setmetatable(c,{__call=c.new})function c:copy()local C=c()C._A=self._A:copy()C._B=self._B:copy()C._C=self._C:copy()C._D=self._D:copy()C._data=self._data;C._len=self._len;return C end;function c:update(B)local f;if B==nil then B=""end;B=tostring(B)self._len=self._len+#B;self._data=self._data..B;while#self._data>=64 do f={}for D=1,64,4 do f[#f+1]=a.byte(self._data,D+3)<<24|(a.byte(self._data,D+2)<<16)|(a.byte(self._data,D+1)<<8)|a.byte(self._data,D)end;self._data=self._data:sub(65,#self._data)self._A,self._B,self._C,self._D=w(self._A,self._B,self._C,self._D,f)end end;function c:digest()local E;local B;local F=0;local G=0;E=self:copy()G=E._len%64;if G<56 then G=56-G else G=120-G end;F=E._len*8;B=a.char(1<<7)..a.rep(a.char(0),G-1)..a.char(F&0xFF)..a.char(F>>8&0xFF)..a.char(F>>16&0xFF)..a.char(F>>24&0xFF)..a.char(F>>32&0xFF)..a.char(F>>40&0xFF)..a.char(F>>48&0xFF)..a.char(F>>56&0xFF)E:update(B)return E._A:swape():asbytestring()..E._B:swape():asbytestring()..E._C:swape():asbytestring()..E._D:swape():asbytestring()end;function c:hexdigest()local H;local I={}H=self:digest()for J=1,#H do I[J]=a.format("%02X",a.byte(H,J))end;return table.concat(I)end;return c
