diff options
author | skdltmxn <supershop@naver.com> | 2020-06-05 04:14:36 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-04 15:14:36 -0400 |
commit | e05ed537130eff116b48af02d1eb6ce65953e7d8 (patch) | |
tree | 0bd1ca235ad9ed89ca602c384ab39301346afe24 /std/hash/_sha3/shake.ts | |
parent | 430beebc46be1dc87a993c2f7442c5c22076f458 (diff) |
feat(std/hash): add sha3 (#5558)
Diffstat (limited to 'std/hash/_sha3/shake.ts')
-rw-r--r-- | std/hash/_sha3/shake.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/std/hash/_sha3/shake.ts b/std/hash/_sha3/shake.ts new file mode 100644 index 000000000..05c699ea5 --- /dev/null +++ b/std/hash/_sha3/shake.ts @@ -0,0 +1,51 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +import { Sponge } from "./sponge.ts"; +import { keccakf } from "./keccakf.ts"; + +/** Shake128 hash */ +export class Shake128 extends Sponge { + /** + * Instantiates a new Shake128 hash + * @param bitsize length of hash in bits + */ + constructor(bitsize: number) { + if (bitsize < 8) { + throw new Error("shake128: `bitsize` too small"); + } + + if (bitsize % 8 !== 0) { + throw new Error("shake128: `bitsize` must be multiple of 8"); + } + + super({ + bitsize: bitsize, + rate: 168, + dsbyte: 0x1f, + permutator: keccakf, + }); + } +} + +/** + * Instantiates a new Shake256 hash + * @param bitsize length of hash in bits + */ +export class Shake256 extends Sponge { + constructor(bitsize: number) { + if (bitsize < 8) { + throw new Error("shake256: `bitsize` too small"); + } + + if (bitsize % 8 !== 0) { + throw new Error("shake256: `bitsize` must be multiple of 8"); + } + + super({ + bitsize: bitsize, + rate: 136, + dsbyte: 0x1f, + permutator: keccakf, + }); + } +} |