-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash.js
52 lines (45 loc) · 1016 Bytes
/
hash.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
/*
* Copyright (c) 2023, Alden Torres
*
* Licensed under the terms of the MIT license.
* Copy of the license at https://opensource.org/licenses/MIT
*/
import {
libecc,
} from "./util.js";
/**
* Computes the SHA-256 of a given input.
*
* See https://en.wikipedia.org/wiki/SHA-2
*
* @param {Uint8Array} input the input message
* @return {Uint8Array} the SHA-256 of the input
*/
export function hash_sha256(
input,
) {
let digest = new Uint8Array(libecc.ecc_hash_sha256_HASHSIZE);
libecc.ecc_hash_sha256(
digest,
input, input.length,
);
return digest;
}
/**
* Computes the SHA-512 of a given input.
*
* See https://en.wikipedia.org/wiki/SHA-2
*
* @param {Uint8Array} input the input message
* @return {Uint8Array} the SHA-512 of the input
*/
export function hash_sha512(
input,
) {
let digest = new Uint8Array(libecc.ecc_hash_sha512_HASHSIZE);
libecc.ecc_hash_sha512(
digest,
input, input.length,
);
return digest;
}