landvex: Fixar och tester klara för alla komponenter
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
This commit is contained in:
+106
@@ -0,0 +1,106 @@
|
||||
# Change Log
|
||||
|
||||
## v0.8.0 / 2018-08-05
|
||||
### Added
|
||||
- TypeScript definitions.
|
||||
|
||||
### Changed
|
||||
- throw error if update after finalize
|
||||
|
||||
## v0.7.0 / 2017-12-01
|
||||
### Added
|
||||
- AMD support.
|
||||
- support for web worker. #13
|
||||
|
||||
### Changed
|
||||
- throw error if input type is incorrect when cSHAKE and KMAC.
|
||||
- freeze hash after finalize.
|
||||
|
||||
## v0.6.1 / 2017-07-03
|
||||
### Fixed
|
||||
- Typo on variable kmac_256 type definition. #12
|
||||
|
||||
## v0.6.0 / 2017-06-15
|
||||
### Added
|
||||
- cSHAKE method.
|
||||
- KMAC method.
|
||||
- alias methods without underscore like shake128, keccak512.
|
||||
|
||||
### Changed
|
||||
- throw error if input type is incorrect.
|
||||
|
||||
## v0.5.7 / 2016-12-30
|
||||
### Fixed
|
||||
- ArrayBuffer detection in old browsers.
|
||||
|
||||
## v0.5.6 / 2016-12-29
|
||||
### Fixed
|
||||
- ArrayBuffer dosen't work in Webpack.
|
||||
|
||||
## v0.5.5 / 2016-09-26
|
||||
### Added
|
||||
- TypeScript support.
|
||||
- ArrayBuffer method.
|
||||
|
||||
### Deprecated
|
||||
- Buffer method.
|
||||
|
||||
## v0.5.4 / 2016-09-12
|
||||
### Fixed
|
||||
- CommonJS detection.
|
||||
|
||||
## v0.5.3 / 2016-09-08
|
||||
### Added
|
||||
- Some missing files to npm package.
|
||||
|
||||
## v0.5.2 / 2016-06-06
|
||||
### Fixed
|
||||
- Shake output incorrect in the special length.
|
||||
|
||||
## v0.5.1 / 2015-10-27
|
||||
### Fixed
|
||||
- Version in package.json and bower.json.
|
||||
|
||||
## v0.5.0 / 2015-09-23
|
||||
### Added
|
||||
- Hash object with create/update interface.
|
||||
|
||||
## v0.4.1 / 2015-09-18
|
||||
### Added
|
||||
- Integer array output.
|
||||
|
||||
### Fixed
|
||||
- Shake output incorrect when it's greater than 1088.
|
||||
|
||||
## v0.4.0 / 2015-09-17
|
||||
### Added
|
||||
- ArrayBuffer output.
|
||||
- Shake alogirthms.
|
||||
|
||||
## v0.3.1 / 2015-05-22
|
||||
### Fixed
|
||||
- Some bugs.
|
||||
|
||||
## v0.3.0 / 2015-05-21
|
||||
### Added
|
||||
- Integer array input.
|
||||
- ArrayBuffer input.
|
||||
|
||||
## v0.2.0 / 2015-04-04
|
||||
### Added
|
||||
- NIST's May 2014 SHA-3 version.
|
||||
|
||||
### Changed
|
||||
- Rename original methods to keccak.
|
||||
|
||||
## v0.1.2 / 2015-02-27
|
||||
### Changed
|
||||
- Improve performance.
|
||||
|
||||
## v0.1.1 / 2015-02-26
|
||||
### Changed
|
||||
- Improve performance.
|
||||
|
||||
## v0.1.0 / 2015-02-23
|
||||
### Added
|
||||
- First version implementation.
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
Copyright 2015-2018 Chen, Yi-Cyuan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
# js-sha3
|
||||
|
||||
[](https://travis-ci.org/emn178/js-sha3)
|
||||
[](https://coveralls.io/r/emn178/js-sha3?branch=master)
|
||||
[](https://nodei.co/npm/js-sha3/)
|
||||
|
||||
A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.
|
||||
|
||||
## Notice
|
||||
* v0.8.0+ will throw an error if try to update hash after finalize.
|
||||
* Sha3 methods has been renamed to keccak since v0.2.0. It means that sha3 methods of v0.1.x are equal to keccak methods of v0.2.x and later.
|
||||
* `buffer` method is deprecated. This maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
|
||||
|
||||
## Demo
|
||||
[SHA3-512 Online](http://emn178.github.io/online-tools/sha3_512.html)
|
||||
[SHA3-384 Online](http://emn178.github.io/online-tools/sha3_384.html)
|
||||
[SHA3-256 Online](http://emn178.github.io/online-tools/sha3_256.html)
|
||||
[SHA3-224 Online](http://emn178.github.io/online-tools/sha3_224.html)
|
||||
[Keccak-512 Online](http://emn178.github.io/online-tools/keccak_512.html)
|
||||
[Keccak-384 Online](http://emn178.github.io/online-tools/keccak_384.html)
|
||||
[Keccak-256 Online](http://emn178.github.io/online-tools/keccak_256.html)
|
||||
[Keccak-224 Online](http://emn178.github.io/online-tools/keccak_224.html)
|
||||
[Shake128 Online](http://emn178.github.io/online-tools/shake_128.html)
|
||||
[Shake256 Online](http://emn178.github.io/online-tools/shake_256.html)
|
||||
|
||||
## Download
|
||||
[Compress](https://raw.github.com/emn178/js-sha3/master/build/sha3.min.js)
|
||||
[Uncompress](https://raw.github.com/emn178/js-sha3/master/src/sha3.js)
|
||||
|
||||
## Installation
|
||||
You can also install js-sha3 by using Bower.
|
||||
|
||||
bower install js-sha3
|
||||
|
||||
For node.js, you can use this command to install:
|
||||
|
||||
npm install js-sha3
|
||||
|
||||
## Usage
|
||||
You could use like this:
|
||||
```JavaScript
|
||||
sha3_512('Message to hash');
|
||||
sha3_384('Message to hash');
|
||||
sha3_256('Message to hash');
|
||||
sha3_224('Message to hash');
|
||||
keccak512('Message to hash');
|
||||
keccak384('Message to hash');
|
||||
keccak256('Message to hash');
|
||||
keccak224('Message to hash');
|
||||
shake128('Message to hash', 256);
|
||||
shake256('Message to hash', 512);
|
||||
cshake128('Message to hash', 256, 'function name', 'customization');
|
||||
cshake256('Message to hash', 512, 'function name', 'customization');
|
||||
kmac128('key', 'Message to hash', 256, 'customization');
|
||||
kmac256('key', 'Message to hash', 512, 'customization');
|
||||
|
||||
// Support ArrayBuffer output
|
||||
var arrayBuffer = keccak224.arrayBuffer('Message to hash');
|
||||
|
||||
// Support Array output
|
||||
var bytes = keccak224.digest('Message to hash');
|
||||
var bytes = keccak224.array('Message to hash');
|
||||
|
||||
// update hash
|
||||
sha3_512.update('Message ').update('to ').update('hash').hex();
|
||||
// specify shake output bits at first update
|
||||
shake128.update('Message ', 256).update('to ').update('hash').hex();
|
||||
|
||||
// or to use create
|
||||
var hash = sha3_512.create();
|
||||
hash.update('...');
|
||||
hash.update('...');
|
||||
hash.hex();
|
||||
|
||||
// specify shake output bits when creating
|
||||
var hash = shake128.create(256);
|
||||
hash.update('...');
|
||||
hash.update('...');
|
||||
hash.hex();
|
||||
|
||||
// specify cshake output bits, function name and customization when creating
|
||||
var hash = cshake128.create(256, 'function name', 'customization');
|
||||
|
||||
// specify kmac key, output bits and customization when creating
|
||||
var hash = kmac128.create('key', 256, 'customization');
|
||||
```
|
||||
If you use node.js, you should require the module first:
|
||||
```JavaScript
|
||||
sha3_512 = require('js-sha3').sha3_512;
|
||||
sha3_384 = require('js-sha3').sha3_384;
|
||||
sha3_256 = require('js-sha3').sha3_256;
|
||||
sha3_224 = require('js-sha3').sha3_224;
|
||||
keccak512 = require('js-sha3').keccak512;
|
||||
keccak384 = require('js-sha3').keccak384;
|
||||
keccak256 = require('js-sha3').keccak256;
|
||||
keccak224 = require('js-sha3').keccak224;
|
||||
shake128 = require('js-sha3').shake128;
|
||||
shake256 = require('js-sha3').shake256;
|
||||
cshake128 = require('js-sha3').cshake128;
|
||||
cshake256 = require('js-sha3').cshake256;
|
||||
kmac128 = require('js-sha3').kmac128;
|
||||
kmac256 = require('js-sha3').kmac256;
|
||||
```
|
||||
If you use TypeScript, you can import like this:
|
||||
```TypeScript
|
||||
import { sha3_512 } from 'js-sha3';
|
||||
```
|
||||
|
||||
## Example
|
||||
Code
|
||||
```JavaScript
|
||||
sha3_512('');
|
||||
// a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26
|
||||
|
||||
sha3_512('The quick brown fox jumps over the lazy dog');
|
||||
// 01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450
|
||||
|
||||
sha3_512('The quick brown fox jumps over the lazy dog.');
|
||||
// 18f4f4bd419603f95538837003d9d254c26c23765565162247483f65c50303597bc9ce4d289f21d1c2f1f458828e33dc442100331b35e7eb031b5d38ba6460f8
|
||||
|
||||
sha3_384('');
|
||||
// 0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004
|
||||
|
||||
sha3_384('The quick brown fox jumps over the lazy dog');
|
||||
// 7063465e08a93bce31cd89d2e3ca8f602498696e253592ed26f07bf7e703cf328581e1471a7ba7ab119b1a9ebdf8be41
|
||||
|
||||
sha3_384('The quick brown fox jumps over the lazy dog.');
|
||||
// 1a34d81695b622df178bc74df7124fe12fac0f64ba5250b78b99c1273d4b080168e10652894ecad5f1f4d5b965437fb9
|
||||
|
||||
sha3_256('');
|
||||
// a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a
|
||||
|
||||
sha3_256('The quick brown fox jumps over the lazy dog');
|
||||
// 69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04
|
||||
|
||||
sha3_256('The quick brown fox jumps over the lazy dog.');
|
||||
// a80f839cd4f83f6c3dafc87feae470045e4eb0d366397d5c6ce34ba1739f734d
|
||||
|
||||
sha3_224('');
|
||||
// 6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7
|
||||
|
||||
sha3_224('The quick brown fox jumps over the lazy dog');
|
||||
// d15dadceaa4d5d7bb3b48f446421d542e08ad8887305e28d58335795
|
||||
|
||||
sha3_224('The quick brown fox jumps over the lazy dog.');
|
||||
// 2d0708903833afabdd232a20201176e8b58c5be8a6fe74265ac54db0
|
||||
|
||||
keccak512('');
|
||||
// 0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e
|
||||
|
||||
keccak512('The quick brown fox jumps over the lazy dog');
|
||||
// d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609
|
||||
|
||||
keccak512('The quick brown fox jumps over the lazy dog.');
|
||||
// ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760
|
||||
|
||||
keccak384('');
|
||||
// 2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff
|
||||
|
||||
keccak384('The quick brown fox jumps over the lazy dog');
|
||||
// 283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3
|
||||
|
||||
keccak384('The quick brown fox jumps over the lazy dog.');
|
||||
// 9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b
|
||||
|
||||
keccak256('');
|
||||
// c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
|
||||
|
||||
keccak256('The quick brown fox jumps over the lazy dog');
|
||||
// 4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15
|
||||
|
||||
keccak256('The quick brown fox jumps over the lazy dog.');
|
||||
// 578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d
|
||||
|
||||
keccak224('');
|
||||
// f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd
|
||||
|
||||
keccak224('The quick brown fox jumps over the lazy dog');
|
||||
// 310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe
|
||||
|
||||
keccak224('The quick brown fox jumps over the lazy dog.');
|
||||
// c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab
|
||||
|
||||
shake128('', 256);
|
||||
// 7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26
|
||||
|
||||
shake256('', 512);
|
||||
// 46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be
|
||||
```
|
||||
It also supports UTF-8 encoding:
|
||||
|
||||
Code
|
||||
```JavaScript
|
||||
sha3_512('中文');
|
||||
// 059bbe2efc50cc30e4d8ec5a96be697e2108fcbf9193e1296192eddabc13b143c0120d059399a13d0d42651efe23a6c1ce2d1efb576c5b207fa2516050505af7
|
||||
|
||||
sha3_384('中文');
|
||||
// 9fb5b99e3c546f2738dcd50a14e9aef9c313800c1bf8cf76bc9b2c3a23307841364c5a2d0794702662c5796fb72f5432
|
||||
|
||||
sha3_256('中文');
|
||||
// ac5305da3d18be1aed44aa7c70ea548da243a59a5fd546f489348fd5718fb1a0
|
||||
|
||||
sha3_224('中文');
|
||||
// 106d169e10b61c2a2a05554d3e631ec94467f8316640f29545d163ee
|
||||
|
||||
keccak512('中文');
|
||||
// 2f6a1bd50562230229af34b0ccf46b8754b89d23ae2c5bf7840b4acfcef86f87395edc0a00b2bfef53bafebe3b79de2e3e01cbd8169ddbb08bde888dcc893524
|
||||
|
||||
keccak384('中文');
|
||||
// 743f64bb7544c6ed923be4741b738dde18b7cee384a3a09c4e01acaaac9f19222cdee137702bd3aa05dc198373d87d6c
|
||||
|
||||
keccak256('中文');
|
||||
// 70a2b6579047f0a977fcb5e9120a4e07067bea9abb6916fbc2d13ffb9a4e4eee
|
||||
|
||||
keccak224('中文');
|
||||
// f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd
|
||||
```
|
||||
|
||||
It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input:
|
||||
|
||||
Code
|
||||
```JavaScript
|
||||
sha3_512([]);
|
||||
// a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26
|
||||
|
||||
sha3_512(new Uint8Array([]));
|
||||
// a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
## Benchmark
|
||||
[UTF8](http://jsperf.com/sha3/5)
|
||||
[ASCII](http://jsperf.com/sha3/4)
|
||||
|
||||
## License
|
||||
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
|
||||
|
||||
## Contact
|
||||
The project's website is located at https://github.com/emn178/js-sha3
|
||||
Author: Chen, Yi-Cyuan (emn178@gmail.com)
|
||||
+9
File diff suppressed because one or more lines are too long
+317
@@ -0,0 +1,317 @@
|
||||
type Message = string | number[] | ArrayBuffer | Uint8Array;
|
||||
|
||||
interface Hasher {
|
||||
/**
|
||||
* Update hash
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(message: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*/
|
||||
hex(): string;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/**
|
||||
* Return hash in ArrayBuffer.
|
||||
*/
|
||||
arrayBuffer(): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*/
|
||||
digest(): number[];
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*/
|
||||
array(): number[];
|
||||
}
|
||||
|
||||
interface Hash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
(message: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
hex(message: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
arrayBuffer(message: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
digest(message: Message): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
array(message: Message): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*/
|
||||
create(): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(message: Message): Hasher;
|
||||
}
|
||||
|
||||
interface ShakeHash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
(message: Message, outputBits: number): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
hex(message: Message, outputBits: number): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
arrayBuffer(message: Message, outputBits: number): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
digest(message: Message, outputBits: number): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
array(message: Message, outputBits: number): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*
|
||||
* @param outputBits The length of output.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
create(outputBits: number): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
update(message: Message, outputBits: number): Hasher;
|
||||
}
|
||||
|
||||
interface CshakeHash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
(message: Message, outputBits: number, functionName: Message, customization: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
hex(message: Message, outputBits: number, functionName: Message, customization: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
arrayBuffer(message: Message, outputBits: number, functionName: Message, customization: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
digest(message: Message, outputBits: number, functionName: Message, customization: Message): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
array(message: Message, outputBits: number, functionName: Message, customization: Message): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*
|
||||
* @param outputBits The length of output.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
create(outputBits: number): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
create(outputBits: number, functionName: Message, customization: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
update(message: Message, outputBits: number, functionName: Message, customization: Message): Hasher;
|
||||
}
|
||||
|
||||
interface KmacHash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
(key: Message, message: Message, outputBits: number, customization: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
hex(key: Message, message: Message, outputBits: number, customization: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
arrayBuffer(key: Message, message: Message, outputBits: number, customization: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
digest(key: Message, message: Message, outputBits: number, customization: Message): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
array(key: Message, message: Message, outputBits: number, customization: Message): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
create(key: Message, outputBits: number, customization: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
update(key: Message, message: Message, outputBits: number, customization: Message): Hasher;
|
||||
}
|
||||
|
||||
export var sha3_512: Hash;
|
||||
export var sha3_384: Hash;
|
||||
export var sha3_256: Hash;
|
||||
export var sha3_224: Hash;
|
||||
export var keccak_512: Hash;
|
||||
export var keccak_384: Hash;
|
||||
export var keccak_256: Hash;
|
||||
export var keccak_224: Hash;
|
||||
export var keccak512: Hash;
|
||||
export var keccak384: Hash;
|
||||
export var keccak256: Hash;
|
||||
export var keccak224: Hash;
|
||||
export var shake_128: ShakeHash;
|
||||
export var shake_256: ShakeHash;
|
||||
export var shake128: ShakeHash;
|
||||
export var shake256: ShakeHash;
|
||||
export var cshake_128: CshakeHash;
|
||||
export var cshake_256: CshakeHash;
|
||||
export var cshake128: CshakeHash;
|
||||
export var cshake256: CshakeHash;
|
||||
export var kmac_128: KmacHash;
|
||||
export var kmac_256: KmacHash;
|
||||
export var kmac128: KmacHash;
|
||||
export var kmac256: KmacHash;
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "js-sha3",
|
||||
"version": "0.8.0",
|
||||
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
|
||||
"main": "src/sha3.js",
|
||||
"devDependencies": {
|
||||
"expect.js": "~0.3.1",
|
||||
"mocha": "~2.3.4",
|
||||
"nyc": "^11.3.0",
|
||||
"uglify-js": "^3.1.9",
|
||||
"webworker-threads": "^0.7.13"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nyc mocha tests/node-test.js",
|
||||
"report": "nyc --reporter=html --reporter=text mocha tests/node-test.js",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||
"build": "uglifyjs src/sha3.js -c -m --comments --output build/sha3.min.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/emn178/js-sha3.git"
|
||||
},
|
||||
"keywords": [
|
||||
"sha3",
|
||||
"keccak",
|
||||
"shake",
|
||||
"cshake",
|
||||
"kmac",
|
||||
"hash",
|
||||
"encryption",
|
||||
"cryptography",
|
||||
"HMAC"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": "Chen, Yi-Cyuan <emn178@gmail.com>",
|
||||
"homepage": "https://github.com/emn178/js-sha3",
|
||||
"bugs": {
|
||||
"url": "https://github.com/emn178/js-sha3/issues"
|
||||
},
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
"tests"
|
||||
]
|
||||
}
|
||||
}
|
||||
+656
@@ -0,0 +1,656 @@
|
||||
/**
|
||||
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
||||
*
|
||||
* @version 0.8.0
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2015-2018
|
||||
* @license MIT
|
||||
*/
|
||||
/*jslint bitwise: true */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var INPUT_ERROR = 'input is invalid type';
|
||||
var FINALIZE_ERROR = 'finalize already called';
|
||||
var WINDOW = typeof window === 'object';
|
||||
var root = WINDOW ? window : {};
|
||||
if (root.JS_SHA3_NO_WINDOW) {
|
||||
WINDOW = false;
|
||||
}
|
||||
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
||||
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
||||
if (NODE_JS) {
|
||||
root = global;
|
||||
} else if (WEB_WORKER) {
|
||||
root = self;
|
||||
}
|
||||
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||
var AMD = typeof define === 'function' && define.amd;
|
||||
var ARRAY_BUFFER = !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
|
||||
var CSHAKE_PADDING = [4, 1024, 262144, 67108864];
|
||||
var KECCAK_PADDING = [1, 256, 65536, 16777216];
|
||||
var PADDING = [6, 1536, 393216, 100663296];
|
||||
var SHIFT = [0, 8, 16, 24];
|
||||
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
|
||||
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
|
||||
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
|
||||
2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
|
||||
2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
|
||||
var BITS = [224, 256, 384, 512];
|
||||
var SHAKE_BITS = [128, 256];
|
||||
var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array', 'digest'];
|
||||
var CSHAKE_BYTEPAD = {
|
||||
'128': 168,
|
||||
'256': 136
|
||||
};
|
||||
|
||||
if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) {
|
||||
Array.isArray = function (obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||
};
|
||||
}
|
||||
|
||||
if (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
||||
ArrayBuffer.isView = function (obj) {
|
||||
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
var createOutputMethod = function (bits, padding, outputType) {
|
||||
return function (message) {
|
||||
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
var createShakeOutputMethod = function (bits, padding, outputType) {
|
||||
return function (message, outputBits) {
|
||||
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
var createCshakeOutputMethod = function (bits, padding, outputType) {
|
||||
return function (message, outputBits, n, s) {
|
||||
return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
var createKmacOutputMethod = function (bits, padding, outputType) {
|
||||
return function (key, message, outputBits, s) {
|
||||
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
var createOutputMethods = function (method, createMethod, bits, padding) {
|
||||
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
||||
var type = OUTPUT_TYPES[i];
|
||||
method[type] = createMethod(bits, padding, type);
|
||||
}
|
||||
return method;
|
||||
};
|
||||
|
||||
var createMethod = function (bits, padding) {
|
||||
var method = createOutputMethod(bits, padding, 'hex');
|
||||
method.create = function () {
|
||||
return new Keccak(bits, padding, bits);
|
||||
};
|
||||
method.update = function (message) {
|
||||
return method.create().update(message);
|
||||
};
|
||||
return createOutputMethods(method, createOutputMethod, bits, padding);
|
||||
};
|
||||
|
||||
var createShakeMethod = function (bits, padding) {
|
||||
var method = createShakeOutputMethod(bits, padding, 'hex');
|
||||
method.create = function (outputBits) {
|
||||
return new Keccak(bits, padding, outputBits);
|
||||
};
|
||||
method.update = function (message, outputBits) {
|
||||
return method.create(outputBits).update(message);
|
||||
};
|
||||
return createOutputMethods(method, createShakeOutputMethod, bits, padding);
|
||||
};
|
||||
|
||||
var createCshakeMethod = function (bits, padding) {
|
||||
var w = CSHAKE_BYTEPAD[bits];
|
||||
var method = createCshakeOutputMethod(bits, padding, 'hex');
|
||||
method.create = function (outputBits, n, s) {
|
||||
if (!n && !s) {
|
||||
return methods['shake' + bits].create(outputBits);
|
||||
} else {
|
||||
return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
|
||||
}
|
||||
};
|
||||
method.update = function (message, outputBits, n, s) {
|
||||
return method.create(outputBits, n, s).update(message);
|
||||
};
|
||||
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
||||
};
|
||||
|
||||
var createKmacMethod = function (bits, padding) {
|
||||
var w = CSHAKE_BYTEPAD[bits];
|
||||
var method = createKmacOutputMethod(bits, padding, 'hex');
|
||||
method.create = function (key, outputBits, s) {
|
||||
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
||||
};
|
||||
method.update = function (key, message, outputBits, s) {
|
||||
return method.create(key, outputBits, s).update(message);
|
||||
};
|
||||
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
||||
};
|
||||
|
||||
var algorithms = [
|
||||
{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod },
|
||||
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
||||
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
||||
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
||||
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }
|
||||
];
|
||||
|
||||
var methods = {}, methodNames = [];
|
||||
|
||||
for (var i = 0; i < algorithms.length; ++i) {
|
||||
var algorithm = algorithms[i];
|
||||
var bits = algorithm.bits;
|
||||
for (var j = 0; j < bits.length; ++j) {
|
||||
var methodName = algorithm.name + '_' + bits[j];
|
||||
methodNames.push(methodName);
|
||||
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
|
||||
if (algorithm.name !== 'sha3') {
|
||||
var newMethodName = algorithm.name + bits[j];
|
||||
methodNames.push(newMethodName);
|
||||
methods[newMethodName] = methods[methodName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Keccak(bits, padding, outputBits) {
|
||||
this.blocks = [];
|
||||
this.s = [];
|
||||
this.padding = padding;
|
||||
this.outputBits = outputBits;
|
||||
this.reset = true;
|
||||
this.finalized = false;
|
||||
this.block = 0;
|
||||
this.start = 0;
|
||||
this.blockCount = (1600 - (bits << 1)) >> 5;
|
||||
this.byteCount = this.blockCount << 2;
|
||||
this.outputBlocks = outputBits >> 5;
|
||||
this.extraBytes = (outputBits & 31) >> 3;
|
||||
|
||||
for (var i = 0; i < 50; ++i) {
|
||||
this.s[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Keccak.prototype.update = function (message) {
|
||||
if (this.finalized) {
|
||||
throw new Error(FINALIZE_ERROR);
|
||||
}
|
||||
var notString, type = typeof message;
|
||||
if (type !== 'string') {
|
||||
if (type === 'object') {
|
||||
if (message === null) {
|
||||
throw new Error(INPUT_ERROR);
|
||||
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
} else if (!Array.isArray(message)) {
|
||||
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
||||
throw new Error(INPUT_ERROR);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error(INPUT_ERROR);
|
||||
}
|
||||
notString = true;
|
||||
}
|
||||
var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
|
||||
blockCount = this.blockCount, index = 0, s = this.s, i, code;
|
||||
|
||||
while (index < length) {
|
||||
if (this.reset) {
|
||||
this.reset = false;
|
||||
blocks[0] = this.block;
|
||||
for (i = 1; i < blockCount + 1; ++i) {
|
||||
blocks[i] = 0;
|
||||
}
|
||||
}
|
||||
if (notString) {
|
||||
for (i = this.start; index < length && i < byteCount; ++index) {
|
||||
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
||||
}
|
||||
} else {
|
||||
for (i = this.start; index < length && i < byteCount; ++index) {
|
||||
code = message.charCodeAt(index);
|
||||
if (code < 0x80) {
|
||||
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
||||
} else if (code < 0x800) {
|
||||
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else {
|
||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastByteIndex = i;
|
||||
if (i >= byteCount) {
|
||||
this.start = i - byteCount;
|
||||
this.block = blocks[blockCount];
|
||||
for (i = 0; i < blockCount; ++i) {
|
||||
s[i] ^= blocks[i];
|
||||
}
|
||||
f(s);
|
||||
this.reset = true;
|
||||
} else {
|
||||
this.start = i;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Keccak.prototype.encode = function (x, right) {
|
||||
var o = x & 255, n = 1;
|
||||
var bytes = [o];
|
||||
x = x >> 8;
|
||||
o = x & 255;
|
||||
while (o > 0) {
|
||||
bytes.unshift(o);
|
||||
x = x >> 8;
|
||||
o = x & 255;
|
||||
++n;
|
||||
}
|
||||
if (right) {
|
||||
bytes.push(n);
|
||||
} else {
|
||||
bytes.unshift(n);
|
||||
}
|
||||
this.update(bytes);
|
||||
return bytes.length;
|
||||
};
|
||||
|
||||
Keccak.prototype.encodeString = function (str) {
|
||||
var notString, type = typeof str;
|
||||
if (type !== 'string') {
|
||||
if (type === 'object') {
|
||||
if (str === null) {
|
||||
throw new Error(INPUT_ERROR);
|
||||
} else if (ARRAY_BUFFER && str.constructor === ArrayBuffer) {
|
||||
str = new Uint8Array(str);
|
||||
} else if (!Array.isArray(str)) {
|
||||
if (!ARRAY_BUFFER || !ArrayBuffer.isView(str)) {
|
||||
throw new Error(INPUT_ERROR);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error(INPUT_ERROR);
|
||||
}
|
||||
notString = true;
|
||||
}
|
||||
var bytes = 0, length = str.length;
|
||||
if (notString) {
|
||||
bytes = length;
|
||||
} else {
|
||||
for (var i = 0; i < str.length; ++i) {
|
||||
var code = str.charCodeAt(i);
|
||||
if (code < 0x80) {
|
||||
bytes += 1;
|
||||
} else if (code < 0x800) {
|
||||
bytes += 2;
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
bytes += 3;
|
||||
} else {
|
||||
code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
|
||||
bytes += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
bytes += this.encode(bytes * 8);
|
||||
this.update(str);
|
||||
return bytes;
|
||||
};
|
||||
|
||||
Keccak.prototype.bytepad = function (strs, w) {
|
||||
var bytes = this.encode(w);
|
||||
for (var i = 0; i < strs.length; ++i) {
|
||||
bytes += this.encodeString(strs[i]);
|
||||
}
|
||||
var paddingBytes = w - bytes % w;
|
||||
var zeros = [];
|
||||
zeros.length = paddingBytes;
|
||||
this.update(zeros);
|
||||
return this;
|
||||
};
|
||||
|
||||
Keccak.prototype.finalize = function () {
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
this.finalized = true;
|
||||
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
|
||||
blocks[i >> 2] |= this.padding[i & 3];
|
||||
if (this.lastByteIndex === this.byteCount) {
|
||||
blocks[0] = blocks[blockCount];
|
||||
for (i = 1; i < blockCount + 1; ++i) {
|
||||
blocks[i] = 0;
|
||||
}
|
||||
}
|
||||
blocks[blockCount - 1] |= 0x80000000;
|
||||
for (i = 0; i < blockCount; ++i) {
|
||||
s[i] ^= blocks[i];
|
||||
}
|
||||
f(s);
|
||||
};
|
||||
|
||||
Keccak.prototype.toString = Keccak.prototype.hex = function () {
|
||||
this.finalize();
|
||||
|
||||
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
||||
extraBytes = this.extraBytes, i = 0, j = 0;
|
||||
var hex = '', block;
|
||||
while (j < outputBlocks) {
|
||||
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
||||
block = s[i];
|
||||
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
|
||||
HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
|
||||
HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
|
||||
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
||||
}
|
||||
if (j % blockCount === 0) {
|
||||
f(s);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
if (extraBytes) {
|
||||
block = s[i];
|
||||
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
|
||||
if (extraBytes > 1) {
|
||||
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
|
||||
}
|
||||
if (extraBytes > 2) {
|
||||
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
|
||||
}
|
||||
}
|
||||
return hex;
|
||||
};
|
||||
|
||||
Keccak.prototype.arrayBuffer = function () {
|
||||
this.finalize();
|
||||
|
||||
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
||||
extraBytes = this.extraBytes, i = 0, j = 0;
|
||||
var bytes = this.outputBits >> 3;
|
||||
var buffer;
|
||||
if (extraBytes) {
|
||||
buffer = new ArrayBuffer((outputBlocks + 1) << 2);
|
||||
} else {
|
||||
buffer = new ArrayBuffer(bytes);
|
||||
}
|
||||
var array = new Uint32Array(buffer);
|
||||
while (j < outputBlocks) {
|
||||
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
||||
array[j] = s[i];
|
||||
}
|
||||
if (j % blockCount === 0) {
|
||||
f(s);
|
||||
}
|
||||
}
|
||||
if (extraBytes) {
|
||||
array[i] = s[i];
|
||||
buffer = buffer.slice(0, bytes);
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
|
||||
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
|
||||
|
||||
Keccak.prototype.digest = Keccak.prototype.array = function () {
|
||||
this.finalize();
|
||||
|
||||
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
||||
extraBytes = this.extraBytes, i = 0, j = 0;
|
||||
var array = [], offset, block;
|
||||
while (j < outputBlocks) {
|
||||
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
||||
offset = j << 2;
|
||||
block = s[i];
|
||||
array[offset] = block & 0xFF;
|
||||
array[offset + 1] = (block >> 8) & 0xFF;
|
||||
array[offset + 2] = (block >> 16) & 0xFF;
|
||||
array[offset + 3] = (block >> 24) & 0xFF;
|
||||
}
|
||||
if (j % blockCount === 0) {
|
||||
f(s);
|
||||
}
|
||||
}
|
||||
if (extraBytes) {
|
||||
offset = j << 2;
|
||||
block = s[i];
|
||||
array[offset] = block & 0xFF;
|
||||
if (extraBytes > 1) {
|
||||
array[offset + 1] = (block >> 8) & 0xFF;
|
||||
}
|
||||
if (extraBytes > 2) {
|
||||
array[offset + 2] = (block >> 16) & 0xFF;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
};
|
||||
|
||||
function Kmac(bits, padding, outputBits) {
|
||||
Keccak.call(this, bits, padding, outputBits);
|
||||
}
|
||||
|
||||
Kmac.prototype = new Keccak();
|
||||
|
||||
Kmac.prototype.finalize = function () {
|
||||
this.encode(this.outputBits, true);
|
||||
return Keccak.prototype.finalize.call(this);
|
||||
};
|
||||
|
||||
var f = function (s) {
|
||||
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
||||
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
||||
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
|
||||
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
|
||||
for (n = 0; n < 48; n += 2) {
|
||||
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
|
||||
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
|
||||
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
|
||||
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
|
||||
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
|
||||
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
|
||||
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
|
||||
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
|
||||
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
|
||||
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
|
||||
|
||||
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
|
||||
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
|
||||
s[0] ^= h;
|
||||
s[1] ^= l;
|
||||
s[10] ^= h;
|
||||
s[11] ^= l;
|
||||
s[20] ^= h;
|
||||
s[21] ^= l;
|
||||
s[30] ^= h;
|
||||
s[31] ^= l;
|
||||
s[40] ^= h;
|
||||
s[41] ^= l;
|
||||
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
|
||||
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
|
||||
s[2] ^= h;
|
||||
s[3] ^= l;
|
||||
s[12] ^= h;
|
||||
s[13] ^= l;
|
||||
s[22] ^= h;
|
||||
s[23] ^= l;
|
||||
s[32] ^= h;
|
||||
s[33] ^= l;
|
||||
s[42] ^= h;
|
||||
s[43] ^= l;
|
||||
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
|
||||
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
|
||||
s[4] ^= h;
|
||||
s[5] ^= l;
|
||||
s[14] ^= h;
|
||||
s[15] ^= l;
|
||||
s[24] ^= h;
|
||||
s[25] ^= l;
|
||||
s[34] ^= h;
|
||||
s[35] ^= l;
|
||||
s[44] ^= h;
|
||||
s[45] ^= l;
|
||||
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
|
||||
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
|
||||
s[6] ^= h;
|
||||
s[7] ^= l;
|
||||
s[16] ^= h;
|
||||
s[17] ^= l;
|
||||
s[26] ^= h;
|
||||
s[27] ^= l;
|
||||
s[36] ^= h;
|
||||
s[37] ^= l;
|
||||
s[46] ^= h;
|
||||
s[47] ^= l;
|
||||
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
|
||||
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
|
||||
s[8] ^= h;
|
||||
s[9] ^= l;
|
||||
s[18] ^= h;
|
||||
s[19] ^= l;
|
||||
s[28] ^= h;
|
||||
s[29] ^= l;
|
||||
s[38] ^= h;
|
||||
s[39] ^= l;
|
||||
s[48] ^= h;
|
||||
s[49] ^= l;
|
||||
|
||||
b0 = s[0];
|
||||
b1 = s[1];
|
||||
b32 = (s[11] << 4) | (s[10] >>> 28);
|
||||
b33 = (s[10] << 4) | (s[11] >>> 28);
|
||||
b14 = (s[20] << 3) | (s[21] >>> 29);
|
||||
b15 = (s[21] << 3) | (s[20] >>> 29);
|
||||
b46 = (s[31] << 9) | (s[30] >>> 23);
|
||||
b47 = (s[30] << 9) | (s[31] >>> 23);
|
||||
b28 = (s[40] << 18) | (s[41] >>> 14);
|
||||
b29 = (s[41] << 18) | (s[40] >>> 14);
|
||||
b20 = (s[2] << 1) | (s[3] >>> 31);
|
||||
b21 = (s[3] << 1) | (s[2] >>> 31);
|
||||
b2 = (s[13] << 12) | (s[12] >>> 20);
|
||||
b3 = (s[12] << 12) | (s[13] >>> 20);
|
||||
b34 = (s[22] << 10) | (s[23] >>> 22);
|
||||
b35 = (s[23] << 10) | (s[22] >>> 22);
|
||||
b16 = (s[33] << 13) | (s[32] >>> 19);
|
||||
b17 = (s[32] << 13) | (s[33] >>> 19);
|
||||
b48 = (s[42] << 2) | (s[43] >>> 30);
|
||||
b49 = (s[43] << 2) | (s[42] >>> 30);
|
||||
b40 = (s[5] << 30) | (s[4] >>> 2);
|
||||
b41 = (s[4] << 30) | (s[5] >>> 2);
|
||||
b22 = (s[14] << 6) | (s[15] >>> 26);
|
||||
b23 = (s[15] << 6) | (s[14] >>> 26);
|
||||
b4 = (s[25] << 11) | (s[24] >>> 21);
|
||||
b5 = (s[24] << 11) | (s[25] >>> 21);
|
||||
b36 = (s[34] << 15) | (s[35] >>> 17);
|
||||
b37 = (s[35] << 15) | (s[34] >>> 17);
|
||||
b18 = (s[45] << 29) | (s[44] >>> 3);
|
||||
b19 = (s[44] << 29) | (s[45] >>> 3);
|
||||
b10 = (s[6] << 28) | (s[7] >>> 4);
|
||||
b11 = (s[7] << 28) | (s[6] >>> 4);
|
||||
b42 = (s[17] << 23) | (s[16] >>> 9);
|
||||
b43 = (s[16] << 23) | (s[17] >>> 9);
|
||||
b24 = (s[26] << 25) | (s[27] >>> 7);
|
||||
b25 = (s[27] << 25) | (s[26] >>> 7);
|
||||
b6 = (s[36] << 21) | (s[37] >>> 11);
|
||||
b7 = (s[37] << 21) | (s[36] >>> 11);
|
||||
b38 = (s[47] << 24) | (s[46] >>> 8);
|
||||
b39 = (s[46] << 24) | (s[47] >>> 8);
|
||||
b30 = (s[8] << 27) | (s[9] >>> 5);
|
||||
b31 = (s[9] << 27) | (s[8] >>> 5);
|
||||
b12 = (s[18] << 20) | (s[19] >>> 12);
|
||||
b13 = (s[19] << 20) | (s[18] >>> 12);
|
||||
b44 = (s[29] << 7) | (s[28] >>> 25);
|
||||
b45 = (s[28] << 7) | (s[29] >>> 25);
|
||||
b26 = (s[38] << 8) | (s[39] >>> 24);
|
||||
b27 = (s[39] << 8) | (s[38] >>> 24);
|
||||
b8 = (s[48] << 14) | (s[49] >>> 18);
|
||||
b9 = (s[49] << 14) | (s[48] >>> 18);
|
||||
|
||||
s[0] = b0 ^ (~b2 & b4);
|
||||
s[1] = b1 ^ (~b3 & b5);
|
||||
s[10] = b10 ^ (~b12 & b14);
|
||||
s[11] = b11 ^ (~b13 & b15);
|
||||
s[20] = b20 ^ (~b22 & b24);
|
||||
s[21] = b21 ^ (~b23 & b25);
|
||||
s[30] = b30 ^ (~b32 & b34);
|
||||
s[31] = b31 ^ (~b33 & b35);
|
||||
s[40] = b40 ^ (~b42 & b44);
|
||||
s[41] = b41 ^ (~b43 & b45);
|
||||
s[2] = b2 ^ (~b4 & b6);
|
||||
s[3] = b3 ^ (~b5 & b7);
|
||||
s[12] = b12 ^ (~b14 & b16);
|
||||
s[13] = b13 ^ (~b15 & b17);
|
||||
s[22] = b22 ^ (~b24 & b26);
|
||||
s[23] = b23 ^ (~b25 & b27);
|
||||
s[32] = b32 ^ (~b34 & b36);
|
||||
s[33] = b33 ^ (~b35 & b37);
|
||||
s[42] = b42 ^ (~b44 & b46);
|
||||
s[43] = b43 ^ (~b45 & b47);
|
||||
s[4] = b4 ^ (~b6 & b8);
|
||||
s[5] = b5 ^ (~b7 & b9);
|
||||
s[14] = b14 ^ (~b16 & b18);
|
||||
s[15] = b15 ^ (~b17 & b19);
|
||||
s[24] = b24 ^ (~b26 & b28);
|
||||
s[25] = b25 ^ (~b27 & b29);
|
||||
s[34] = b34 ^ (~b36 & b38);
|
||||
s[35] = b35 ^ (~b37 & b39);
|
||||
s[44] = b44 ^ (~b46 & b48);
|
||||
s[45] = b45 ^ (~b47 & b49);
|
||||
s[6] = b6 ^ (~b8 & b0);
|
||||
s[7] = b7 ^ (~b9 & b1);
|
||||
s[16] = b16 ^ (~b18 & b10);
|
||||
s[17] = b17 ^ (~b19 & b11);
|
||||
s[26] = b26 ^ (~b28 & b20);
|
||||
s[27] = b27 ^ (~b29 & b21);
|
||||
s[36] = b36 ^ (~b38 & b30);
|
||||
s[37] = b37 ^ (~b39 & b31);
|
||||
s[46] = b46 ^ (~b48 & b40);
|
||||
s[47] = b47 ^ (~b49 & b41);
|
||||
s[8] = b8 ^ (~b0 & b2);
|
||||
s[9] = b9 ^ (~b1 & b3);
|
||||
s[18] = b18 ^ (~b10 & b12);
|
||||
s[19] = b19 ^ (~b11 & b13);
|
||||
s[28] = b28 ^ (~b20 & b22);
|
||||
s[29] = b29 ^ (~b21 & b23);
|
||||
s[38] = b38 ^ (~b30 & b32);
|
||||
s[39] = b39 ^ (~b31 & b33);
|
||||
s[48] = b48 ^ (~b40 & b42);
|
||||
s[49] = b49 ^ (~b41 & b43);
|
||||
|
||||
s[0] ^= RC[n];
|
||||
s[1] ^= RC[n + 1];
|
||||
}
|
||||
};
|
||||
|
||||
if (COMMON_JS) {
|
||||
module.exports = methods;
|
||||
} else {
|
||||
for (i = 0; i < methodNames.length; ++i) {
|
||||
root[methodNames[i]] = methods[methodNames[i]];
|
||||
}
|
||||
if (AMD) {
|
||||
define(function () {
|
||||
return methods;
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user