Skip to content

Commit 6f73711

Browse files
add loadWasm in pbkdf2 and update readme
1 parent 51c9b43 commit 6f73711

File tree

7 files changed

+26
-8
lines changed

7 files changed

+26
-8
lines changed

README-CN.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ yarn add @originjs/crypto-js-wasm
3939

4040
在使用各算法前需调用一次对应的`loadWasm()`,或调用`loadAllWasm()`以加载所有算法的WebAssembly文件。
4141

42-
43-
4442
```javascript
4543
import CryptoJSW from 'crypto-js-wasm';
4644

@@ -59,6 +57,10 @@ CryptoJSW.SHA256.loadWasm().then(() => {
5957
})
6058
```
6159

60+
需要注意的是,`HMAC` 没有`loadWasm`,因为如果要使用`HMAC`,必须指定哈希(例如`HmacSHA1`)。
61+
62+
同时, `pbkdf2` 中的 `loadWasm` 实现是调用了 `SHA1.loadWasm` ,这是因为 `SHA1``pbkdf2` 的默认哈希算法。 如果指定了另一个哈希算法,则应分别调用该哈希算法对应的 `loadWasm``evpkdf`/`MD5` 的情况与之类似, `MD5``evpkdf` 的默认哈希算法。
63+
6264

6365

6466
**目前可用的算法**

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ yarn add @originjs/crypto-js-wasm
3939

4040
Note that the async function `loadWasm()` should be called once (and once only!) for each algorithm that will be used, unless `loadAllWasm()` is called at the very beginning.
4141

42-
43-
4442
```javascript
4543
import CryptoJSW from 'crypto-js-wasm';
4644

@@ -59,6 +57,10 @@ CryptoJSW.SHA256.loadWasm().then(() => {
5957
})
6058
```
6159

60+
Please note that `HMAC` does not have a `loadWasm`, as a hasher must be specified if you want to use `HMAC` (i.e. `HmacSHA1`).
61+
62+
And the `loadWasm` in `pbkdf2` only calls `SHA1.loadWasm` as `SHA1` is the default hasher of `pbkdf2`. If you specified another hasher, the corresponding `loadWasm` of the hasher should be called repectly. Same case in `evpkdf`/`MD5` as `MD5` is the default hasher of `evpkdf`.
63+
6264

6365

6466
**Available standards**

src/algo/pbkdf2/pbkdf2.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ export class PBKDF2Algo extends Base {
4242
);
4343
}
4444

45+
/**
46+
* SHA1 is the default hasher of pbkdf2.
47+
* With another hasher configured, user should call the corresponding loadWasm of the configured hasher.
48+
*
49+
* @returns {Promise<null>}
50+
*/
51+
static async loadWasm() {
52+
return SHA1Algo.loadWasm();
53+
}
54+
55+
async loadWasm() {
56+
return PBKDF2Algo.loadWasm();
57+
}
58+
4559
/**
4660
* Computes the Password-Based Key Derivation Function 2.
4761
*

test/hmac.sha224.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import C from '../src/index';
22

33
beforeAll(async () => {
4-
await C.SHA224.loadWasm();
4+
await C.HmacSHA224.loadWasm();
55
});
66

77
describe('algo-hmac-sha224-test', () => {

test/hmac.sha256.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import C from '../src/index';
22

33
beforeAll(async () => {
4-
await C.SHA256.loadWasm();
4+
await C.HmacSHA256.loadWasm();
55
});
66

77
describe('algo-hmac-sha256-test', () => {

test/hmac.sha384.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import C from '../src/index';
22

33
beforeAll(async () => {
4-
await C.SHA384.loadWasm();
4+
await C.HmacSHA384.loadWasm();
55
});
66

77
describe('algo-hmac-sha384-test', () => {

test/hmac.sha512.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import C from '../src/index';
22

33
beforeAll(async () => {
4-
await C.SHA512.loadWasm();
4+
await C.HmacSHA512.loadWasm();
55
});
66

77
describe('algo-hmac-sha512-test', () => {

0 commit comments

Comments
 (0)