-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add hash sha2 javascript api layer (#103)
- Loading branch information
Showing
11 changed files
with
212 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* 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: Uint8Array): Uint8Array; | ||
/** | ||
* 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: Uint8Array): Uint8Array; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* See https://datatracker.ietf.org/doc/html/rfc9106 | ||
* | ||
* @param {Uint8Array} passphrase | ||
* @param {Uint8Array} salt, must be of size ecc_kdf_argon2id_SALTIZE | ||
* @param {number} memorySize amount of memory (in kibibytes) to use | ||
* @param {number} iterations number of passes | ||
* @param {number} len intended output length | ||
* @return {Uint8Array} the result or null if the computation didn't complete | ||
*/ | ||
export function kdf_argon2id(passphrase: Uint8Array, salt: Uint8Array, memorySize: number, iterations: number, len: number): Uint8Array; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |
Oops, something went wrong.