|
1 |
+ |
import { keccak_256 } from "@noble/hashes/sha3.js" |
|
2 |
+ |
|
| 1 |
3 |
|
class ContractCall extends HTMLElement { |
|
4 |
+ |
/** |
|
5 |
+ |
* ContractCall Web Component |
|
6 |
+ |
* |
|
7 |
+ |
* A custom HTML element for interacting with Ethereum smart contracts. |
|
8 |
+ |
* Supports both read-only (view/pure) and write operations through wallet integration. |
|
9 |
+ |
* |
|
10 |
+ |
* @example |
|
11 |
+ |
* Basic usage with inline ABI: |
|
12 |
+ |
* ```html |
|
13 |
+ |
* <contract-call |
|
14 |
+ |
* contract-address="0x1234567890123456789012345678901234567890" |
|
15 |
+ |
* method-name="balanceOf" |
|
16 |
+ |
* method-args='["0xabcdef1234567890123456789012345678901234"]' |
|
17 |
+ |
* abi='[{"type":"function","name":"balanceOf","inputs":[{"type":"address","name":"owner"}],"outputs":[{"type":"uint256","name":""}],"stateMutability":"view"}]'> |
|
18 |
+ |
* </contract-call> |
|
19 |
+ |
* ``` |
|
20 |
+ |
* |
|
21 |
+ |
* @example |
|
22 |
+ |
* Using ABI from URL: |
|
23 |
+ |
* ```html |
|
24 |
+ |
* <contract-call |
|
25 |
+ |
* contract-address="0x1234567890123456789012345678901234567890" |
|
26 |
+ |
* method-name="transfer" |
|
27 |
+ |
* method-args='["0xrecipient123", "1000000000000000000"]' |
|
28 |
+ |
* abi-url="https://api.example.com/contract-abi.json" |
|
29 |
+ |
* button-text="Send Tokens"> |
|
30 |
+ |
* </contract-call> |
|
31 |
+ |
* ``` |
|
32 |
+ |
* |
|
33 |
+ |
* @example |
|
34 |
+ |
* Custom styling: |
|
35 |
+ |
* ```html |
|
36 |
+ |
* <contract-call |
|
37 |
+ |
* contract-address="0x1234567890123456789012345678901234567890" |
|
38 |
+ |
* method-name="getName" |
|
39 |
+ |
* abi-url="/abi/token.json" |
|
40 |
+ |
* background="#1a1a1a" |
|
41 |
+ |
* foreground="#ffffff" |
|
42 |
+ |
* primary="#00ff88" |
|
43 |
+ |
* secondary="#00cc66" |
|
44 |
+ |
* border-radius="8px" |
|
45 |
+ |
* error-color="#ff4444" |
|
46 |
+ |
* success-color="#44ff44"> |
|
47 |
+ |
* </contract-call> |
|
48 |
+ |
* ``` |
|
49 |
+ |
* |
|
50 |
+ |
* Attributes: |
|
51 |
+ |
* - contract-address (required): The Ethereum contract address |
|
52 |
+ |
* - method-name (required): The contract method to call |
|
53 |
+ |
* - method-args: JSON array of method arguments (default: []) |
|
54 |
+ |
* - abi: JSON string of the contract ABI |
|
55 |
+ |
* - abi-url: URL to fetch the contract ABI from |
|
56 |
+ |
* - chain-id: Ethereum chain ID in hex format (default: "0x1" for mainnet) |
|
57 |
+ |
* - button-text: Text displayed on the call button (default: "Call Contract") |
|
58 |
+ |
* - background: Background color (default: "#232323") |
|
59 |
+ |
* - foreground: Text color (default: "#ffffff") |
|
60 |
+ |
* - primary: Primary button color (default: "#5F8787") |
|
61 |
+ |
* - secondary: Secondary/hover color (default: "#6F9797") |
|
62 |
+ |
* - border-radius: Border radius for UI elements (default: "4px") |
|
63 |
+ |
* - error-color: Color for error messages (default: "#E78A53") |
|
64 |
+ |
* - success-color: Color for success messages (default: "#5F8787") |
|
65 |
+ |
* |
|
66 |
+ |
* Events: |
|
67 |
+ |
* - abi-loaded: Fired when ABI is successfully loaded from URL |
|
68 |
+ |
* - abi-error: Fired when ABI loading fails |
|
69 |
+ |
* - contract-call-success: Fired when contract call succeeds |
|
70 |
+ |
* - contract-call-error: Fired when contract call fails |
|
71 |
+ |
* |
|
72 |
+ |
* Requirements: |
|
73 |
+ |
* - MetaMask or compatible wallet extension |
|
74 |
+ |
* - @noble/hashes library for keccak256 hashing |
|
75 |
+ |
* |
|
76 |
+ |
* Notes: |
|
77 |
+ |
* - Read-only methods (view/pure) use eth_call |
|
78 |
+ |
* - Write methods send transactions via eth_sendTransaction |
|
79 |
+ |
* - Simplified ABI encoding/decoding (use ethers.js/web3.js for production) |
|
80 |
+ |
* - Automatically switches to the specified chain if needed |
|
81 |
+ |
*/ |
|
82 |
+ |
|
| 2 |
83 |
|
// Constructor and lifecycle methods |
| 3 |
84 |
|
constructor() { |
| 4 |
85 |
|
super(); |
|
| 372 |
453 |
|
} |
| 373 |
454 |
|
|
| 374 |
455 |
|
keccak256(input) { |
| 375 |
|
- |
if (typeof window.keccak256 === "function") { |
| 376 |
|
- |
return window.keccak256(input); |
| 377 |
|
- |
} else { |
| 378 |
|
- |
throw new Error("keccak256 function not available"); |
| 379 |
|
- |
} |
|
456 |
+ |
const inputBytes = new TextEncoder().encode(input); |
|
457 |
+ |
const hashBytes = keccak_256(inputBytes); |
|
458 |
+ |
return Array.from(hashBytes).map(b => b.toString(16).padStart(2, '0')).join(''); |
| 380 |
459 |
|
} |
| 381 |
460 |
|
|
| 382 |
461 |
|
// UI helper methods |
|
| 599 |
678 |
|
} |
| 600 |
679 |
|
|
| 601 |
680 |
|
customElements.define("contract-call", ContractCall); |
| 602 |
|
- |
|
| 603 |
|
- |
/** |
| 604 |
|
- |
* ============================================================================ |
| 605 |
|
- |
* KECCAK256 DEPENDENCY - DO NOT EDIT BELOW THIS LINE |
| 606 |
|
- |
* ============================================================================ |
| 607 |
|
- |
* |
| 608 |
|
- |
* The following code is a third-party implementation of the Keccak/SHA-3 |
| 609 |
|
- |
* cryptographic hash functions. This code should not be modified as it |
| 610 |
|
- |
* provides the necessary keccak256 functionality for the ContractCall component. |
| 611 |
|
- |
* |
| 612 |
|
- |
* ============================================================================ |
| 613 |
|
- |
*/ |
| 614 |
|
- |
|
| 615 |
|
- |
/** |
| 616 |
|
- |
* [js-sha3]{@link https://github.com/emn178/js-sha3} |
| 617 |
|
- |
* |
| 618 |
|
- |
* @version 0.9.3 |
| 619 |
|
- |
* @author Chen, Yi-Cyuan [emn178@gmail.com] |
| 620 |
|
- |
* @copyright Chen, Yi-Cyuan 2015-2023 |
| 621 |
|
- |
* @license MIT |
| 622 |
|
- |
*/ |
| 623 |
|
- |
/*jslint bitwise: true */ |
| 624 |
|
- |
(function () { |
| 625 |
|
- |
var INPUT_ERROR = "input is invalid type"; |
| 626 |
|
- |
var FINALIZE_ERROR = "finalize already called"; |
| 627 |
|
- |
var WINDOW = typeof window === "object"; |
| 628 |
|
- |
var root = WINDOW ? window : {}; |
| 629 |
|
- |
if (root.JS_SHA3_NO_WINDOW) { |
| 630 |
|
- |
WINDOW = false; |
| 631 |
|
- |
} |
| 632 |
|
- |
var WEB_WORKER = !WINDOW && typeof self === "object"; |
| 633 |
|
- |
var NODE_JS = |
| 634 |
|
- |
!root.JS_SHA3_NO_NODE_JS && |
| 635 |
|
- |
typeof process === "object" && |
| 636 |
|
- |
process.versions && |
| 637 |
|
- |
process.versions.node; |
| 638 |
|
- |
if (NODE_JS) { |
| 639 |
|
- |
root = global; |
| 640 |
|
- |
} else if (WEB_WORKER) { |
| 641 |
|
- |
root = self; |
| 642 |
|
- |
} |
| 643 |
|
- |
var COMMON_JS = |
| 644 |
|
- |
!root.JS_SHA3_NO_COMMON_JS && typeof module === "object" && module.exports; |
| 645 |
|
- |
var AMD = typeof define === "function" && define.amd; |
| 646 |
|
- |
var ARRAY_BUFFER = |
| 647 |
|
- |
!root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; |
| 648 |
|
- |
var HEX_CHARS = "0123456789abcdef".split(""); |
| 649 |
|
- |
var SHAKE_PADDING = [31, 7936, 2031616, 520093696]; |
| 650 |
|
- |
var CSHAKE_PADDING = [4, 1024, 262144, 67108864]; |
| 651 |
|
- |
var KECCAK_PADDING = [1, 256, 65536, 16777216]; |
| 652 |
|
- |
var PADDING = [6, 1536, 393216, 100663296]; |
| 653 |
|
- |
var SHIFT = [0, 8, 16, 24]; |
| 654 |
|
- |
var RC = [ |
| 655 |
|
- |
1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, |
| 656 |
|
- |
2147483649, 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, |
| 657 |
|
- |
2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, |
| 658 |
|
- |
2147483648, 32771, 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, |
| 659 |
|
- |
2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, |
| 660 |
|
- |
2147483649, 0, 2147516424, 2147483648, |
| 661 |
|
- |
]; |
| 662 |
|
- |
var BITS = [224, 256, 384, 512]; |
| 663 |
|
- |
var SHAKE_BITS = [128, 256]; |
| 664 |
|
- |
var OUTPUT_TYPES = ["hex", "buffer", "arrayBuffer", "array", "digest"]; |
| 665 |
|
- |
var CSHAKE_BYTEPAD = { |
| 666 |
|
- |
128: 168, |
| 667 |
|
- |
256: 136, |
| 668 |
|
- |
}; |
| 669 |
|
- |
|
| 670 |
|
- |
var isArray = |
| 671 |
|
- |
root.JS_SHA3_NO_NODE_JS || !Array.isArray |
| 672 |
|
- |
? function (obj) { |
| 673 |
|
- |
return Object.prototype.toString.call(obj) === "[object Array]"; |
| 674 |
|
- |
} |
| 675 |
|
- |
: Array.isArray; |
| 676 |
|
- |
|
| 677 |
|
- |
var isView = |
| 678 |
|
- |
ARRAY_BUFFER && |
| 679 |
|
- |
(root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) |
| 680 |
|
- |
? function (obj) { |
| 681 |
|
- |
return ( |
| 682 |
|
- |
typeof obj === "object" && |
| 683 |
|
- |
obj.buffer && |
| 684 |
|
- |
obj.buffer.constructor === ArrayBuffer |
| 685 |
|
- |
); |
| 686 |
|
- |
} |
| 687 |
|
- |
: ArrayBuffer.isView; |
| 688 |
|
- |
|
| 689 |
|
- |
// [message: string, isString: bool] |
| 690 |
|
- |
var formatMessage = function (message) { |
| 691 |
|
- |
var type = typeof message; |
| 692 |
|
- |
if (type === "string") { |
| 693 |
|
- |
return [message, true]; |
| 694 |
|
- |
} |
| 695 |
|
- |
if (type !== "object" || message === null) { |
| 696 |
|
- |
throw new Error(INPUT_ERROR); |
| 697 |
|
- |
} |
| 698 |
|
- |
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { |
| 699 |
|
- |
return [new Uint8Array(message), false]; |
| 700 |
|
- |
} |
| 701 |
|
- |
if (!isArray(message) && !isView(message)) { |
| 702 |
|
- |
throw new Error(INPUT_ERROR); |
| 703 |
|
- |
} |
| 704 |
|
- |
return [message, false]; |
| 705 |
|
- |
}; |
| 706 |
|
- |
|
| 707 |
|
- |
var empty = function (message) { |
| 708 |
|
- |
return formatMessage(message)[0].length === 0; |
| 709 |
|
- |
}; |
| 710 |
|
- |
|
| 711 |
|
- |
var cloneArray = function (array) { |
| 712 |
|
- |
var newArray = []; |
| 713 |
|
- |
for (let i = 0; i < array.length; ++i) { |
| 714 |
|
- |
newArray[i] = array[i]; |
| 715 |
|
- |
} |
| 716 |
|
- |
return newArray; |
| 717 |
|
- |
}; |
| 718 |
|
- |
|
| 719 |
|
- |
var createOutputMethod = function (bits, padding, outputType) { |
| 720 |
|
- |
return function (message) { |
| 721 |
|
- |
return new Keccak(bits, padding, bits).update(message)[outputType](); |
| 722 |
|
- |
}; |
| 723 |
|
- |
}; |
| 724 |
|
- |
|
| 725 |
|
- |
var createShakeOutputMethod = function (bits, padding, outputType) { |
| 726 |
|
- |
return function (message, outputBits) { |
| 727 |
|
- |
return new Keccak(bits, padding, outputBits) |
| 728 |
|
- |
.update(message) |
| 729 |
|
- |
[outputType](); |
| 730 |
|
- |
}; |
| 731 |
|
- |
}; |
| 732 |
|
- |
|
| 733 |
|
- |
var createCshakeOutputMethod = function (bits, padding, outputType) { |
| 734 |
|
- |
return function (message, outputBits, n, s) { |
| 735 |
|
- |
return methods["cshake" + bits] |
| 736 |
|
- |
.update(message, outputBits, n, s) |
| 737 |
|
- |
[outputType](); |
| 738 |
|
- |
}; |
| 739 |
|
- |
}; |
| 740 |
|
- |
|
| 741 |
|
- |
var createKmacOutputMethod = function (bits, padding, outputType) { |
| 742 |
|
- |
return function (key, message, outputBits, s) { |
| 743 |
|
- |
return methods["kmac" + bits] |
| 744 |
|
- |
.update(key, message, outputBits, s) |
| 745 |
|
- |
[outputType](); |
| 746 |
|
- |
}; |
| 747 |
|
- |
}; |
| 748 |
|
- |
|
| 749 |
|
- |
var createOutputMethods = function (method, createMethod, bits, padding) { |
| 750 |
|
- |
for (let i = 0; i < OUTPUT_TYPES.length; ++i) { |
| 751 |
|
- |
const type = OUTPUT_TYPES[i]; |
| 752 |
|
- |
method[type] = createMethod(bits, padding, type); |
| 753 |
|
- |
} |
| 754 |
|
- |
return method; |
| 755 |
|
- |
}; |
| 756 |
|
- |
|
| 757 |
|
- |
var createMethod = function (bits, padding) { |
| 758 |
|
- |
var method = createOutputMethod(bits, padding, "hex"); |
| 759 |
|
- |
method.create = function () { |
| 760 |
|
- |
return new Keccak(bits, padding, bits); |
| 761 |
|
- |
}; |
| 762 |
|
- |
method.update = function (message) { |
| 763 |
|
- |
return method.create().update(message); |
| 764 |
|
- |
}; |
| 765 |
|
- |
return createOutputMethods(method, createOutputMethod, bits, padding); |
| 766 |
|
- |
}; |
| 767 |
|
- |
|
| 768 |
|
- |
var createShakeMethod = function (bits, padding) { |
| 769 |
|
- |
var method = createShakeOutputMethod(bits, padding, "hex"); |
| 770 |
|
- |
method.create = function (outputBits) { |
| 771 |
|
- |
return new Keccak(bits, padding, outputBits); |
| 772 |
|
- |
}; |
| 773 |
|
- |
method.update = function (message, outputBits) { |
| 774 |
|
- |
return method.create(outputBits).update(message); |
| 775 |
|
- |
}; |
| 776 |
|
- |
return createOutputMethods(method, createShakeOutputMethod, bits, padding); |
| 777 |
|
- |
}; |
| 778 |
|
- |
|
| 779 |
|
- |
var createCshakeMethod = function (bits, padding) { |
| 780 |
|
- |
var w = CSHAKE_BYTEPAD[bits]; |
| 781 |
|
- |
var method = createCshakeOutputMethod(bits, padding, "hex"); |
| 782 |
|
- |
method.create = function (outputBits, n, s) { |
| 783 |
|
- |
if (empty(n) && empty(s)) { |
| 784 |
|
- |
return methods["shake" + bits].create(outputBits); |
| 785 |
|
- |
} else { |
| 786 |
|
- |
return new Keccak(bits, padding, outputBits).bytepad([n, s], w); |
| 787 |
|
- |
} |
| 788 |
|
- |
}; |
| 789 |
|
- |
method.update = function (message, outputBits, n, s) { |
| 790 |
|
- |
return method.create(outputBits, n, s).update(message); |
| 791 |
|
- |
}; |
| 792 |
|
- |
return createOutputMethods(method, createCshakeOutputMethod, bits, padding); |
| 793 |
|
- |
}; |
| 794 |
|
- |
|
| 795 |
|
- |
var createKmacMethod = function (bits, padding) { |
| 796 |
|
- |
var w = CSHAKE_BYTEPAD[bits]; |
| 797 |
|
- |
var method = createKmacOutputMethod(bits, padding, "hex"); |
| 798 |
|
- |
method.create = function (key, outputBits, s) { |
| 799 |
|
- |
return new Kmac(bits, padding, outputBits) |
| 800 |
|
- |
.bytepad(["KMAC", s], w) |
| 801 |
|
- |
.bytepad([key], w); |
| 802 |
|
- |
}; |
| 803 |
|
- |
method.update = function (key, message, outputBits, s) { |
| 804 |
|
- |
return method.create(key, outputBits, s).update(message); |
| 805 |
|
- |
}; |
| 806 |
|
- |
return createOutputMethods(method, createKmacOutputMethod, bits, padding); |
| 807 |
|
- |
}; |
| 808 |
|
- |
|
| 809 |
|
- |
var algorithms = [ |
| 810 |
|
- |
{ |
| 811 |
|
- |
name: "keccak", |
| 812 |
|
- |
padding: KECCAK_PADDING, |
| 813 |
|
- |
bits: BITS, |
| 814 |
|
- |
createMethod: createMethod, |
| 815 |
|
- |
}, |
| 816 |
|
- |
{ name: "sha3", padding: PADDING, bits: BITS, createMethod: createMethod }, |
| 817 |
|
- |
{ |
| 818 |
|
- |
name: "shake", |
| 819 |
|
- |
padding: SHAKE_PADDING, |
| 820 |
|
- |
bits: SHAKE_BITS, |
| 821 |
|
- |
createMethod: createShakeMethod, |
| 822 |
|
- |
}, |
| 823 |
|
- |
{ |
| 824 |
|
- |
name: "cshake", |
| 825 |
|
- |
padding: CSHAKE_PADDING, |
| 826 |
|
- |
bits: SHAKE_BITS, |
| 827 |
|
- |
createMethod: createCshakeMethod, |
| 828 |
|
- |
}, |
| 829 |
|
- |
{ |
| 830 |
|
- |
name: "kmac", |
| 831 |
|
- |
padding: CSHAKE_PADDING, |
| 832 |
|
- |
bits: SHAKE_BITS, |
| 833 |
|
- |
createMethod: createKmacMethod, |
| 834 |
|
- |
}, |
| 835 |
|
- |
]; |
| 836 |
|
- |
|
| 837 |
|
- |
var methods = {}, |
| 838 |
|
- |
methodNames = []; |
| 839 |
|
- |
|
| 840 |
|
- |
for (let i = 0; i < algorithms.length; ++i) { |
| 841 |
|
- |
const algorithm = algorithms[i]; |
| 842 |
|
- |
const bits = algorithm.bits; |
| 843 |
|
- |
for (let j = 0; j < bits.length; ++j) { |
| 844 |
|
- |
const methodName = algorithm.name + "_" + bits[j]; |
| 845 |
|
- |
methodNames.push(methodName); |
| 846 |
|
- |
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding); |
| 847 |
|
- |
if (algorithm.name !== "sha3") { |
| 848 |
|
- |
const newMethodName = algorithm.name + bits[j]; |
| 849 |
|
- |
methodNames.push(newMethodName); |
| 850 |
|
- |
methods[newMethodName] = methods[methodName]; |
| 851 |
|
- |
} |
| 852 |
|
- |
} |
| 853 |
|
- |
} |
| 854 |
|
- |
|
| 855 |
|
- |
function Keccak(bits, padding, outputBits) { |
| 856 |
|
- |
this.blocks = []; |
| 857 |
|
- |
this.s = []; |
| 858 |
|
- |
this.padding = padding; |
| 859 |
|
- |
this.outputBits = outputBits; |
| 860 |
|
- |
this.reset = true; |
| 861 |
|
- |
this.finalized = false; |
| 862 |
|
- |
this.block = 0; |
| 863 |
|
- |
this.start = 0; |
| 864 |
|
- |
this.blockCount = (1600 - (bits << 1)) >> 5; |
| 865 |
|
- |
this.byteCount = this.blockCount << 2; |
| 866 |
|
- |
this.outputBlocks = outputBits >> 5; |
| 867 |
|
- |
this.extraBytes = (outputBits & 31) >> 3; |
| 868 |
|
- |
|
| 869 |
|
- |
for (let i = 0; i < 50; ++i) { |
| 870 |
|
- |
this.s[i] = 0; |
| 871 |
|
- |
} |
| 872 |
|
- |
} |
| 873 |
|
- |
|
| 874 |
|
- |
Keccak.prototype.update = function (message) { |
| 875 |
|
- |
if (this.finalized) { |
| 876 |
|
- |
throw new Error(FINALIZE_ERROR); |
| 877 |
|
- |
} |
| 878 |
|
- |
var result = formatMessage(message); |
| 879 |
|
- |
message = result[0]; |
| 880 |
|
- |
var isString = result[1]; |
| 881 |
|
- |
var blocks = this.blocks, |
| 882 |
|
- |
byteCount = this.byteCount, |
| 883 |
|
- |
length = message.length, |
| 884 |
|
- |
blockCount = this.blockCount, |
| 885 |
|
- |
index = 0, |
| 886 |
|
- |
s = this.s, |
| 887 |
|
- |
i, |
| 888 |
|
- |
code; |
| 889 |
|
- |
|
| 890 |
|
- |
while (index < length) { |
| 891 |
|
- |
if (this.reset) { |
| 892 |
|
- |
this.reset = false; |
| 893 |
|
- |
blocks[0] = this.block; |
| 894 |
|
- |
for (i = 1; i < blockCount + 1; ++i) { |
| 895 |
|
- |
blocks[i] = 0; |
| 896 |
|
- |
} |
| 897 |
|
- |
} |
| 898 |
|
- |
if (isString) { |
| 899 |
|
- |
for (i = this.start; index < length && i < byteCount; ++index) { |
| 900 |
|
- |
code = message.charCodeAt(index); |
| 901 |
|
- |
if (code < 0x80) { |
| 902 |
|
- |
blocks[i >> 2] |= code << SHIFT[i++ & 3]; |
| 903 |
|
- |
} else if (code < 0x800) { |
| 904 |
|
- |
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; |
| 905 |
|
- |
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
| 906 |
|
- |
} else if (code < 0xd800 || code >= 0xe000) { |
| 907 |
|
- |
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; |
| 908 |
|
- |
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; |
| 909 |
|
- |
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
| 910 |
|
- |
} else { |
| 911 |
|
- |
code = |
| 912 |
|
- |
0x10000 + |
| 913 |
|
- |
(((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); |
| 914 |
|
- |
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; |
| 915 |
|
- |
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; |
| 916 |
|
- |
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; |
| 917 |
|
- |
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
| 918 |
|
- |
} |
| 919 |
|
- |
} |
| 920 |
|
- |
} else { |
| 921 |
|
- |
for (i = this.start; index < length && i < byteCount; ++index) { |
| 922 |
|
- |
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; |
| 923 |
|
- |
} |
| 924 |
|
- |
} |
| 925 |
|
- |
this.lastByteIndex = i; |
| 926 |
|
- |
if (i >= byteCount) { |
| 927 |
|
- |
this.start = i - byteCount; |
| 928 |
|
- |
this.block = blocks[blockCount]; |
| 929 |
|
- |
for (i = 0; i < blockCount; ++i) { |
| 930 |
|
- |
s[i] ^= blocks[i]; |
| 931 |
|
- |
} |
| 932 |
|
- |
f(s); |
| 933 |
|
- |
this.reset = true; |
| 934 |
|
- |
} else { |
| 935 |
|
- |
this.start = i; |
| 936 |
|
- |
} |
| 937 |
|
- |
} |
| 938 |
|
- |
return this; |
| 939 |
|
- |
}; |
| 940 |
|
- |
|
| 941 |
|
- |
Keccak.prototype.encode = function (x, right) { |
| 942 |
|
- |
var o = x & 255, |
| 943 |
|
- |
n = 1; |
| 944 |
|
- |
var bytes = [o]; |
| 945 |
|
- |
x = x >> 8; |
| 946 |
|
- |
o = x & 255; |
| 947 |
|
- |
while (o > 0) { |
| 948 |
|
- |
bytes.unshift(o); |
| 949 |
|
- |
x = x >> 8; |
| 950 |
|
- |
o = x & 255; |
| 951 |
|
- |
++n; |
| 952 |
|
- |
} |
| 953 |
|
- |
if (right) { |
| 954 |
|
- |
bytes.push(n); |
| 955 |
|
- |
} else { |
| 956 |
|
- |
bytes.unshift(n); |
| 957 |
|
- |
} |
| 958 |
|
- |
this.update(bytes); |
| 959 |
|
- |
return bytes.length; |
| 960 |
|
- |
}; |
| 961 |
|
- |
|
| 962 |
|
- |
Keccak.prototype.encodeString = function (str) { |
| 963 |
|
- |
var result = formatMessage(str); |
| 964 |
|
- |
str = result[0]; |
| 965 |
|
- |
var isString = result[1]; |
| 966 |
|
- |
var bytes = 0, |
| 967 |
|
- |
length = str.length; |
| 968 |
|
- |
if (isString) { |
| 969 |
|
- |
for (let i = 0; i < str.length; ++i) { |
| 970 |
|
- |
let code = str.charCodeAt(i); |
| 971 |
|
- |
if (code < 0x80) { |
| 972 |
|
- |
bytes += 1; |
| 973 |
|
- |
} else if (code < 0x800) { |
| 974 |
|
- |
bytes += 2; |
| 975 |
|
- |
} else if (code < 0xd800 || code >= 0xe000) { |
| 976 |
|
- |
bytes += 3; |
| 977 |
|
- |
} else { |
| 978 |
|
- |
code = |
| 979 |
|
- |
0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff)); |
| 980 |
|
- |
bytes += 4; |
| 981 |
|
- |
} |
| 982 |
|
- |
} |
| 983 |
|
- |
} else { |
| 984 |
|
- |
bytes = length; |
| 985 |
|
- |
} |
| 986 |
|
- |
bytes += this.encode(bytes * 8); |
| 987 |
|
- |
this.update(str); |
| 988 |
|
- |
return bytes; |
| 989 |
|
- |
}; |
| 990 |
|
- |
|
| 991 |
|
- |
Keccak.prototype.bytepad = function (strs, w) { |
| 992 |
|
- |
var bytes = this.encode(w); |
| 993 |
|
- |
for (let i = 0; i < strs.length; ++i) { |
| 994 |
|
- |
bytes += this.encodeString(strs[i]); |
| 995 |
|
- |
} |
| 996 |
|
- |
var paddingBytes = (w - (bytes % w)) % w; |
| 997 |
|
- |
var zeros = []; |
| 998 |
|
- |
zeros.length = paddingBytes; |
| 999 |
|
- |
this.update(zeros); |
| 1000 |
|
- |
return this; |
| 1001 |
|
- |
}; |
| 1002 |
|
- |
|
| 1003 |
|
- |
Keccak.prototype.finalize = function () { |
| 1004 |
|
- |
if (this.finalized) { |
| 1005 |
|
- |
return; |
| 1006 |
|
- |
} |
| 1007 |
|
- |
this.finalized = true; |
| 1008 |
|
- |
var blocks = this.blocks, |
| 1009 |
|
- |
i = this.lastByteIndex, |
| 1010 |
|
- |
blockCount = this.blockCount, |
| 1011 |
|
- |
s = this.s; |
| 1012 |
|
- |
blocks[i >> 2] |= this.padding[i & 3]; |
| 1013 |
|
- |
if (this.lastByteIndex === this.byteCount) { |
| 1014 |
|
- |
blocks[0] = blocks[blockCount]; |
| 1015 |
|
- |
for (i = 1; i < blockCount + 1; ++i) { |
| 1016 |
|
- |
blocks[i] = 0; |
| 1017 |
|
- |
} |
| 1018 |
|
- |
} |
| 1019 |
|
- |
blocks[blockCount - 1] |= 0x80000000; |
| 1020 |
|
- |
for (i = 0; i < blockCount; ++i) { |
| 1021 |
|
- |
s[i] ^= blocks[i]; |
| 1022 |
|
- |
} |
| 1023 |
|
- |
f(s); |
| 1024 |
|
- |
}; |
| 1025 |
|
- |
|
| 1026 |
|
- |
Keccak.prototype.toString = Keccak.prototype.hex = function () { |
| 1027 |
|
- |
this.finalize(); |
| 1028 |
|
- |
|
| 1029 |
|
- |
var blockCount = this.blockCount, |
| 1030 |
|
- |
s = this.s, |
| 1031 |
|
- |
outputBlocks = this.outputBlocks, |
| 1032 |
|
- |
extraBytes = this.extraBytes, |
| 1033 |
|
- |
i = 0, |
| 1034 |
|
- |
j = 0; |
| 1035 |
|
- |
var hex = "", |
| 1036 |
|
- |
block; |
| 1037 |
|
- |
while (j < outputBlocks) { |
| 1038 |
|
- |
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { |
| 1039 |
|
- |
block = s[i]; |
| 1040 |
|
- |
hex += |
| 1041 |
|
- |
HEX_CHARS[(block >> 4) & 0x0f] + |
| 1042 |
|
- |
HEX_CHARS[block & 0x0f] + |
| 1043 |
|
- |
HEX_CHARS[(block >> 12) & 0x0f] + |
| 1044 |
|
- |
HEX_CHARS[(block >> 8) & 0x0f] + |
| 1045 |
|
- |
HEX_CHARS[(block >> 20) & 0x0f] + |
| 1046 |
|
- |
HEX_CHARS[(block >> 16) & 0x0f] + |
| 1047 |
|
- |
HEX_CHARS[(block >> 28) & 0x0f] + |
| 1048 |
|
- |
HEX_CHARS[(block >> 24) & 0x0f]; |
| 1049 |
|
- |
} |
| 1050 |
|
- |
if (j % blockCount === 0) { |
| 1051 |
|
- |
s = cloneArray(s); |
| 1052 |
|
- |
f(s); |
| 1053 |
|
- |
i = 0; |
| 1054 |
|
- |
} |
| 1055 |
|
- |
} |
| 1056 |
|
- |
if (extraBytes) { |
| 1057 |
|
- |
block = s[i]; |
| 1058 |
|
- |
hex += HEX_CHARS[(block >> 4) & 0x0f] + HEX_CHARS[block & 0x0f]; |
| 1059 |
|
- |
if (extraBytes > 1) { |
| 1060 |
|
- |
hex += HEX_CHARS[(block >> 12) & 0x0f] + HEX_CHARS[(block >> 8) & 0x0f]; |
| 1061 |
|
- |
} |
| 1062 |
|
- |
if (extraBytes > 2) { |
| 1063 |
|
- |
hex += |
| 1064 |
|
- |
HEX_CHARS[(block >> 20) & 0x0f] + HEX_CHARS[(block >> 16) & 0x0f]; |
| 1065 |
|
- |
} |
| 1066 |
|
- |
} |
| 1067 |
|
- |
return hex; |
| 1068 |
|
- |
}; |
| 1069 |
|
- |
|
| 1070 |
|
- |
Keccak.prototype.arrayBuffer = function () { |
| 1071 |
|
- |
this.finalize(); |
| 1072 |
|
- |
|
| 1073 |
|
- |
var blockCount = this.blockCount, |
| 1074 |
|
- |
s = this.s, |
| 1075 |
|
- |
outputBlocks = this.outputBlocks, |
| 1076 |
|
- |
extraBytes = this.extraBytes, |
| 1077 |
|
- |
i = 0, |
| 1078 |
|
- |
j = 0; |
| 1079 |
|
- |
var bytes = this.outputBits >> 3; |
| 1080 |
|
- |
var buffer; |
| 1081 |
|
- |
if (extraBytes) { |
| 1082 |
|
- |
buffer = new ArrayBuffer((outputBlocks + 1) << 2); |
| 1083 |
|
- |
} else { |
| 1084 |
|
- |
buffer = new ArrayBuffer(bytes); |
| 1085 |
|
- |
} |
| 1086 |
|
- |
var array = new Uint32Array(buffer); |
| 1087 |
|
- |
while (j < outputBlocks) { |
| 1088 |
|
- |
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { |
| 1089 |
|
- |
array[j] = s[i]; |
| 1090 |
|
- |
} |
| 1091 |
|
- |
if (j % blockCount === 0) { |
| 1092 |
|
- |
s = cloneArray(s); |
| 1093 |
|
- |
f(s); |
| 1094 |
|
- |
} |
| 1095 |
|
- |
} |
| 1096 |
|
- |
if (extraBytes) { |
| 1097 |
|
- |
array[j] = s[i]; |
| 1098 |
|
- |
buffer = buffer.slice(0, bytes); |
| 1099 |
|
- |
} |
| 1100 |
|
- |
return buffer; |
| 1101 |
|
- |
}; |
| 1102 |
|
- |
|
| 1103 |
|
- |
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer; |
| 1104 |
|
- |
|
| 1105 |
|
- |
Keccak.prototype.digest = Keccak.prototype.array = function () { |
| 1106 |
|
- |
this.finalize(); |
| 1107 |
|
- |
|
| 1108 |
|
- |
var blockCount = this.blockCount, |
| 1109 |
|
- |
s = this.s, |
| 1110 |
|
- |
outputBlocks = this.outputBlocks, |
| 1111 |
|
- |
extraBytes = this.extraBytes, |
| 1112 |
|
- |
i = 0, |
| 1113 |
|
- |
j = 0; |
| 1114 |
|
- |
var array = [], |
| 1115 |
|
- |
offset, |
| 1116 |
|
- |
block; |
| 1117 |
|
- |
while (j < outputBlocks) { |
| 1118 |
|
- |
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { |
| 1119 |
|
- |
offset = j << 2; |
| 1120 |
|
- |
block = s[i]; |
| 1121 |
|
- |
array[offset] = block & 0xff; |
| 1122 |
|
- |
array[offset + 1] = (block >> 8) & 0xff; |
| 1123 |
|
- |
array[offset + 2] = (block >> 16) & 0xff; |
| 1124 |
|
- |
array[offset + 3] = (block >> 24) & 0xff; |
| 1125 |
|
- |
} |
| 1126 |
|
- |
if (j % blockCount === 0) { |
| 1127 |
|
- |
s = cloneArray(s); |
| 1128 |
|
- |
f(s); |
| 1129 |
|
- |
} |
| 1130 |
|
- |
} |
| 1131 |
|
- |
if (extraBytes) { |
| 1132 |
|
- |
offset = j << 2; |
| 1133 |
|
- |
block = s[i]; |
| 1134 |
|
- |
array[offset] = block & 0xff; |
| 1135 |
|
- |
if (extraBytes > 1) { |
| 1136 |
|
- |
array[offset + 1] = (block >> 8) & 0xff; |
| 1137 |
|
- |
} |
| 1138 |
|
- |
if (extraBytes > 2) { |
| 1139 |
|
- |
array[offset + 2] = (block >> 16) & 0xff; |
| 1140 |
|
- |
} |
| 1141 |
|
- |
} |
| 1142 |
|
- |
return array; |
| 1143 |
|
- |
}; |
| 1144 |
|
- |
|
| 1145 |
|
- |
function Kmac(bits, padding, outputBits) { |
| 1146 |
|
- |
Keccak.call(this, bits, padding, outputBits); |
| 1147 |
|
- |
} |
| 1148 |
|
- |
|
| 1149 |
|
- |
Kmac.prototype = new Keccak(); |
| 1150 |
|
- |
|
| 1151 |
|
- |
Kmac.prototype.finalize = function () { |
| 1152 |
|
- |
this.encode(this.outputBits, true); |
| 1153 |
|
- |
return Keccak.prototype.finalize.call(this); |
| 1154 |
|
- |
}; |
| 1155 |
|
- |
|
| 1156 |
|
- |
var f = function (s) { |
| 1157 |
|
- |
var h, |
| 1158 |
|
- |
l, |
| 1159 |
|
- |
n, |
| 1160 |
|
- |
c0, |
| 1161 |
|
- |
c1, |
| 1162 |
|
- |
c2, |
| 1163 |
|
- |
c3, |
| 1164 |
|
- |
c4, |
| 1165 |
|
- |
c5, |
| 1166 |
|
- |
c6, |
| 1167 |
|
- |
c7, |
| 1168 |
|
- |
c8, |
| 1169 |
|
- |
c9, |
| 1170 |
|
- |
b0, |
| 1171 |
|
- |
b1, |
| 1172 |
|
- |
b2, |
| 1173 |
|
- |
b3, |
| 1174 |
|
- |
b4, |
| 1175 |
|
- |
b5, |
| 1176 |
|
- |
b6, |
| 1177 |
|
- |
b7, |
| 1178 |
|
- |
b8, |
| 1179 |
|
- |
b9, |
| 1180 |
|
- |
b10, |
| 1181 |
|
- |
b11, |
| 1182 |
|
- |
b12, |
| 1183 |
|
- |
b13, |
| 1184 |
|
- |
b14, |
| 1185 |
|
- |
b15, |
| 1186 |
|
- |
b16, |
| 1187 |
|
- |
b17, |
| 1188 |
|
- |
b18, |
| 1189 |
|
- |
b19, |
| 1190 |
|
- |
b20, |
| 1191 |
|
- |
b21, |
| 1192 |
|
- |
b22, |
| 1193 |
|
- |
b23, |
| 1194 |
|
- |
b24, |
| 1195 |
|
- |
b25, |
| 1196 |
|
- |
b26, |
| 1197 |
|
- |
b27, |
| 1198 |
|
- |
b28, |
| 1199 |
|
- |
b29, |
| 1200 |
|
- |
b30, |
| 1201 |
|
- |
b31, |
| 1202 |
|
- |
b32, |
| 1203 |
|
- |
b33, |
| 1204 |
|
- |
b34, |
| 1205 |
|
- |
b35, |
| 1206 |
|
- |
b36, |
| 1207 |
|
- |
b37, |
| 1208 |
|
- |
b38, |
| 1209 |
|
- |
b39, |
| 1210 |
|
- |
b40, |
| 1211 |
|
- |
b41, |
| 1212 |
|
- |
b42, |
| 1213 |
|
- |
b43, |
| 1214 |
|
- |
b44, |
| 1215 |
|
- |
b45, |
| 1216 |
|
- |
b46, |
| 1217 |
|
- |
b47, |
| 1218 |
|
- |
b48, |
| 1219 |
|
- |
b49; |
| 1220 |
|
- |
for (n = 0; n < 48; n += 2) { |
| 1221 |
|
- |
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]; |
| 1222 |
|
- |
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]; |
| 1223 |
|
- |
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]; |
| 1224 |
|
- |
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43]; |
| 1225 |
|
- |
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44]; |
| 1226 |
|
- |
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45]; |
| 1227 |
|
- |
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46]; |
| 1228 |
|
- |
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47]; |
| 1229 |
|
- |
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48]; |
| 1230 |
|
- |
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49]; |
| 1231 |
|
- |
|
| 1232 |
|
- |
h = c8 ^ ((c2 << 1) | (c3 >>> 31)); |
| 1233 |
|
- |
l = c9 ^ ((c3 << 1) | (c2 >>> 31)); |
| 1234 |
|
- |
s[0] ^= h; |
| 1235 |
|
- |
s[1] ^= l; |
| 1236 |
|
- |
s[10] ^= h; |
| 1237 |
|
- |
s[11] ^= l; |
| 1238 |
|
- |
s[20] ^= h; |
| 1239 |
|
- |
s[21] ^= l; |
| 1240 |
|
- |
s[30] ^= h; |
| 1241 |
|
- |
s[31] ^= l; |
| 1242 |
|
- |
s[40] ^= h; |
| 1243 |
|
- |
s[41] ^= l; |
| 1244 |
|
- |
h = c0 ^ ((c4 << 1) | (c5 >>> 31)); |
| 1245 |
|
- |
l = c1 ^ ((c5 << 1) | (c4 >>> 31)); |
| 1246 |
|
- |
s[2] ^= h; |
| 1247 |
|
- |
s[3] ^= l; |
| 1248 |
|
- |
s[12] ^= h; |
| 1249 |
|
- |
s[13] ^= l; |
| 1250 |
|
- |
s[22] ^= h; |
| 1251 |
|
- |
s[23] ^= l; |
| 1252 |
|
- |
s[32] ^= h; |
| 1253 |
|
- |
s[33] ^= l; |
| 1254 |
|
- |
s[42] ^= h; |
| 1255 |
|
- |
s[43] ^= l; |
| 1256 |
|
- |
h = c2 ^ ((c6 << 1) | (c7 >>> 31)); |
| 1257 |
|
- |
l = c3 ^ ((c7 << 1) | (c6 >>> 31)); |
| 1258 |
|
- |
s[4] ^= h; |
| 1259 |
|
- |
s[5] ^= l; |
| 1260 |
|
- |
s[14] ^= h; |
| 1261 |
|
- |
s[15] ^= l; |
| 1262 |
|
- |
s[24] ^= h; |
| 1263 |
|
- |
s[25] ^= l; |
| 1264 |
|
- |
s[34] ^= h; |
| 1265 |
|
- |
s[35] ^= l; |
| 1266 |
|
- |
s[44] ^= h; |
| 1267 |
|
- |
s[45] ^= l; |
| 1268 |
|
- |
h = c4 ^ ((c8 << 1) | (c9 >>> 31)); |
| 1269 |
|
- |
l = c5 ^ ((c9 << 1) | (c8 >>> 31)); |
| 1270 |
|
- |
s[6] ^= h; |
| 1271 |
|
- |
s[7] ^= l; |
| 1272 |
|
- |
s[16] ^= h; |
| 1273 |
|
- |
s[17] ^= l; |
| 1274 |
|
- |
s[26] ^= h; |
| 1275 |
|
- |
s[27] ^= l; |
| 1276 |
|
- |
s[36] ^= h; |
| 1277 |
|
- |
s[37] ^= l; |
| 1278 |
|
- |
s[46] ^= h; |
| 1279 |
|
- |
s[47] ^= l; |
| 1280 |
|
- |
h = c6 ^ ((c0 << 1) | (c1 >>> 31)); |
| 1281 |
|
- |
l = c7 ^ ((c1 << 1) | (c0 >>> 31)); |
| 1282 |
|
- |
s[8] ^= h; |
| 1283 |
|
- |
s[9] ^= l; |
| 1284 |
|
- |
s[18] ^= h; |
| 1285 |
|
- |
s[19] ^= l; |
| 1286 |
|
- |
s[28] ^= h; |
| 1287 |
|
- |
s[29] ^= l; |
| 1288 |
|
- |
s[38] ^= h; |
| 1289 |
|
- |
s[39] ^= l; |
| 1290 |
|
- |
s[48] ^= h; |
| 1291 |
|
- |
s[49] ^= l; |
| 1292 |
|
- |
|
| 1293 |
|
- |
b0 = s[0]; |
| 1294 |
|
- |
b1 = s[1]; |
| 1295 |
|
- |
b32 = (s[11] << 4) | (s[10] >>> 28); |
| 1296 |
|
- |
b33 = (s[10] << 4) | (s[11] >>> 28); |
| 1297 |
|
- |
b14 = (s[20] << 3) | (s[21] >>> 29); |
| 1298 |
|
- |
b15 = (s[21] << 3) | (s[20] >>> 29); |
| 1299 |
|
- |
b46 = (s[31] << 9) | (s[30] >>> 23); |
| 1300 |
|
- |
b47 = (s[30] << 9) | (s[31] >>> 23); |
| 1301 |
|
- |
b28 = (s[40] << 18) | (s[41] >>> 14); |
| 1302 |
|
- |
b29 = (s[41] << 18) | (s[40] >>> 14); |
| 1303 |
|
- |
b20 = (s[2] << 1) | (s[3] >>> 31); |
| 1304 |
|
- |
b21 = (s[3] << 1) | (s[2] >>> 31); |
| 1305 |
|
- |
b2 = (s[13] << 12) | (s[12] >>> 20); |
| 1306 |
|
- |
b3 = (s[12] << 12) | (s[13] >>> 20); |
| 1307 |
|
- |
b34 = (s[22] << 10) | (s[23] >>> 22); |
| 1308 |
|
- |
b35 = (s[23] << 10) | (s[22] >>> 22); |
| 1309 |
|
- |
b16 = (s[33] << 13) | (s[32] >>> 19); |
| 1310 |
|
- |
b17 = (s[32] << 13) | (s[33] >>> 19); |
| 1311 |
|
- |
b48 = (s[42] << 2) | (s[43] >>> 30); |
| 1312 |
|
- |
b49 = (s[43] << 2) | (s[42] >>> 30); |
| 1313 |
|
- |
b40 = (s[5] << 30) | (s[4] >>> 2); |
| 1314 |
|
- |
b41 = (s[4] << 30) | (s[5] >>> 2); |
| 1315 |
|
- |
b22 = (s[14] << 6) | (s[15] >>> 26); |
| 1316 |
|
- |
b23 = (s[15] << 6) | (s[14] >>> 26); |
| 1317 |
|
- |
b4 = (s[25] << 11) | (s[24] >>> 21); |
| 1318 |
|
- |
b5 = (s[24] << 11) | (s[25] >>> 21); |
| 1319 |
|
- |
b36 = (s[34] << 15) | (s[35] >>> 17); |
| 1320 |
|
- |
b37 = (s[35] << 15) | (s[34] >>> 17); |
| 1321 |
|
- |
b18 = (s[45] << 29) | (s[44] >>> 3); |
| 1322 |
|
- |
b19 = (s[44] << 29) | (s[45] >>> 3); |
| 1323 |
|
- |
b10 = (s[6] << 28) | (s[7] >>> 4); |
| 1324 |
|
- |
b11 = (s[7] << 28) | (s[6] >>> 4); |
| 1325 |
|
- |
b42 = (s[17] << 23) | (s[16] >>> 9); |
| 1326 |
|
- |
b43 = (s[16] << 23) | (s[17] >>> 9); |
| 1327 |
|
- |
b24 = (s[26] << 25) | (s[27] >>> 7); |
| 1328 |
|
- |
b25 = (s[27] << 25) | (s[26] >>> 7); |
| 1329 |
|
- |
b6 = (s[36] << 21) | (s[37] >>> 11); |
| 1330 |
|
- |
b7 = (s[37] << 21) | (s[36] >>> 11); |
| 1331 |
|
- |
b38 = (s[47] << 24) | (s[46] >>> 8); |
| 1332 |
|
- |
b39 = (s[46] << 24) | (s[47] >>> 8); |
| 1333 |
|
- |
b30 = (s[8] << 27) | (s[9] >>> 5); |
| 1334 |
|
- |
b31 = (s[9] << 27) | (s[8] >>> 5); |
| 1335 |
|
- |
b12 = (s[18] << 20) | (s[19] >>> 12); |
| 1336 |
|
- |
b13 = (s[19] << 20) | (s[18] >>> 12); |
| 1337 |
|
- |
b44 = (s[29] << 7) | (s[28] >>> 25); |
| 1338 |
|
- |
b45 = (s[28] << 7) | (s[29] >>> 25); |
| 1339 |
|
- |
b26 = (s[38] << 8) | (s[39] >>> 24); |
| 1340 |
|
- |
b27 = (s[39] << 8) | (s[38] >>> 24); |
| 1341 |
|
- |
b8 = (s[48] << 14) | (s[49] >>> 18); |
| 1342 |
|
- |
b9 = (s[49] << 14) | (s[48] >>> 18); |
| 1343 |
|
- |
|
| 1344 |
|
- |
s[0] = b0 ^ (~b2 & b4); |
| 1345 |
|
- |
s[1] = b1 ^ (~b3 & b5); |
| 1346 |
|
- |
s[10] = b10 ^ (~b12 & b14); |
| 1347 |
|
- |
s[11] = b11 ^ (~b13 & b15); |
| 1348 |
|
- |
s[20] = b20 ^ (~b22 & b24); |
| 1349 |
|
- |
s[21] = b21 ^ (~b23 & b25); |
| 1350 |
|
- |
s[30] = b30 ^ (~b32 & b34); |
| 1351 |
|
- |
s[31] = b31 ^ (~b33 & b35); |
| 1352 |
|
- |
s[40] = b40 ^ (~b42 & b44); |
| 1353 |
|
- |
s[41] = b41 ^ (~b43 & b45); |
| 1354 |
|
- |
s[2] = b2 ^ (~b4 & b6); |
| 1355 |
|
- |
s[3] = b3 ^ (~b5 & b7); |
| 1356 |
|
- |
s[12] = b12 ^ (~b14 & b16); |
| 1357 |
|
- |
s[13] = b13 ^ (~b15 & b17); |
| 1358 |
|
- |
s[22] = b22 ^ (~b24 & b26); |
| 1359 |
|
- |
s[23] = b23 ^ (~b25 & b27); |
| 1360 |
|
- |
s[32] = b32 ^ (~b34 & b36); |
| 1361 |
|
- |
s[33] = b33 ^ (~b35 & b37); |
| 1362 |
|
- |
s[42] = b42 ^ (~b44 & b46); |
| 1363 |
|
- |
s[43] = b43 ^ (~b45 & b47); |
| 1364 |
|
- |
s[4] = b4 ^ (~b6 & b8); |
| 1365 |
|
- |
s[5] = b5 ^ (~b7 & b9); |
| 1366 |
|
- |
s[14] = b14 ^ (~b16 & b18); |
| 1367 |
|
- |
s[15] = b15 ^ (~b17 & b19); |
| 1368 |
|
- |
s[24] = b24 ^ (~b26 & b28); |
| 1369 |
|
- |
s[25] = b25 ^ (~b27 & b29); |
| 1370 |
|
- |
s[34] = b34 ^ (~b36 & b38); |
| 1371 |
|
- |
s[35] = b35 ^ (~b37 & b39); |
| 1372 |
|
- |
s[44] = b44 ^ (~b46 & b48); |
| 1373 |
|
- |
s[45] = b45 ^ (~b47 & b49); |
| 1374 |
|
- |
s[6] = b6 ^ (~b8 & b0); |
| 1375 |
|
- |
s[7] = b7 ^ (~b9 & b1); |
| 1376 |
|
- |
s[16] = b16 ^ (~b18 & b10); |
| 1377 |
|
- |
s[17] = b17 ^ (~b19 & b11); |
| 1378 |
|
- |
s[26] = b26 ^ (~b28 & b20); |
| 1379 |
|
- |
s[27] = b27 ^ (~b29 & b21); |
| 1380 |
|
- |
s[36] = b36 ^ (~b38 & b30); |
| 1381 |
|
- |
s[37] = b37 ^ (~b39 & b31); |
| 1382 |
|
- |
s[46] = b46 ^ (~b48 & b40); |
| 1383 |
|
- |
s[47] = b47 ^ (~b49 & b41); |
| 1384 |
|
- |
s[8] = b8 ^ (~b0 & b2); |
| 1385 |
|
- |
s[9] = b9 ^ (~b1 & b3); |
| 1386 |
|
- |
s[18] = b18 ^ (~b10 & b12); |
| 1387 |
|
- |
s[19] = b19 ^ (~b11 & b13); |
| 1388 |
|
- |
s[28] = b28 ^ (~b20 & b22); |
| 1389 |
|
- |
s[29] = b29 ^ (~b21 & b23); |
| 1390 |
|
- |
s[38] = b38 ^ (~b30 & b32); |
| 1391 |
|
- |
s[39] = b39 ^ (~b31 & b33); |
| 1392 |
|
- |
s[48] = b48 ^ (~b40 & b42); |
| 1393 |
|
- |
s[49] = b49 ^ (~b41 & b43); |
| 1394 |
|
- |
|
| 1395 |
|
- |
s[0] ^= RC[n]; |
| 1396 |
|
- |
s[1] ^= RC[n + 1]; |
| 1397 |
|
- |
} |
| 1398 |
|
- |
}; |
| 1399 |
|
- |
|
| 1400 |
|
- |
if (COMMON_JS) { |
| 1401 |
|
- |
module.exports = methods; |
| 1402 |
|
- |
} else { |
| 1403 |
|
- |
for (i = 0; i < methodNames.length; ++i) { |
| 1404 |
|
- |
root[methodNames[i]] = methods[methodNames[i]]; |
| 1405 |
|
- |
} |
| 1406 |
|
- |
if (AMD) { |
| 1407 |
|
- |
define(function () { |
| 1408 |
|
- |
return methods; |
| 1409 |
|
- |
}); |
| 1410 |
|
- |
} |
| 1411 |
|
- |
} |
| 1412 |
|
- |
|
| 1413 |
|
- |
// Ensure functions are always available globally in browser |
| 1414 |
|
- |
if (typeof window !== "undefined") { |
| 1415 |
|
- |
for (let i = 0; i < methodNames.length; ++i) { |
| 1416 |
|
- |
window[methodNames[i]] = methods[methodNames[i]]; |
| 1417 |
|
- |
} |
| 1418 |
|
- |
} |
| 1419 |
|
- |
})(); |