diff options
author | Florian Dold <florian@dold.me> | 2021-10-18 21:48:22 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-10-18 21:48:45 +0200 |
commit | 269022a526b670d602ca146f4df02850983bb72e (patch) | |
tree | e0a66e8b15ef305c99274c76964a119d0d9512ba /packages/taler-util/src/kdf.ts | |
parent | 3a69f27412782872c1264e8a4dd1be13d57a8a80 (diff) | |
download | wallet-core-269022a526b670d602ca146f4df02850983bb72e.tar.xz |
move some more crypto to taler-util package
Diffstat (limited to 'packages/taler-util/src/kdf.ts')
-rw-r--r-- | packages/taler-util/src/kdf.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/taler-util/src/kdf.ts b/packages/taler-util/src/kdf.ts index af4d05035..7710de90c 100644 --- a/packages/taler-util/src/kdf.ts +++ b/packages/taler-util/src/kdf.ts @@ -59,15 +59,30 @@ export function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array { return hmac(sha256, 64, key, message); } +/** + * HMAC-SHA512-SHA256 (see RFC 5869). + */ +export function kdfKw(args: { + outputLength: number; + ikm: Uint8Array; + salt?: Uint8Array; + info?: Uint8Array; +}) { + return kdf(args.outputLength, args.ikm, args.salt, args.info); +} + export function kdf( outputLength: number, ikm: Uint8Array, - salt: Uint8Array, - info: Uint8Array, + salt?: Uint8Array, + info?: Uint8Array, ): Uint8Array { + salt = salt ?? new Uint8Array(64); // extract const prk = hmacSha512(salt, ikm); + info = info ?? new Uint8Array(0); + // expand const N = Math.ceil(outputLength / 32); const output = new Uint8Array(N * 32); |