source: trip-planner-front/node_modules/uuid/dist/sha1-browser.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.5 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8// Adapted from Chris Veness' SHA1 code at
9// http://www.movable-type.co.uk/scripts/sha1.html
10function f(s, x, y, z) {
11 switch (s) {
12 case 0:
13 return x & y ^ ~x & z;
14
15 case 1:
16 return x ^ y ^ z;
17
18 case 2:
19 return x & y ^ x & z ^ y & z;
20
21 case 3:
22 return x ^ y ^ z;
23 }
24}
25
26function ROTL(x, n) {
27 return x << n | x >>> 32 - n;
28}
29
30function sha1(bytes) {
31 const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
32 const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
33
34 if (typeof bytes === 'string') {
35 const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
36
37 bytes = [];
38
39 for (let i = 0; i < msg.length; ++i) {
40 bytes.push(msg.charCodeAt(i));
41 }
42 } else if (!Array.isArray(bytes)) {
43 // Convert Array-like to Array
44 bytes = Array.prototype.slice.call(bytes);
45 }
46
47 bytes.push(0x80);
48 const l = bytes.length / 4 + 2;
49 const N = Math.ceil(l / 16);
50 const M = new Array(N);
51
52 for (let i = 0; i < N; ++i) {
53 const arr = new Uint32Array(16);
54
55 for (let j = 0; j < 16; ++j) {
56 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];
57 }
58
59 M[i] = arr;
60 }
61
62 M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
63 M[N - 1][14] = Math.floor(M[N - 1][14]);
64 M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
65
66 for (let i = 0; i < N; ++i) {
67 const W = new Uint32Array(80);
68
69 for (let t = 0; t < 16; ++t) {
70 W[t] = M[i][t];
71 }
72
73 for (let t = 16; t < 80; ++t) {
74 W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
75 }
76
77 let a = H[0];
78 let b = H[1];
79 let c = H[2];
80 let d = H[3];
81 let e = H[4];
82
83 for (let t = 0; t < 80; ++t) {
84 const s = Math.floor(t / 20);
85 const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
86 e = d;
87 d = c;
88 c = ROTL(b, 30) >>> 0;
89 b = a;
90 a = T;
91 }
92
93 H[0] = H[0] + a >>> 0;
94 H[1] = H[1] + b >>> 0;
95 H[2] = H[2] + c >>> 0;
96 H[3] = H[3] + d >>> 0;
97 H[4] = H[4] + e >>> 0;
98 }
99
100 return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
101}
102
103var _default = sha1;
104exports.default = _default;
Note: See TracBrowser for help on using the repository browser.