PageSourceSearch

https://www.oauth.com/wp-content/themes/oauthdotcom/js/crypto.js?ver=b1999063286ff48e2dfaeed2107d9f427c8506d8

js oauth.com collected 2026-09-24 07:33:16 UTC 4,717 bytes, 150 lines download raw bytes

1var sha256 = function sha256(ascii) {
2  function rightRotate(value, amount) {
3    return (value>>>amount) | (value<<(32 - amount));
4  };
5  
6  var mathPow = Math.pow;
7  var maxWord = mathPow(2, 32);
8  var lengthProperty = 'length';
9  var i, j; // Used as a counter across the whole file
10  var result = '';
11
12  var words = [];
13  var asciiBitLength = ascii[lengthProperty]*8;
14  
15  //* caching results is optional - remove/add slash from front of this line to toggle
16  // Initial hash value: first 32 bits of the fractional parts of the square roots of the first 8 primes
17  // (we actually calculate the first 64, but extra values are just ignored)
18  var hash = sha256.h = sha256.h || [];
19  // Round constants: first 32 bits of the fractional parts of the cube roots of the first 64 primes
20  var k = sha256.k = sha256.k || [];
21  var primeCounter = k[lengthProperty];
22  /*/
23  var hash = [], k = [];
24  var primeCounter = 0;
25  //*/
26
27  var isComposite = {};
28  for (var candidate = 2; primeCounter < 64; candidate++) {
29    if (!isComposite[candidate]) {
30      for (i = 0; i < 313; i += candidate) {
31        isComposite[i] = candidate;
32      }
33      hash[primeCounter] = (mathPow(candidate, .5)*maxWord)|0;
34      k[primeCounter++] = (mathPow(candidate, 1/3)*maxWord)|0;
35    }
36  }
37  
38  ascii += '\x80'; // Append '1' bit (plus zero padding)
39  while (ascii[lengthProperty]%64 - 56) ascii += '\x00'; // More zero padding
40  for (i = 0; i < ascii[lengthProperty]; i++) {
41    j = ascii.charCodeAt(i);
42    if (j>>8) return; // ASCII check: only accept characters in range 0-255
43    words[i>>2] |= j << ((3 - i)%4)*8;
44  }
45  words[words[lengthProperty]] = ((asciiBitLength/maxWord)|0);
46  words[words[lengthProperty]] = (asciiBitLength)
47  
48  // process each chunk
49  for (j = 0; j < words[lengthProperty];) {
50    var w = words.slice(j, j += 16); // The message is expanded into 64 words as part of the iteration
51    var oldHash = hash;
52    // This is now the "working hash", often labelled as variables a...g
53    // (we have to truncate as well, otherwise extra entries at the end accumulate
54    hash = hash.slice(0, 8);
55    
56    for (i = 0; i < 64; i++) {
57      var i2 = i + j;
58      // Expand the message into 64 words
59      // Used below if 
60      var w15 = w[i - 15], w2 = w[i - 2];
61
62      // Iterate
63      var a = hash[0], e = hash[4];
64      var temp1 = hash[7]
65        + (rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25)) // S1
66        + ((e&hash[5])^((~e)&hash[6])) // ch
67        + k[i]
68        // Expand the message schedule if needed
69        + (w[i] = (i < 16) ? w[i] : (
70            w[i - 16]
71            + (rightRotate(w15, 7) ^ rightRotate(w15, 18) ^ (w15>>>3)) // s0
72            + w[i - 7]
73            + (rightRotate(w2, 17) ^ rightRotate(w2, 19) ^ (w2>>>10)) // s1
74          )|0
75        );
76      // This is only used once, so *could* be moved below, but it only saves 4 bytes and makes things unreadble
77      var temp2 = (rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22)) // S0
78        + ((a&hash[1])^(a&hash[2])^(hash[1]&hash[2])); // maj
79      
80      hash = [(temp1 + temp2)|0].concat(hash); // We don't bother trimming off the extra ones, they're harmless as long as we're truncating when we do the slice()
81      hash[4] = (hash[4] + temp1)|0;
82    }
83    
84    for (i = 0; i < 8; i++) {
85      hash[i] = (hash[i] + oldHash[i])|0;
86    }
87  }
88  
89  for (i = 0; i < 8; i++) {
90    for (j = 3; j + 1; j--) {
91      var b = (hash[i]>>(j*8))&255;
92      result += ((b < 16) ? 0 : '') + b.toString(16);
93    }
94  }
95  return result;
96};
97
98function hex2bin(s) {
99  //  discuss at: http://locutus.io/php/hex2bin/
100  // original by: Dumitru Uzun (http://duzun.me)
101  //   example 1: hex2bin('44696d61')
102  //   returns 1: 'Dima'
103  //   example 2: hex2bin('00')
104  //   returns 2: '\x00'
105  //   example 3: hex2bin('2f1q')
106  //   returns 3: false
107
108  var ret = []
109  var i = 0
110  var l
111
112  s += ''
113
114  for (l = s.length; i < l; i += 2) {
115    var c = parseInt(s.substr(i, 1), 16)
116    var k = parseInt(s.substr(i + 1, 1), 16)
117    if (isNaN(c) || isNaN(k)) return false
118    ret.push((c << 4) | k)
119  }
120
121  return String.fromCharCode.apply(String, ret)
122}
123
124function dec2hex(dec) {
125  return ('0' + dec.toString(16)).substr(-2)
126}
127
128// Array of integers to binary data
129function dec2bin(arr) {
130  return hex2bin(Array.from(arr, dec2hex).join(''));
131}
132
133function sha256bin(ascii) {
134  return hex2bin(sha256(ascii));
135}
136
137function base64_urlencode(str) {
138  return btoa(str)
139            .replace(/\+/g, '-')
140            .replace(/\//g, '_')
141            .replace(/=/g, '');
142}
143
144function random_string(len) {
145  var arr = new Uint8Array(len);
146  window.crypto.getRandomValues(arr);
147  var str = base64_urlencode(dec2bin(arr));
148  return str.substring(0, len);
149}
150

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.