-
Notifications
You must be signed in to change notification settings - Fork 41
/
salsa20.min.js
1 lines (1 loc) · 1.05 KB
/
salsa20.min.js
1
function salsa20(r,n,t){function o(r){for(var n=[],t=0;t<r.length;t++)n.push(255&r.charCodeAt(t));return n}function f(r,n,t,o){var f=s[o]+s[t];s[r]^=f<<7|f>>>25,f=s[r]+s[o],s[n]^=f<<9|f>>>23,f=s[n]+s[r],s[t]^=f<<13|f>>>19,f=s[t]+s[n],s[o]^=f<<18|f>>>14}var e,a=r,i=a.length,g=[],h=[],s=[16];for("string"==typeof r&&(a=o(r)),"string"==typeof n&&(n=o(n)),"string"==typeof t&&(t=o(t)),e=0;e<32;e+=4)g.push((n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0);var u=[1634760805,g[0],g[1],g[2],g[3],857760878,0,0,0,0,2036477234,g[4],g[5],g[6],g[7],1797285236];for(t.length>=8&&(u[6]=(t[0]|t[1]<<8|t[2]<<16|t[3]<<24)>>>0,u[7]=(t[4]|t[5]<<8|t[6]<<16|t[7]<<24)>>>0);i>0;){for(e=0;e<16;e++)s[e]=u[e];for(e=0;e<10;e++)f(4,8,12,0),f(9,13,1,5),f(14,2,6,10),f(3,7,11,15),f(1,2,3,0),f(6,7,4,5),f(11,8,9,10),f(12,13,14,15);for(e=0;e<16;e++)s[e]+=u[e];u[8]++;var l=i<64?i:64,p=a.length-i;for(i-=64,e=0;e<l;e++)h[p+e]=a[p+e]^s[e>>2]>>>((3&e)<<3)&255}if("string"==typeof r){for(var e=0;e<h.length;e++)h[e]=String.fromCharCode(h[e]);return h.join("")}return r instanceof Uint8Array?new Uint8Array(h):h}