UNPKG

@hpke/dhkem-x25519

Version:

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

71 lines (70 loc) 2.03 kB
import { Dhkem, KemId } from "@hpke/common"; import { HkdfSha256 } from "./hkdfSha256.js"; import { X25519 } from "./x25519.js"; /** * The DHKEM(X25519, HKDF-SHA256) for HPKE KEM implementing {@link KemInterface}. * * This class is implemented using * {@link https://github.com/paulmillr/noble-curves | @noble/curves}. * * The instance of this class can be specified to the * {@link https://jsr.io/@hpke/core/doc/~/CipherSuiteParams | CipherSuiteParams} as follows: * * @example Use with `@hpke/core`: * * ```ts * import { * Aes128Gcm, * CipherSuite, * HkdfSha256, * } from "@hpke/core"; * import { DhkemX25519HkdfSha256 } from "@hpke/dhkem-x25519"; * * const suite = new CipherSuite({ * kem: new DhkemX25519HkdfSha256(), * kdf: new HkdfSha256(), * aead: new Aes128Gcm(), * }); * ``` */ export class DhkemX25519HkdfSha256 extends Dhkem { constructor() { const kdf = new HkdfSha256(); super(KemId.DhkemX25519HkdfSha256, new X25519(kdf), kdf); /** KemId.DhkemX25519HkdfSha256 (0x0020) */ Object.defineProperty(this, "id", { enumerable: true, configurable: true, writable: true, value: KemId.DhkemX25519HkdfSha256 }); /** 32 */ Object.defineProperty(this, "secretSize", { enumerable: true, configurable: true, writable: true, value: 32 }); /** 32 */ Object.defineProperty(this, "encSize", { enumerable: true, configurable: true, writable: true, value: 32 }); /** 32 */ Object.defineProperty(this, "publicKeySize", { enumerable: true, configurable: true, writable: true, value: 32 }); /** 32 */ Object.defineProperty(this, "privateKeySize", { enumerable: true, configurable: true, writable: true, value: 32 }); } }