summaryrefslogtreecommitdiff
path: root/packages/taler-util/src/kdf.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-10-18 21:48:22 +0200
committerFlorian Dold <florian@dold.me>2021-10-18 21:48:45 +0200
commit269022a526b670d602ca146f4df02850983bb72e (patch)
treee0a66e8b15ef305c99274c76964a119d0d9512ba /packages/taler-util/src/kdf.ts
parent3a69f27412782872c1264e8a4dd1be13d57a8a80 (diff)
downloadwallet-core-269022a526b670d602ca146f4df02850983bb72e.tar.gz
wallet-core-269022a526b670d602ca146f4df02850983bb72e.tar.bz2
wallet-core-269022a526b670d602ca146f4df02850983bb72e.zip
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.ts19
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);