Advertisement
9551

Untitled

Jul 2nd, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.79 KB | None | 0 0
  1. local e=2^32 local t=bit32 and bit32.band or bit.band local a=bit32 and
  2. bit32.bnot or bit.bnot local o=bit32 and bit32.bxor or bit.bxor local i=bit32
  3. and bit32.lshift or bit.blshift local n=unpack local function s(h,r)local
  4. d=h/(2^r)local l=d%1 return(d-l)+l*e end local function u(c,m)local
  5. f=c/(2^m)return f-f%1 end local
  6. w={0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19,}local
  7. y={0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2,}local
  8. function p(v)local b,g=0,0 if 0xFFFFFFFF-b<v then g=g+1 b=v-(0xFFFFFFFF-b)-1
  9. else b=b+v end return g,b end local function k(q,j)return i((q[j]or
  10. 0),24)+i((q[j+1]or 0),16)+i((q[j+2]or 0),8)+(q[j+3]or 0)end local function
  11. x(z)local E=#z local T={}z[#z+1]=0x80 while#z%64~=56 do z[#z+1]=0 end local
  12. A=math.ceil(#z/64)for O=1,A do T[O]={}for I=1,16 do
  13. T[O][I]=k(z,1+((O-1)*64)+((I-1)*4))end end T[A][15],T[A][16]=p(E*8)return T end
  14. local function N(S,H)for R=17,64 do local D=S[R-15]local
  15. L=o(s(S[R-15],7),s(S[R-15],18),u(S[R-15],3))local
  16. U=o(s(S[R-2],17),s(S[R-2],19),u(S[R-2],10))S[R]=(S[R-16]+L+S[R-7]+U)%e end
  17. local C,M,F,W,Y,P,V,B=n(H)for G=1,64 do local K=o(s(Y,6),s(Y,11),s(Y,25))local
  18. Q=o(t(Y,P),t(a(Y),V))local J=(B+K+Q+y[G]+S[G])%e local
  19. X=o(s(C,2),s(C,13),s(C,22))local Z=o(o(t(C,M),t(C,F)),t(M,F))local et=(X+Z)%e
  20. B,V,P,Y,W,F,M,C=V,P,Y,(W+J)%e,F,M,C,(J+et)%e end H[1]=(H[1]+C)%e
  21. H[2]=(H[2]+M)%e H[3]=(H[3]+F)%e H[4]=(H[4]+W)%e H[5]=(H[5]+Y)%e H[6]=(H[6]+P)%e
  22. H[7]=(H[7]+V)%e H[8]=(H[8]+B)%e return H end local
  23. tt={__tostring=function(at)return
  24. string.char(unpack(at))end,__index={toHex=function(ot,it)return("%02x"):rep(#ot):format(unpack(ot))end,isEqual=function(nt,st)if
  25. type(st)~="table"then return false end if#nt~=#st then return false end local
  26. ht=0 for rt=1,#nt do ht=bit32.bor(ht,o(nt[rt],st[rt]))end return ht==0
  27. end}}local function dt(lt,ut)local ct={}for mt=1,ut do
  28. ct[(mt-1)*4+1]=t(u(lt[mt],24),0xFF)ct[(mt-1)*4+2]=t(u(lt[mt],16),0xFF)ct[(mt-1)*4+3]=t(u(lt[mt],8),0xFF)ct[(mt-1)*4+4]=t(lt[mt],0xFF)end
  29. return setmetatable(ct,tt)end local function ft(wt)local wt=wt
  30. or""wt=type(wt)=="table"and{n(wt)}or{tostring(wt):byte(1,-1)}wt=x(wt)local
  31. yt={n(w)}for pt=1,#wt do yt=N(wt[pt],yt)end return dt(yt,8)end local function
  32. vt(bt,gt)local bt=type(bt)=="table"and{n(bt)}or{tostring(bt):byte(1,-1)}local
  33. gt=type(gt)=="table"and{n(gt)}or{tostring(gt):byte(1,-1)}local kt=64 gt=#gt>kt
  34. and ft(gt)or gt local qt={}local jt={}local xt={}for zt=1,kt do
  35. qt[zt]=o(0x36,gt[zt]or 0)jt[zt]=o(0x5C,gt[zt]or 0)end for Et=1,#bt do
  36. qt[kt+Et]=bt[Et]end qt=ft(qt)for Tt=1,kt do xt[Tt]=jt[Tt]xt[kt+Tt]=qt[Tt]end
  37. return ft(xt)end local function At(Ot,It,Nt,St)local It=type(It)=="table"and It
  38. or{tostring(It):byte(1,-1)}local Ht=32 local St=St or 32 local Rt=1 local
  39. Dt={}while St>0 do local Lt={}local Ut={n(It)}local Ct=St>Ht and Ht or St
  40. Ut[#Ut+1]=t(u(Rt,24),0xFF)Ut[#Ut+1]=t(u(Rt,16),0xFF)Ut[#Ut+1]=t(u(Rt,8),0xFF)Ut[#Ut+1]=t(Rt,0xFF)for
  41. Mt=1,Nt do Ut=vt(Ut,Ot)for Ft=1,Ct do Lt[Ft]=o(Ut[Ft],Lt[Ft]or 0)end if
  42. Mt%200==0 then os.queueEvent("PBKDF2",Mt)coroutine.yield("PBKDF2")end end
  43. St=St-Ct Rt=Rt+1 for Wt=1,Ct do Dt[#Dt+1]=Lt[Wt]end end return
  44. setmetatable(Dt,tt)end
  45. return{digest=ft,hmac=vt,pbkdf2=At,}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement