Skip to content

Commit

Permalink
add hash sha2 javascript api layer (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml authored Mar 19, 2023
1 parent 2b5fd3d commit 6ac557b
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 53 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ https://en.wikipedia.org/wiki/Proxy_re-encryption
### Cryptographic primitives and utilities

```
ecc_hash_sha256
ecc_hash_sha512
ecc_kdf_argon2id
```

Expand Down
5 changes: 4 additions & 1 deletion bindings/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,8 @@ https://en.wikipedia.org/wiki/Proxy_re-encryption
### Cryptographic primitives and utilities

```
ecc_kdf_argon2id
hash_sha256
hash_sha512
kdf_argon2id
```
135 changes: 101 additions & 34 deletions bindings/js/dist/ecc.dev.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindings/js/dist/ecc.min.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions bindings/js/dist/hash.d.ts
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;
1 change: 1 addition & 0 deletions bindings/js/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const libecc_module: (libecc_module: any) => Promise<any>;
export * from "./util.js";
export * from "./hash.js";
export * from "./kdf.js";
export * from "./oprf.js";
export * from "./opaque.js";
Expand Down
11 changes: 11 additions & 0 deletions bindings/js/dist/kdf.d.ts
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;
52 changes: 52 additions & 0 deletions bindings/js/hash.js
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;
}
Loading

0 comments on commit 6ac557b

Please sign in to comment.