1/* * sjcl.js 2 * Stanford Javascript Crypto Library 3 * 1.0.7 4 * 5 * By bitwiseshiftleft 6 * License: BSD http://opensource.org/licenses/BSD-2-Clause 7 * See https://github.com/bitwiseshiftleft/sjcl/blob/master/LICENSE.txt under BSD license 8 */ 9"use strict"; 10 11var ApaLib = ApaLib || {} 12 13var sjcl = { 14 cipher: {}, 15 hash: {}, 16 keyexchange: {}, 17 mode: {}, 18 misc: {}, 19 codec: {}, 20 exception: { 21 corrupt: function (a) { 22 this.toString = function () { 23 return "CORRUPT: " + this.message; 24 }; 25 this.message = a; 26 }, 27 invalid: function (a) { 28 this.toString = function () { 29 return "INVALID: " + this.message; 30 }; 31 this.message = a; 32 }, 33 bug: function (a) { 34 this.toString = function () { 35 return "BUG: " + this.message; 36 }; 37 this.message = a; 38 }, 39 notReady: function (a) { 40 this.toString = function () { 41 return "NOT READY: " + this.message; 42 }; 43 this.message = a; 44 }, 45 }, 46}; 47sjcl.cipher.aes = function (a) { 48 this.s[0][0][0] || this.O(); 49 var b, 50 c, 51 d, 52 e, 53 f = this.s[0][4], 54 g = this.s[1]; 55 b = a.length; 56 var h = 1; 57 if (4 !== b && 6 !== b && 8 !== b) throw new sjcl.exception.invalid("invalid aes key size"); 58 this.b = [(d = a.slice(0)), (e = [])]; 59 for (a = b; a < 4 * b + 28; a++) { 60 c = d[a - 1]; 61 if (0 === a % b || (8 === b && 4 === a % b)) 62 (c = (f[c >>> 24] << 24) ^ (f[(c >> 16) & 255] << 16) ^ (f[(c >> 8) & 255] << 8) ^ f[c & 255]), 63 0 === a % b && ((c = (c << 8) ^ (c >>> 24) ^ (h << 24)), (h = (h << 1) ^ (283 * (h >> 7)))); 64 d[a] = d[a - b] ^ c; 65 } 66 for (b = 0; a; b++, a--) 67 (c = d[b & 3 ? a : a - 4]), 68 (e[b] = 69 4 >= a || 4 > b 70 ? c 71 : g[0][f[c >>> 24]] ^ g[1][f[(c >> 16) & 255]] ^ g[2][f[(c >> 8) & 255]] ^ g[3][f[c & 255]]); 72}; 73sjcl.cipher.aes.prototype = { 74 encrypt: function (a) { 75 return t(this, a, 0); 76 }, 77 decrypt: function (a) { 78 return t(this, a, 1); 79 }, 80 s: [ 81 [[], [], [], [], []], 82 [[], [], [], [], []], 83 ], 84 O: function () { 85 var a = this.s[0], 86 b = this.s[1], 87 c = a[4], 88 d = b[4], 89 e, 90 f, 91 g, 92 h = [], 93 k = [], 94 l, 95 n, 96 m, 97 p; 98 for (e = 0; 0x100 > e; e++) k[(h[e] = (e << 1) ^ (283 * (e >> 7))) ^ e] = e; 99 for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) 100 for ( 101 m = g ^ (g << 1) ^ (g << 2) ^ (g << 3) ^ (g << 4), 102 m = (m >> 8) ^ (m & 255) ^ 99, 103 c[f] = m, 104 d[m] = f, 105 n = h[(e = h[(l = h[f])])], 106 p = (0x1010101 * n) ^ (0x10001 * e) ^ (0x101 * l) ^ (0x1010100 * f), 107 n = (0x101 * h[m]) ^ (0x1010100 * m), 108 e = 0; 109 4 > e; 110 e++ 111 ) 112 (a[e][f] = n = (n << 24) ^ (n >>> 8)), (b[e][m] = p = (p << 24) ^ (p >>> 8)); 113 for (e = 0; 5 > e; e++) (a[e] = a[e].slice(0)), (b[e] = b[e].slice(0)); 114 }, 115}; 116function t(a, b, c) { 117 if (4 !== b.length) throw new sjcl.exception.invalid("invalid aes block size"); 118 var d = a.b[c], 119 e = b[0] ^ d[0], 120 f = b[c ? 3 : 1] ^ d[1], 121 g = b[2] ^ d[2]; 122 b = b[c ? 1 : 3] ^ d[3]; 123 var h, 124 k, 125 l, 126 n = d.length / 4 - 2, 127 m, 128 p = 4, 129 r = [0, 0, 0, 0]; 130 h = a.s[c]; 131 a = h[0]; 132 var q = h[1], 133 v = h[2], 134 w = h[3], 135 x = h[4]; 136 for (m = 0; m < n; m++) 137 (h = a[e >>> 24] ^ q[(f >> 16) & 255] ^ v[(g >> 8) & 255] ^ w[b & 255] ^ d[p]), 138 (k = a[f >>> 24] ^ q[(g >> 16) & 255] ^ v[(b >> 8) & 255] ^ w[e & 255] ^ d[p + 1]), 139 (l = a[g >>> 24] ^ q[(b >> 16) & 255] ^ v[(e >> 8) & 255] ^ w[f & 255] ^ d[p + 2]), 140 (b = a[b >>> 24] ^ q[(e >> 16) & 255] ^ v[(f >> 8) & 255] ^ w[g & 255] ^ d[p + 3]), 141 (p += 4), 142 (e = h), 143 (f = k), 144 (g = l); 145 for (m = 0; 4 > m; m++) 146 (r[c ? 3 & -m : m] = 147 (x[e >>> 24] << 24) ^ (x[(f >> 16) & 255] << 16) ^ (x[(g >> 8) & 255] << 8) ^ x[b & 255] ^ d[p++]), 148 (h = e), 149 (e = f), 150 (f = g), 151 (g = b), 152 (b = h); 153 return r; 154} 155sjcl.bitArray = { 156 bitSlice: function (a, b, c) { 157 a = sjcl.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1); 158 return void 0 === c ? a : sjcl.bitArray.clamp(a, c - b); 159 }, 160 extract: function (a, b, c) { 161 var d = Math.floor((-b - c) & 31); 162 return ( 163 (((b + c - 1) ^ b) & -32 ? (a[(b / 32) | 0] << (32 - d)) ^ (a[(b / 32 + 1) | 0] >>> d) : a[(b / 32) | 0] >>> d) & 164 ((1 << c) - 1) 165 ); 166 }, 167 concat: function (a, b) { 168 if (0 === a.length || 0 === b.length) return a.concat(b); 169 var c = a[a.length - 1], 170 d = sjcl.bitArray.getPartial(c); 171 return 32 === d ? a.concat(b) : sjcl.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1)); 172 }, 173 bitLength: function (a) { 174 var b = a.length; 175 return 0 === b ? 0 : 32 * (b - 1) + sjcl.bitArray.getPartial(a[b - 1]); 176 }, 177 clamp: function (a, b) { 178 if (32 * a.length < b) return a; 179 a = a.slice(0, Math.ceil(b / 32)); 180 var c = a.length; 181 b = b & 31; 182 0 < c && b && (a[c - 1] = sjcl.bitArray.partial(b, a[c - 1] & (2147483648 >> (b - 1)), 1)); 183 return a; 184 }, 185 partial: function (a, b, c) { 186 return 32 === a ? b : (c ? b | 0 : b << (32 - a)) + 0x10000000000 * a; 187 }, 188 getPartial: function (a) { 189 return Math.round(a / 0x10000000000) || 32; 190 }, 191 equal: function (a, b) {
192 if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) return !1; 193 var c = 0, 194 d; 195 for (d = 0; d < a.length; d++) c |= a[d] ^ b[d]; 196 return 0 === c; 197 }, 198 $: function (a, b, c, d) { 199 var e; 200 e = 0; 201 for (void 0 === d && (d = []); 32 <= b; b -= 32) d.push(c), (c = 0); 202 if (0 === b) return d.concat(a); 203 for (e = 0; e < a.length; e++) d.push(c | (a[e] >>> b)), (c = a[e] << (32 - b)); 204 e = a.length ? a[a.length - 1] : 0; 205 a = sjcl.bitArray.getPartial(e); 206 d.push(sjcl.bitArray.partial((b + a) & 31, 32 < b + a ? c : d.pop(), 1)); 207 return d; 208 }, 209 i: function (a, b) { 210 return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]; 211 }, 212 byteswapM: function (a) { 213 var b, c; 214 for (b = 0; b < a.length; ++b) 215 (c = a[b]), (a[b] = (c >>> 24) | ((c >>> 8) & 0xff00) | ((c & 0xff00) << 8) | (c << 24)); 216 return a; 217 }, 218}; 219sjcl.codec.utf8String = { 220 fromBits: function (a) { 221 var b = "", 222 c = sjcl.bitArray.bitLength(a), 223 d, 224 e; 225 for (d = 0; d < c / 8; d++) 226 0 === (d & 3) && (e = a[d / 4]), (b += String.fromCharCode(((e >>> 8) >>> 8) >>> 8)), (e <<= 8); 227 return decodeURIComponent(escape(b)); 228 }, 229 toBits: function (a) { 230 a = unescape(encodeURIComponent(a)); 231 var b = [], 232 c, 233 d = 0; 234 for (c = 0; c < a.length; c++) (d = (d << 8) | a.charCodeAt(c)), 3 === (c & 3) && (b.push(d), (d = 0)); 235 c & 3 && b.push(sjcl.bitArray.partial(8 * (c & 3), d)); 236 return b; 237 }, 238}; 239sjcl.codec.hex = { 240 fromBits: function (a) { 241 var b = "", 242 c; 243 for (c = 0; c < a.length; c++) b += ((a[c] | 0) + 0xf00000000000).toString(16).substr(4); 244 return b.substr(0, sjcl.bitArray.bitLength(a) / 4); 245 }, 246 toBits: function (a) { 247 var b, 248 c = [], 249 d; 250 a = a.replace(/\s|0x/g, ""); 251 d = a.length; 252 a = a + "00000000"; 253 for (b = 0; b < a.length; b += 8) c.push(parseInt(a.substr(b, 8), 16) ^ 0); 254 return sjcl.bitArray.clamp(c, 4 * d); 255 }, 256}; 257sjcl.codec.base32 = { 258 B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", 259 X: "0123456789ABCDEFGHIJKLMNOPQRSTUV", 260 BITS: 32, 261 BASE: 5, 262 REMAINING: 27, 263 fromBits: function (a, b, c) { 264 var d = sjcl.codec.base32.BASE, 265 e = sjcl.codec.base32.REMAINING, 266 f = "", 267 g = 0, 268 h = sjcl.codec.base32.B, 269 k = 0, 270 l = sjcl.bitArray.bitLength(a); 271 c && (h = sjcl.codec.base32.X); 272 for (c = 0; f.length * d < l; ) 273 (f += h.charAt((k ^ (a[c] >>> g)) >>> e)), g < d ? ((k = a[c] << (d - g)), (g += e), c++) : ((k <<= d), (g -= d)); 274 for (; f.length & 7 && !b; ) f += "="; 275 return f; 276 }, 277 toBits: function (a, b) { 278 a = a.replace(/\s|=/g, "").toUpperCase(); 279 var c = sjcl.codec.base32.BITS, 280 d = sjcl.codec.base32.BASE, 281 e = sjcl.codec.base32.REMAINING, 282 f = [], 283 g, 284 h = 0, 285 k = sjcl.codec.base32.B, 286 l = 0, 287 n, 288 m = "base32"; 289 b && ((k = sjcl.codec.base32.X), (m = "base32hex")); 290 for (g = 0; g < a.length; g++) { 291 n = k.indexOf(a.charAt(g)); 292 if (0 > n) { 293 if (!b) 294 try { 295 return sjcl.codec.base32hex.toBits(a); 296 } catch (p) {} 297 throw new sjcl.exception.invalid("this isn't " + m + "!"); 298 } 299 h > e ? ((h -= e), f.push(l ^ (n >>> h)), (l = n << (c - h))) : ((h += d), (l ^= n << (c - h))); 300 } 301 h & 56 && f.push(sjcl.bitArray.partial(h & 56, l, 1)); 302 return f; 303 }, 304}; 305sjcl.codec.base32hex = { 306 fromBits: function (a, b) { 307 return sjcl.codec.base32.fromBits(a, b, 1); 308 }, 309 toBits: function (a) { 310 return sjcl.codec.base32.toBits(a, 1); 311 }, 312}; 313sjcl.codec.base64 = { 314 B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 315 fromBits: function (a, b, c) { 316 var d = "", 317 e = 0, 318 f = sjcl.codec.base64.B, 319 g = 0, 320 h = sjcl.bitArray.bitLength(a); 321 c && (f = f.substr(0, 62) + "-_"); 322 for (c = 0; 6 * d.length < h; ) 323 (d += f.charAt((g ^ (a[c] >>> e)) >>> 26)), 324 6 > e ? ((g = a[c] << (6 - e)), (e += 26), c++) : ((g <<= 6), (e -= 6)); 325 for (; d.length & 3 && !b; ) d += "="; 326 return d; 327 }, 328 toBits: function (a, b) { 329 a = a.replace(/\s|=/g, ""); 330 var c = [], 331 d, 332 e = 0, 333 f = sjcl.codec.base64.B, 334 g = 0, 335 h; 336 b && (f = f.substr(0, 62) + "-_"); 337 for (d = 0; d < a.length; d++) { 338 h = f.indexOf(a.charAt(d)); 339 if (0 > h) throw new sjcl.exception.invalid("this isn't base64!"); 340 26 < e ? ((e -= 26), c.push(g ^ (h >>> e)), (g = h << (32 - e))) : ((e += 6), (g ^= h << (32 - e))); 341 } 342 e & 56 && c.push(sjcl.bitArray.partial(e & 56, g, 1)); 343 return c; 344 }, 345}; 346sjcl.codec.base64url = { 347 fromBits: function (a) { 348 return sjcl.codec.base64.fromBits(a, 1, 1); 349 }, 350 toBits: function (a) { 351 return sjcl.codec.base64.toBits(a, 1); 352 }, 353}; 354sjcl.hash.sha256 = function (a) { 355 this.b[0] || this.O(); 356 a ? ((this.F = a.F.slice(0)), (this.A = a.A.slice(0)), (this.l = a.l)) : this.reset(); 357}; 358sjcl.hash.sha256.hash = function (a) { 359 return new sjcl.hash.sha256().update(a).finalize(); 360}; 361sjcl.hash.sha256.prototype = { 362 blockSize: 512, 363 reset: function () {
364 this.F = this.Y.slice(0); 365 this.A = []; 366 this.l = 0; 367 return this; 368 }, 369 update: function (a) { 370 "string" === typeof a && (a = sjcl.codec.utf8String.toBits(a)); 371 var b, 372 c = (this.A = sjcl.bitArray.concat(this.A, a)); 373 b = this.l; 374 a = this.l = b + sjcl.bitArray.bitLength(a); 375 if (0x1fffffffffffff < a) throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits"); 376 if ("undefined" !== typeof Uint32Array) { 377 var d = new Uint32Array(c), 378 e = 0; 379 for (b = 512 + b - ((512 + b) & 0x1ff); b <= a; b += 512) u(this, d.subarray(16 * e, 16 * (e + 1))), (e += 1); 380 c.splice(0, 16 * e); 381 } else for (b = 512 + b - ((512 + b) & 0x1ff); b <= a; b += 512) u(this, c.splice(0, 16)); 382 return this; 383 }, 384 finalize: function () { 385 var a, 386 b = this.A, 387 c = this.F, 388 b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]); 389 for (a = b.length + 2; a & 15; a++) b.push(0); 390 b.push(Math.floor(this.l / 0x100000000)); 391 for (b.push(this.l | 0); b.length; ) u(this, b.splice(0, 16)); 392 this.reset(); 393 return c; 394 }, 395 Y: [], 396 b: [], 397 O: function () { 398 function a(a) { 399 return (0x100000000 * (a - Math.floor(a))) | 0; 400 } 401 for (var b = 0, c = 2, d, e; 64 > b; c++) { 402 e = !0; 403 for (d = 2; d * d <= c; d++) 404 if (0 === c % d) { 405 e = !1; 406 break; 407 } 408 e && (8 > b && (this.Y[b] = a(Math.pow(c, 0.5))), (this.b[b] = a(Math.pow(c, 1 / 3))), b++); 409 } 410 }, 411}; 412function u(a, b) { 413 var c, 414 d, 415 e, 416 f = a.F, 417 g = a.b, 418 h = f[0], 419 k = f[1], 420 l = f[2], 421 n = f[3], 422 m = f[4], 423 p = f[5], 424 r = f[6], 425 q = f[7]; 426 for (c = 0; 64 > c; c++) 427 16 > c 428 ? (d = b[c]) 429 : ((d = b[(c + 1) & 15]), 430 (e = b[(c + 14) & 15]), 431 (d = b[c & 15] = 432 (((d >>> 7) ^ (d >>> 18) ^ (d >>> 3) ^ (d << 25) ^ (d << 14)) + 433 ((e >>> 17) ^ (e >>> 19) ^ (e >>> 10) ^ (e << 15) ^ (e << 13)) + 434 b[c & 15] + 435 b[(c + 9) & 15]) | 436 0)), 437 (d = 438 d + q + ((m >>> 6) ^ (m >>> 11) ^ (m >>> 25) ^ (m << 26) ^ (m << 21) ^ (m << 7)) + (r ^ (m & (p ^ r))) + g[c]), 439 (q = r), 440 (r = p), 441 (p = m), 442 (m = (n + d) | 0), 443 (n = l), 444 (l = k), 445 (k = h), 446 (h = 447 (d + ((k & l) ^ (n & (k ^ l))) + ((k >>> 2) ^ (k >>> 13) ^ (k >>> 22) ^ (k << 30) ^ (k << 19) ^ (k << 10))) | 448 0); 449 f[0] = (f[0] + h) | 0; 450 f[1] = (f[1] + k) | 0; 451 f[2] = (f[2] + l) | 0; 452 f[3] = (f[3] + n) | 0; 453 f[4] = (f[4] + m) | 0; 454 f[5] = (f[5] + p) | 0; 455 f[6] = (f[6] + r) | 0; 456 f[7] = (f[7] + q) | 0; 457} 458sjcl.mode.ccm = { 459 name: "ccm", 460 G: [], 461 listenProgress: function (a) { 462 sjcl.mode.ccm.G.push(a); 463 }, 464 unListenProgress: function (a) { 465 a = sjcl.mode.ccm.G.indexOf(a); 466 -1 < a && sjcl.mode.ccm.G.splice(a, 1); 467 }, 468 fa: function (a) { 469 var b = sjcl.mode.ccm.G.slice(), 470 c; 471 for (c = 0; c < b.length; c += 1) b[c](a); 472 }, 473 encrypt: function (a, b, c, d, e) { 474 var f, 475 g = b.slice(0), 476 h = sjcl.bitArray, 477 k = h.bitLength(c) / 8, 478 l = h.bitLength(g) / 8; 479 e = e || 64; 480 d = d || []; 481 if (7 > k) throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"); 482 for (f = 2; 4 > f && l >>> (8 * f); f++); 483 f < 15 - k && (f = 15 - k); 484 c = h.clamp(c, 8 * (15 - f)); 485 b = sjcl.mode.ccm.V(a, b, c, d, e, f); 486 g = sjcl.mode.ccm.C(a, g, c, b, e, f); 487 return h.concat(g.data, g.tag); 488 }, 489 decrypt: function (a, b, c, d, e) { 490 e = e || 64; 491 d = d || []; 492 var f = sjcl.bitArray, 493 g = f.bitLength(c) / 8, 494 h = f.bitLength(b), 495 k = f.clamp(b, h - e), 496 l = f.bitSlice(b, h - e), 497 h = (h - e) / 8; 498 if (7 > g) throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"); 499 for (b = 2; 4 > b && h >>> (8 * b); b++); 500 b < 15 - g && (b = 15 - g); 501 c = f.clamp(c, 8 * (15 - b)); 502 k = sjcl.mode.ccm.C(a, k, c, l, e, b); 503 a = sjcl.mode.ccm.V(a, k.data, c, d, e, b); 504 if (!f.equal(k.tag, a)) throw new sjcl.exception.corrupt("ccm: tag doesn't match"); 505 return k.data; 506 }, 507 na: function (a, b, c, d, e, f) { 508 var g = [], 509 h = sjcl.bitArray, 510 k = h.i; 511 d = [h.partial(8, (b.length ? 64 : 0) | ((d - 2) << 2) | (f - 1))]; 512 d = h.concat(d, c); 513 d[3] |= e;
514 d = a.encrypt(d); 515 if (b.length) 516 for ( 517 c = h.bitLength(b) / 8, 518 65279 >= c ? (g = [h.partial(16, c)]) : 0xffffffff >= c && (g = h.concat([h.partial(16, 65534)], [c])), 519 g = h.concat(g, b), 520 b = 0; 521 b < g.length; 522 b += 4 523 ) 524 d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0]))); 525 return d; 526 }, 527 V: function (a, b, c, d, e, f) { 528 var g = sjcl.bitArray, 529 h = g.i; 530 e /= 8; 531 if (e % 2 || 4 > e || 16 < e) throw new sjcl.exception.invalid("ccm: invalid tag length"); 532 if (0xffffffff < d.length || 0xffffffff < b.length) 533 throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data"); 534 c = sjcl.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f); 535 for (d = 0; d < b.length; d += 4) c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0]))); 536 return g.clamp(c, 8 * e); 537 }, 538 C: function (a, b, c, d, e, f) { 539 var g, 540 h = sjcl.bitArray; 541 g = h.i; 542 var k = b.length, 543 l = h.bitLength(b), 544 n = k / 50, 545 m = n; 546 c = h 547 .concat([h.partial(8, f - 1)], c) 548 .concat([0, 0, 0]) 549 .slice(0, 4); 550 d = h.bitSlice(g(d, a.encrypt(c)), 0, e); 551 if (!k) return { tag: d, data: [] }; 552 for (g = 0; g < k; g += 4) 553 g > n && (sjcl.mode.ccm.fa(g / k), (n += m)), 554 c[3]++, 555 (e = a.encrypt(c)), 556 (b[g] ^= e[0]), 557 (b[g + 1] ^= e[1]), 558 (b[g + 2] ^= e[2]), 559 (b[g + 3] ^= e[3]); 560 return { tag: d, data: h.clamp(b, l) }; 561 }, 562}; 563sjcl.mode.ocb2 = { 564 name: "ocb2", 565 encrypt: function (a, b, c, d, e, f) { 566 if (128 !== sjcl.bitArray.bitLength(c)) throw new sjcl.exception.invalid("ocb iv must be 128 bits"); 567 var g, 568 h = sjcl.mode.ocb2.S, 569 k = sjcl.bitArray, 570 l = k.i, 571 n = [0, 0, 0, 0]; 572 c = h(a.encrypt(c)); 573 var m, 574 p = []; 575 d = d || []; 576 e = e || 64; 577 for (g = 0; g + 4 < b.length; g += 4) 578 (m = b.slice(g, g + 4)), (n = l(n, m)), (p = p.concat(l(c, a.encrypt
578(l(c, m))))), (c = h(c)); 579 m = b.slice(g); 580 b = k.bitLength(m); 581 g = a.encrypt(l(c, [0, 0, 0, b])); 582 m = k.clamp(l(m.concat([0, 0, 0]), g), b); 583 n = l(n, l(m.concat([0, 0, 0]), g)); 584 n = a.encrypt(l(n, l(c, h(c)))); 585 d.length && (n = l(n, f ? d : sjcl.mode.ocb2.pmac(a, d))); 586 return p.concat(k.concat(m, k.clamp(n, e))); 587 }, 588 decrypt: function (a, b, c, d, e, f) { 589 if (128 !== sjcl.bitArray.bitLength(c)) throw new sjcl.exception.invalid("ocb iv must be 128 bits"); 590 e = e || 64; 591 var g = sjcl.mode.ocb2.S, 592 h = sjcl.bitArray, 593 k = h.i, 594 l = [0, 0, 0, 0], 595 n = g(a.encrypt(c)), 596 m, 597 p, 598 r = sjcl.bitArray.bitLength(b) - e, 599 q = []; 600 d = d || []; 601 for (c = 0; c + 4 < r / 32; c += 4) 602 (m = k(n, a.decrypt(k(n, b.slice(c, c + 4))))), (l = k(l, m)), (q = q.concat(m)), (n = g(n)); 603 p = r - 32 * c; 604 m = a.encrypt(k(n, [0, 0, 0, p])); 605 m = k(m, h.clamp(b.slice(c), p).concat([0, 0, 0])); 606 l = k(l, m); 607 l = a.encrypt(k(l, k(n, g(n)))); 608 d.length && (l = k(l, f ? d : sjcl.mode.ocb2.pmac(a, d))); 609 if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl.exception.corrupt("ocb: tag doesn't match"); 610 return q.concat(h.clamp(m, p)); 611 }, 612 pmac: function (a, b) { 613 var c, 614 d = sjcl.mode.ocb2.S, 615 e = sjcl.bitArray, 616 f = e.i, 617 g = [0, 0, 0, 0], 618 h = a.encrypt([0, 0, 0, 0]), 619 h = f(h, d(d(h))); 620 for (c = 0; c + 4 < b.length; c += 4) (h = d(h)), (g = f(g, a.encrypt(f(h, b.slice(c, c + 4))))); 621 c = b.slice(c); 622 128 > e.bitLength(c) && ((h = f(h, d(h))), (c = e.concat(c, [-2147483648, 0, 0, 0]))); 623 g = f(g, c); 624 return a.encrypt(f(d(f(h, d(h))), g)); 625 }, 626 S: function (a) { 627 return [ 628 (a[0] << 1) ^ (a[1] >>> 31), 629 (a[1] << 1) ^ (a[2] >>> 31), 630 (a[2] << 1) ^ (a[3] >>> 31), 631 (a[3] << 1) ^ (135 * (a[0] >>> 31)), 632 ]; 633 }, 634}; 635sjcl.mode.gcm = { 636 name: "gcm", 637 encrypt: function (a, b, c, d, e) { 638 var f = b.slice(0); 639 b = sjcl.bitArray; 640 d = d || []; 641 a = sjcl.mode.gcm.C(!0, a, f, d, c, e || 128); 642 return b.concat(a.data, a.tag); 643 }, 644 decrypt: function (a, b, c, d, e) { 645 var f = b.slice(0), 646 g = sjcl.bitArray, 647 h = g.bitLength(f); 648 e = e || 128; 649 d = d || []; 650 e <= h ? ((b = g.bitSlice(f, h - e)), (f = g.bitSlice(f, 0, h - e))) : ((b = f), (f = [])); 651 a = sjcl.mode.gcm.C(!1, a, f, d, c, e); 652 if (!g.equal(a.tag, b)) throw new sjcl.exception.corrupt("gcm: tag doesn't match"); 653 return a.data; 654 }, 655 ka: function (a, b) { 656 var c, 657 d, 658 e, 659 f, 660 g, 661 h = sjcl.bitArray.i; 662 e = [0, 0, 0, 0]; 663 f = b.slice(0); 664 for (c = 0; 128 > c; c++) { 665 (d = 0 !== (a[Math.floor(c / 32)] & (1 << (31 - (c % 32))))) && (e = h(e, f)); 666 g = 0 !== (f[3] & 1); 667 for (d = 3; 0 < d; d--) f[d] = (f[d] >>> 1) | ((f[d - 1] & 1) << 31); 668 f[0] >>>= 1; 669 g && (f[0] ^= -0x1f000000); 670 } 671 return e; 672 }, 673 j: function (a, b, c) { 674 var d, 675 e = c.length; 676 b = b.slice(0); 677 for (d = 0; d < e; d += 4) 678 (b[0] ^= 0xffffffff & c[d]), 679 (b[1] ^= 0xffffffff & c[d + 1]), 680 (b[2] ^= 0xffffffff & c[d + 2]), 681 (b[3] ^= 0xffffffff & c[d + 3]), 682 (b = sjcl.mode.gcm.ka(b, a)); 683 return b; 684 }, 685 C: function (a, b, c, d, e, f) { 686 var g, 687 h, 688 k, 689 l, 690 n, 691 m, 692 p, 693 r, 694 q = sjcl.bitArray; 695 m = c.length; 696 p = q.bitLength(c); 697 r = q.bitLength(d); 698 h = q.bitLength(e); 699 g = b.encrypt([0, 0, 0, 0]); 700 96 === h 701 ? ((e = e.slice(0)), (e = q.concat(e, [1]))) 702 : ((e = sjcl.mode.gcm.j(g, [0, 0, 0, 0], e)), 703 (e = sjcl.mode.gcm.j(g, e, [0, 0, Math.floor(h / 0x100000000), h & 0xffffffff]))); 704 h = sjcl.mode.gcm.j(g, [0, 0, 0, 0], d); 705 n = e.slice(0); 706 d = h.slice(0); 707 a || (d = sjcl.mode.gcm.j(g, h, c)); 708 for (l = 0; l < m; l += 4) 709 n[3]++, (k = b.encrypt(n)), (c[l] ^= k[0]), (c[l + 1] ^= k[1]), (c[l + 2] ^= k[2]), (c[l + 3] ^= k[3]); 710 c = q.clamp(c, p); 711 a && (d = sjcl.mode.gcm.j(g, h, c)); 712 a = [Math.floor(r / 0x100000000), r & 0xffffffff, Math.floor(p / 0x100000000), p & 0xffffffff]; 713 d = sjcl.mode.gcm.j(g, d, a); 714 k = b.encrypt(e); 715 d[0] ^= k[0]; 716 d[1] ^= k[1]; 717 d[2] ^= k[2]; 718 d[3] ^= k[3]; 719 return { tag: q.bitSlice(d, 0, f), data: c }; 720 }, 721}; 722sjcl.misc.hmac = function (a, b) { 723 this.W = b = b || sjcl.hash.sha256; 724 var c = [[], []], 725 d, 726 e = b.prototype.blockSize / 32; 727 this.w = [new b(), new b()]; 728 a.length > e && (a = b.hash(a)); 729 for (d = 0; d < e; d++) (c[0][d] = a[d] ^ 909522486), (c[1][d] = a[d] ^ 1549556828); 730 this.w[0].update(c[0]); 731 this.w[1].update(c[1]); 732 this.R = new b(this.w[0]); 733}; 734sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function (a) { 735 if (this.aa) throw new sjcl.exception.invalid("encrypt on already updated hmac called!"); 736 this.update(a); 737 return this.digest(a); 738}; 739sjcl.misc.hmac.prototype.reset = function () { 740 this.R = new this.W(this.w[0]); 741 this.aa = !1; 742}; 743sjcl.misc.hmac.prototype.update = function (a) { 744 this.aa = !0; 745 this.R.update(a); 746}; 747sjcl.misc.hmac.prototype.digest = function () { 748 var a = this.R.finalize(), 749 a = new this.W(this.w[1]).update(a).finalize(); 750 this.reset(); 751 return a; 752}; 753sjcl.misc.pbkdf2 = function (a, b, c, d, e) { 754 c = c || 1e4; 755 if (0 > d || 0 > c) throw new sjcl.exception.invalid("invalid params to pbkdf2"); 756 "string" === typeof a && (a = sjcl.codec.utf8String.toBits(a)); 757 "string" === typeof b && (b = sjcl.codec.utf8String.toBits(b)); 758 e = e || sjcl.misc.hmac; 759 a = new e(a); 760 var f, 761 g, 762 h, 763 k, 764 l = [], 765 n = sjcl.bitArray; 766 for (k = 1; 32 * l.length < (d || 1); k++) {
767 e = f = a.encrypt(n.concat(b, [k])); 768 for (g = 1; g < c; g++) for (f = a.encrypt(f), h = 0; h < f.length; h++) e[h] ^= f[h]; 769 l = l.concat(e); 770 } 771 d && (l = n.clamp(l, d)); 772 return l; 773}; 774sjcl.prng = function (a) { 775 this.c = [new sjcl.hash.sha256()]; 776 this.m = [0]; 777 this.P = 0; 778 this.H = {}; 779 this.N = 0; 780 this.U = {}; 781 this.Z = this.f = this.o = this.ha = 0; 782 this.b = [0, 0, 0, 0, 0, 0, 0, 0]; 783 this.h = [0, 0, 0, 0]; 784 this.L = void 0; 785 this.M = a; 786 this.D = !1; 787 this.K = { progress: {}, seeded: {} }; 788 this.u = this.ga = 0; 789 this.I = 1; 790 this.J = 2; 791 this.ca = 0x10000; 792 this.T = [0, 48, 64, 96, 128, 192, 0x100, 384, 512, 768, 1024]; 793 this.da = 3e4; 794 this.ba = 80; 795}; 796sjcl.prng.prototype = { 797 randomWords: function (a, b) { 798 var c = [], 799 d; 800 d = this.isReady(b); 801 var e; 802 if (d === this.u) throw new sjcl.exception.notReady("generator isn't seeded"); 803 if (d & this.J) { 804 d = !(d & this.I); 805 e = []; 806 var f = 0, 807 g; 808 this.Z = e[0] = new Date().valueOf() + this.da; 809 for (g = 0; 16 > g; g++) e.push((0x100000000 * Math.random()) | 0); 810 for ( 811 g = 0; 812 g < this.c.length && 813 ((e = e.concat(this.c[g].finalize())), (f += this.m[g]), (this.m[g] = 0), d || !(this.P & (1 << g))); 814 g++ 815 ); 816 this.P >= 1 << this.c.length && (this.c.push(new sjcl.hash.sha256()), this.m.push(0)); 817 this.f -= f; 818 f > this.o && (this.o = f); 819 this.P++; 820 this.b = sjcl.hash.sha256.hash(this.b.concat(e)); 821 this.L = new sjcl.cipher.aes(this.b); 822 for (d = 0; 4 > d && ((this.h[d] = (this.h[d] + 1) | 0), !this.h[d]); d++); 823 } 824 for (d = 0; d < a; d += 4) 0 === (d + 1) % this.ca && y(this), (e = z(this)), c.push(e[0], e[1], e[2], e[3]); 825 y(this); 826 return c.slice(0, a); 827 }, 828 setDefaultParanoia: function (a, b) { 829 if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) 830 throw new sjcl.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing"); 831 this.M = a; 832 }, 833 addEntropy: function (a, b, c) { 834 c = c || "user"; 835 var d, 836 e, 837 f = new Date().valueOf(), 838 g = this.H[c], 839 h = this.isReady(), 840 k = 0; 841 d = this.U[c]; 842 void 0 === d && (d = this.U[c] = this.ha++); 843 void 0 === g && (g = this.H[c] = 0); 844 this.H[c] = (this.H[c] + 1) % this.c.length; 845 switch (typeof a) { 846 case "number": 847 void 0 === b && (b = 1); 848 this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]); 849 break; 850 case "object": 851 c = Object.prototype.toString.call(a); 852 if ("[object Uint32Array]" === c) { 853 e = []; 854 for (c = 0; c < a.length; c++) e.push(a[c]); 855 a = e; 856 } else 857 for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) "number" !== typeof a[c] && (k = 1); 858 if (!k) { 859 if (void 0 === b) for (c = b = 0; c < a.length; c++) for (e = a[c]; 0 < e; ) b++, (e = e >>> 1); 860 this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a)); 861 } 862 break; 863 case "string": 864 void 0 === b && (b = a.length); 865 this.c[g].update([d, this.N++, 3, b, f, a.length]); 866 this.c[g].update(a); 867 break; 868 default: 869 k = 1; 870 } 871 if (k) throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string"); 872 this.m[g] += b; 873 this.f += b; 874 h === this.u && 875 (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress())); 876 }, 877 isReady: function (a) { 878 a = this.T[void 0 !== a ? a : this.M]; 879 return this.o && this.o >= a 880 ? this.m[0] > this.ba && new Date().valueOf() > this.Z 881 ? this.J | this.I 882 : this.I 883 : this.f >= a 884 ? this.J | this.u 885 : this.u; 886 }, 887 getProgress: function (a) { 888 a = this.T[a ? a : this.M]; 889 return this.o >= a ? 1 : this.f > a ? 1 : this.f / a; 890 }, 891 startCollectors: function () { 892 if (!this.D) { 893 this.a = { 894 loadTimeCollector: B(this, this.ma), 895 mouseCollector: B(this, this.oa), 896 keyboardCollector: B(this, this.la), 897 accelerometerCollector: B(this, this.ea), 898 touchCollector: B(this, this.qa), 899 }; 900 if (window.addEventListener) 901 window.addEventListener("load", this.a.loadTimeCollector, !1), 902 window.addEventListener("mousemove", this.a.mouseCollector, !1), 903 window.addEventListener("keypress", this.a.keyboardCollector, !1), 904 window.addEventListener("devicemotion", this.a.accelerometerCollector, !1), 905 window.addEventListener("touchmove", this.a.touchCollector, !1); 906 else if (document.attachEvent) 907 document.attachEvent("onload", this.a.loadTimeCollector), 908 document.attachEvent("onmousemove", this.a.mouseCollector), 909 document.attachEvent("keypress", this.a.keyboardCollector); 910 else throw new sjcl.exception.bug("can't attach event"); 911 this.D = !0; 912 } 913 }, 914 stopCollectors: function () { 915 this.D && 916 (window.removeEventListener 917 ? (window.removeEventListener("load", this.a.loadTimeCollector, !1), 918 window.removeEventListener("mousemove", this.a.mouseCollector, !1), 919 window.removeEventListener("keypress", this.a.keyboardCollector, !1), 920 window.removeEventListener("devicemotion", this.a.accelerometerCollector, !1), 921 window.removeEventListener("touchmove", this.a.touchCollector, !1)) 922 : document.detachEvent && 923 (document.detachEvent("onload", this.a.loadTimeCollector), 924 document.detachEvent("onmousemove", this.a.mouseCollector), 925 document.detachEvent("keypress", this.a.keyboardCollector)), 926 (this.D = !1)); 927 }, 928 addEventListener: function (a, b) { 929 this.K[a][this.ga++] = b; 930 }, 931 removeEventListener: function (a, b) { 932 var c, 933 d, 934 e = this.K[a], 935 f = []; 936 for (d in e) e.hasOwnProperty(d) && e[d] === b && f.push(d); 937 for (c = 0; c < f.length; c++) (d = f[c]), delete e[d]; 938 }, 939 la: function () { 940 C(this, 1); 941 }, 942 oa: function (a) { 943 var b, c; 944 try { 945 (b = a.x || a.clientX || a.offsetX || 0), (c = a.y || a.clientY || a.offsetY || 0
945); 946 } catch (d) { 947 c = b = 0; 948 } 949 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse"); 950 C(this, 0); 951 }, 952 qa: function (a) { 953 a = a.touches[0] || a.changedTouches[0]; 954 this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch"); 955 C(this, 0); 956 }, 957 ma: function () { 958 C(this, 2); 959 }, 960 ea: function (a) { 961 a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z; 962 if (window.orientation) { 963 var b = window.orientation; 964 "number" === typeof b && this.addEntropy(b, 1, "accelerometer"); 965 } 966 a && this.addEntropy(a, 2, "accelerometer"); 967 C(this, 0); 968 }, 969}; 970function A(a, b) { 971 var c, 972 d = sjcl.random.K[a], 973 e = []; 974 for (c in d) d.hasOwnProperty(c) && e.push(d[c]); 975 for (c = 0; c < e.length; c++) e[c](b); 976} 977function C(a, b) { 978 "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now 979 ? a.addEntropy(window.performance.now(), b, "loadtime") 980 : a.addEntropy(new Date().valueOf(), b, "loadtime"); 981} 982function y(a) { 983 a.b = z(a).concat(z(a)); 984 a.L = new sjcl.cipher.aes(a.b); 985} 986function z(a) { 987 for (var b = 0; 4 > b && ((a.h[b] = (a.h[b] + 1) | 0), !a.h[b]); b++); 988 return a.L.encrypt(a.h); 989} 990function B(a, b) { 991 return function () { 992 b.apply(a, arguments); 993 }; 994} 995sjcl.random = new sjcl.prng(6); 996a: try { 997 var D, E, F, G; 998 if ((G = "undefined" !== typeof module && module.exports)) { 999 var H; 1000 try { 1001 H = require("crypto"); 1002 } catch (a) { 1003 H = null; 1004 } 1005 G = E = H; 1006 } 1007 if (G && E.randomBytes) 1008 (D = E.randomBytes(128)), 1009 (D = new Uint32Array(new Uint8Array(D).buffer)), 1010 sjcl.random.addEntropy(D, 1024, "crypto['randomBytes']"); 1011 else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) { 1012 F = new Uint32Array(32); 1013 if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F); 1014 else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F); 1015 else break a; 1016 sjcl.random.addEntropy(F, 1024, "crypto['getRandomValues']"); 1017 } 1018} catch (a) { 1019 "undefined" !== typeof window && 1020 window.console && 1021 (console.log("There was an error collecting entropy from the browser:"), console.log(a)); 1022} 1023sjcl.json = { 1024 defaults: { v: 1, iter: 1e4, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" }, 1025 ja: function (a, b, c, d) { 1026 c = c || {}; 1027 d = d || {}; 1028 var e = sjcl.json, 1029 f = e.g({ iv: sjcl.random.randomWords(4, 0) }, e.defaults), 1030 g; 1031 e.g(f, c); 1032 c = f.adata; 1033 "string" === typeof f.salt && (f.salt = sjcl.codec.base64.toBits(f.salt)); 1034 "string" === typeof f.iv && (f.iv = sjcl.codec.base64.toBits(f.iv)); 1035 if ( 1036 !sjcl.mode[f.mode] || 1037 !sjcl.cipher[f.cipher] || 1038 ("string" === typeof a && 100 >= f.iter) || 1039 (64 !== f.ts && 96 !== f.ts && 128 !== f.ts) || 1040 (128 !== f.ks && 192 !== f.ks && 0x100 !== f.ks) || 1041 2 > f.iv.length || 1042 4 < f.iv.length 1043 ) 1044 throw new sjcl.exception.invalid("json encrypt: invalid parameters"); 1045 "string" === typeof a 1046 ? ((g = sjcl.misc.cachedPbkdf2(a, f)), (a = g.key.slice(0, f.ks / 32)), (f.salt = g.salt)) 1047 : sjcl.ecc && 1048 a instanceof sjcl.ecc.elGamal.publicKey && 1049 ((g = a.kem()), (f.kemtag = g.tag), (a = g.key.slice(0, f.ks / 32))); 1050 "string" === typeof b && (b = sjcl.codec.utf8String.toBits(b)); 1051 "string" === typeof c && (f.adata = c = sjcl.codec.utf8String.toBits(c)); 1052 g = new sjcl.cipher[f.cipher](a); 1053 e.g(d, f); 1054 d.key = a; 1055 f.ct = 1056 "ccm" === f.mode && sjcl.arrayBuffer && sjcl.arrayBuffer.ccm && b instanceof ArrayBuffer 1057 ? sjcl.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) 1058 : sjcl.mode[f.mode].encrypt(g, b, f.iv, c, f.ts); 1059 return f; 1060 }, 1061 encrypt: function (a, b, c, d) { 1062 var e = sjcl.json, 1063 f = e.ja.apply(e, arguments); 1064 return e.encode(f); 1065 }, 1066 ia: function (a, b, c, d) { 1067 c = c || {}; 1068 d = d || {}; 1069 var e = sjcl.json; 1070 b = e.g(e.g(e.g({}, e.defaults), b), c, !0); 1071 var f, g; 1072 f = b.adata; 1073 "string" === typeof b.salt && (b.salt = sjcl.codec.base64.toBits(b.salt)); 1074 "string" === typeof b.iv && (b.iv = sjcl.codec.base64.toBits(b.iv)); 1075 if ( 1076 !sjcl.mode[b.mode] || 1077 !sjcl.cipher[b.cipher] || 1078 ("string" === typeof a && 100 >= b.iter) || 1079 (64 !== b.ts && 96 !== b.ts && 128 !== b.ts) || 1080 (128 !== b.ks && 192 !== b.ks && 0x100 !== b.ks) || 1081 !b.iv || 1082 2 > b.iv.length || 1083 4 < b.iv.length 1084 ) 1085 throw new sjcl.exception.invalid("json decrypt: invalid parameters"); 1086 "string" === typeof a 1087 ? ((g = sjcl.misc.cachedPbkdf2(a, b)), (a = g.key.slice(0, b.ks / 32)), (b.salt = g.salt)) 1088 : sjcl.ecc && 1089 a instanceof sjcl.ecc.elGamal.secretKey && 1090 (a = a.unkem(sjcl.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)); 1091 "string" === typeof f && (f = sjcl.codec.utf8String.toBits(f)); 1092 g = new sjcl.cipher[b.cipher](a); 1093 f = 1094 "ccm" === b.mode && sjcl.arrayBuffer && sjcl.arrayBuffer.ccm && b.ct instanceof ArrayBuffer 1095 ? sjcl.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) 1096 : sjcl.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts); 1097 e.g(d, b); 1098 d.key = a; 1099 return 1 === c.raw ? f : sjcl.codec.utf8String.fromBits(f); 1100 }, 1101 decrypt: function (a, b, c, d) { 1102 var e = sjcl.json; 1103 return e.ia(a, e.decode(b), c, d); 1104 }, 1105 encode: function (a) { 1106 var b, 1107 c = "{", 1108 d = ""; 1109 for (b in a) 1110 if (a.hasOwnProperty(b)) { 1111 if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl.exception.invalid("json encode: invalid property name"); 1112 c += d + '"' + b + '":'; 1113 d = ","; 1114 switch (typeof a[b]) { 1115 case "number": 1116 case "boolean": 1117 c += a[b]; 1118 break; 1119 case "string": 1120 c += '"' + escape(a[b]) + '"'; 1121 break; 1122 case "object": 1123 c += '"' + sjcl.codec.base64.fromBits(a[b], 0) + '"'; 1124 break; 1125 default: 1126 throw new sjcl.exception.bug("json encode: unsupported type"); 1127 } 1128 } 1129 return c + "}"; 1130 }, 1131 decode: function (a) { 1132 a = a.replace(/\s/g, ""); 1133 if (!a.match(/^\{.*\}$/)) throw new sjcl.exception.invalid("json decode: this isn't json!"); 1134 a = a.replace(/^\{|\}$/g, "").split(/,/); 1135 var b = {}, 1136 c, 1137 d; 1138 for (c = 0; c < a.length; c++) { 1139 if ( 1140 !(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i)) 1141 ) 1142 throw new sjcl.exception.invalid("json decode: this isn't json!"); 1143 null != d[3] 1144 ? (b[d[2]] = parseInt(d[3], 10)) 1145 : null != d[4] 1146 ? (b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl.codec.base64.toBits(d[4]) : unescape(d[4])) 1147 : null != d[5] && (b[d[2]] = "true" === d[5]); 1148 } 1149 return b; 1150 }, 1151 g: function (a, b, c) { 1152 void 0 === a && (a = {}); 1153 if (void 0 === b) return a; 1154 for (var d in b) 1155 if (b.hasOwnProperty(d)) { 1156 if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl.exception.invalid("required parameter overridden"); 1157 a[d] = b[d]; 1158 } 1159 return a; 1160 }, 1161 sa: function (a, b) { 1162 var c = {}, 1163 d; 1164 for (d in a) a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]); 1165 return c; 1166 }, 1167 ra: function (a, b) { 1168 var c = {}, 1169 d; 1170 for (d = 0; d < b.length; d++) void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]); 1171 return c; 1172 }, 1173}; 1174sjcl.encrypt = sjcl.json.encrypt; 1175sjcl.decrypt = sjcl.json.decrypt; 1176sjcl.misc.pa = {}; 1177sjcl.misc.cachedPbkdf2 = function (a, b) { 1178 var c = sjcl.misc.pa, 1179 d; 1180 b = b || {}; 1181 d = b.iter || 1e3; 1182 c = c[a] = c[a] || {}; 1183 d = c[d] = c[d] || { firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl.random.randomWords(2, 0) }; 1184 c = void 0 === b.salt ? d.firstSalt : b.salt; 1185 d[c] = d[c] || sjcl.misc.pbkdf2(a, c, b.iter); 1186 return { key: d[c].slice(0), salt: c.slice(0) }; 1187}; 1188"undefined" !== typeof module && module.exports && (module.exports = sjcl); 1189"function" === typeof define && 1190 define([], function () { 1191 return sjcl; 1192 }); 1193 1194/* 1195 * Simple Email Hasher by APS Document 1196 * https://drive.google.com/file/d/1LPc9FoBUpyg64GPul-b4vSqiMwxt4N5y/view 1197 */ 1198 1199// Normalize email address so that it is lowercase without any whitespace let 1200ApaLib.normalizeEmail = function (string) { 1201 return string 1202 .trim() 1203 .toLowerCase() 1204 .replace(/\+[^@]*@/g, "@"); 1205}; 1206 1207// Check to make sure that the value is a valid email address let 1208ApaLib.isValidEmailAddress = function (emailAddress) { 1209 return (emailAddress.match(/@/g) || []).length === 1; 1210}; 1211 1212// Normalizes an email address value and then checks to make sure it is a valid email address 1213ApaLib.emailNormalizer = function (record) { 1214 let email = ApaLib.normalizeEmail(record); 1215 if (ApaLib.isValidEmailAddress(email)) { 1216 return email; 1217 } else { 1218 console.error(record + "is not a valid email."); 1219 } 1220}; 1221
1222// Main function takes an argument file: string[] || string and hashes the value(s) 1223ApaLib.emailHasher = function (file) { 1224 try { 1225 if (Array.isArray(file)) { 1226 let arrayOfRecords = []; 1227 file.forEach(function (record) { 1228 arrayOfRecords.push(sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(ApaLib.emailNormalizer(record)))); 1229 }); 1230 return arrayOfRecords; 1231 } else if (typeof file === "string") { 1232 return sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(ApaLib.emailNormalizer(file))); 1233 } else { 1234 console.error("Error: typeof argument should be array or string" + file); 1235 } 1236 } catch (err) { 1237 console.error(err); 1238 } 1239}; 1240 1241/* 1242 * Client-side Implementation. 1243 */ 1244ApaLib.appendScript = function () { 1245 const APSTAG_SCRIPT_URL = "https://c.amazon-adsystem.com/aax2/apstag.js"; 1246 const scriptElm = document.createElement("script"); 1247 scriptElm.src = APSTAG_SCRIPT_URL; 1248 document.head.appendChild(scriptElm); 1249}; 1250 1251ApaLib.transitNextPage = function () { 1252 const formElm = document.getElementById("login"); 1253 if (!formElm) return; 1254 const formElmActionUrl = formElm.action; 1255 location.href = formElmActionUrl; 1256}; 1257 1258ApaLib.sendData = function (hashMail) { 1259 const COOKIE_NAME_AMZN_TOKEN = "AMZN-Token"; 1260 const PUB_ID = "bb49897c-6ae0-4d48-8db0-c4531321096f"; 1261 const cookieList = document.cookie.split(";"); 1262 const isExistAmznToken = cookieList.some(function (value) { 1263 return value.includes(COOKIE_NAME_AMZN_TOKEN); 1264 }); 1265 1266 if ( 1267 typeof apstag === "undefined" || 1268 typeof apstag.init !== "function" || 1269 typeof apstag.upa !== "function" || 1270 typeof apstag.rpa !== "function" 1271 ) { 1272 return; 1273 } 1274 1275 // init APS 1276 apstag.init({ 1277 pubID: PUB_ID, 1278 bidTimeout: 2e3, 1279 }); 1280 const tokenConfig = { 1281 hashedRecords: [ 1282 { 1283 type: "email", 1284 record: hashMail, 1285 }, 1286 ], 1287 }; 1288 if (isExistAmznToken) { 1289 apstag.upa(tokenConfig, ApaLib.transitNextPage); 1290 } else { 1291 apstag.rpa(tokenConfig, ApaLib.transitNextPage); 1292 } 1293}; 1294 1295ApaLib.submitHashMail = function (mailAddresVal) { 1296 /** 1297 * emailHasherã®å¼æ°ã«ã¦ã¼ã¶ã¼ã®ã¡ã¼ã«ã¢ãã¬ã¹ãæå®ãã¾ã 1298 * ⻠以ä¸ã§ã¯ä»®ã§è¨è¿°ãã¦ãã¾ãã®ã§å®éã«åå¾ã§ããæ å ±ããç«¶ã£ã¦é ãã¾ãç¨ãé¡ããããã¾ãã 1299 */ 1300 const hashMail = ApaLib.emailHasher(mailAddresVal); 1301 ApaLib.sendData(hashMail); 1302};
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.