forked from bcoin-org/bcrypto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshake.js
76 lines (60 loc) · 1.34 KB
/
shake.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*!
* shake.js - SHAKE implementation for bcrypto
* Copyright (c) 2017-2019, Christopher Jeffrey (MIT License).
* https://github.com/bcoin-org/bcrypto
*
* Resources:
* https://en.wikipedia.org/wiki/SHA-3
* https://keccak.team/specifications.html
* https://csrc.nist.gov/projects/hash-functions/sha-3-project/sha-3-standardization
* http://dx.doi.org/10.6028/NIST.FIPS.202
*/
'use strict';
const Keccak = require('./keccak');
/**
* SHAKE
*/
class SHAKE extends Keccak {
/**
* Create a SHAKE Context.
* @constructor
*/
constructor() {
super();
}
final(len) {
return super.final(0x1f, len);
}
static hash() {
return new SHAKE();
}
static hmac(bits, len) {
return super.hmac(bits, 0x1f, len);
}
static digest(data, bits, len) {
return super.digest(data, bits, 0x1f, len);
}
static root(left, right, bits, len) {
return super.root(left, right, bits, 0x1f, len);
}
static multi(x, y, z, bits, len) {
return super.multi(x, y, z, bits, 0x1f, len);
}
static mac(data, key, bits, len) {
return super.mac(data, key, bits, 0x1f, len);
}
}
/*
* Static
*/
SHAKE.native = Keccak.native;
SHAKE.id = 'SHAKE256';
SHAKE.size = 32;
SHAKE.bits = 256;
SHAKE.blockSize = 136;
SHAKE.zero = Buffer.alloc(32, 0x00);
SHAKE.ctx = new SHAKE();
/*
* Expose
*/
module.exports = SHAKE;