UNPKG

@hpke/dhkem-x448

Version:

A Hybrid Public Key Encryption (HPKE) module extension for X448

20 lines (19 loc) 684 B
import { hmac } from "@noble/hashes/hmac"; import { sha512 } from "@noble/hashes/sha512"; import { HkdfSha512Native } from "@hpke/common"; export class HkdfSha512 extends HkdfSha512Native { async extract(salt, ikm) { await this._setup(); if (salt.byteLength === 0) { salt = new ArrayBuffer(this.hashSize); } if (salt.byteLength !== this.hashSize) { return hmac(sha512, new Uint8Array(salt), new Uint8Array(ikm)) .buffer; } const key = await this._api.importKey("raw", salt, this.algHash, false, [ "sign", ]); return await this._api.sign("HMAC", key, ikm); } }