MCPcopy Create free account
hub / github.com/SocketCluster/socketcluster / sha1

Function sha1

app/public/socketcluster-client.js:8200–8271  ·  view source on GitHub ↗
(bytes)

Source from the content-addressed store, hash-verified

8198}
8199
8200function sha1(bytes) {
8201 const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
8202 const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
8203
8204 if (typeof bytes === 'string') {
8205 const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
8206
8207 bytes = [];
8208
8209 for (let i = 0; i < msg.length; ++i) {
8210 bytes.push(msg.charCodeAt(i));
8211 }
8212 } else if (!Array.isArray(bytes)) {
8213 // Convert Array-like to Array
8214 bytes = Array.prototype.slice.call(bytes);
8215 }
8216
8217 bytes.push(0x80);
8218 const l = bytes.length / 4 + 2;
8219 const N = Math.ceil(l / 16);
8220 const M = new Array(N);
8221
8222 for (let i = 0; i < N; ++i) {
8223 const arr = new Uint32Array(16);
8224
8225 for (let j = 0; j < 16; ++j) {
8226 arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
8227 }
8228
8229 M[i] = arr;
8230 }
8231
8232 M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
8233 M[N - 1][14] = Math.floor(M[N - 1][14]);
8234 M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
8235
8236 for (let i = 0; i < N; ++i) {
8237 const W = new Uint32Array(80);
8238
8239 for (let t = 0; t < 16; ++t) {
8240 W[t] = M[i][t];
8241 }
8242
8243 for (let t = 16; t < 80; ++t) {
8244 W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
8245 }
8246
8247 let a = H[0];
8248 let b = H[1];
8249 let c = H[2];
8250 let d = H[3];
8251 let e = H[4];
8252
8253 for (let t = 0; t < 80; ++t) {
8254 const s = Math.floor(t / 20);
8255 const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
8256 e = d;
8257 d = c;

Callers

nothing calls this directly

Calls 2

ROTLFunction · 0.85
fFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…