@hpke/core
Version:
A Hybrid Public Key Encryption (HPKE) core module for various JavaScript runtimes
253 lines (252 loc) • 8.61 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "@hpke/common", "./cipherSuiteNative.js", "./kems/dhkemNative.js"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HkdfSha512 = exports.HkdfSha384 = exports.HkdfSha256 = exports.DhkemP521HkdfSha512 = exports.DhkemP384HkdfSha384 = exports.DhkemP256HkdfSha256 = exports.CipherSuite = void 0;
const common_1 = require("@hpke/common");
const cipherSuiteNative_js_1 = require("./cipherSuiteNative.js");
const dhkemNative_js_1 = require("./kems/dhkemNative.js");
/**
* The Hybrid Public Key Encryption (HPKE) ciphersuite,
* which is implemented using only
* {@link https://www.w3.org/TR/WebCryptoAPI/ | Web Cryptography API}.
*
* This class is the same as
* {@link https://jsr.io/@hpke/core/doc/~/CipherSuiteNative | @hpke/core#CipherSuiteNative} as follows:
* which supports only the ciphersuites that can be implemented on the native
* {@link https://www.w3.org/TR/WebCryptoAPI/ | Web Cryptography API}.
* Therefore, the following cryptographic algorithms are not supported for now:
* - `DHKEM(X25519, HKDF-SHA256)`
* - `DHKEM(X448, HKDF-SHA512)`
* - `ChaCha20Poly1305`
*
* In addtion, the HKDF functions contained in this `CipherSuiteNative`
* class can only derive keys of the same length as the `hashSize`.
*
* If you want to use the unsupported cryptographic algorithms
* above or derive keys longer than the `hashSize`,
* please use {@link https://jsr.io/@hpke/hpke-js/doc/~/CipherSuite | hpke-js#CipherSuite}.
*
* This class provides following functions:
*
* - Creates encryption contexts both for senders and recipients.
* - {@link createSenderContext}
* - {@link createRecipientContext}
* - Provides single-shot encryption API.
* - {@link seal}
* - {@link open}
*
* The calling of the constructor of this class is the starting
* point for HPKE operations for both senders and recipients.
*
* @example Use only ciphersuites supported by Web Cryptography API.
*
* ```ts
* import {
* Aes128Gcm,
* DhkemP256HkdfSha256,
* HkdfSha256,
* CipherSuite,
* } from "@hpke/core";
*
* const suite = new CipherSuite({
* kem: new DhkemP256HkdfSha256(),
* kdf: new HkdfSha256(),
* aead: new Aes128Gcm(),
* });
* ```
*
* @example Use a ciphersuite which is currently not supported by Web Cryptography API.
*
* ```ts
* import { Aes128Gcm, HkdfSha256, CipherSuite } from "@hpke/core";
* import { DhkemX25519HkdfSha256 } from "@hpke/dhkem-x25519";
* const suite = new CipherSuite({
* kem: new DhkemX25519HkdfSha256(),
* kdf: new HkdfSha256(),
* aead: new Aes128Gcm(),
* });
* ```
*/
class CipherSuite extends cipherSuiteNative_js_1.CipherSuiteNative {
}
exports.CipherSuite = CipherSuite;
/**
* The DHKEM(P-256, HKDF-SHA256) for HPKE KEM implementing {@link KemInterface}.
*
* When using `@hpke/core`, the instance of this class must be specified
* to the `kem` parameter of {@link CipherSuiteParams} instead of `KemId.DhkemP256HkdfSha256`
* as follows:
*
* @example
*
* ```ts
* import {
* Aes128Gcm,
* CipherSuite,
* DhkemP256HkdfSha256,
* HkdfSha256,
* } from "@hpke/core";
*
* const suite = new CipherSuite({
* kem: new DhkemP256HkdfSha256(),
* kdf: new HkdfSha256(),
* aead: new Aes128Gcm(),
* });
* ```
*/
class DhkemP256HkdfSha256 extends dhkemNative_js_1.DhkemP256HkdfSha256Native {
}
exports.DhkemP256HkdfSha256 = DhkemP256HkdfSha256;
/**
* The DHKEM(P-384, HKDF-SHA384) for HPKE KEM implementing {@link KemInterface}.
*
* When using `@hpke/core`, the instance of this class must be specified
* to the `kem` parameter of {@link CipherSuiteParams} instead of `KemId.DhkemP384HkdfSha384`
* as follows:
*
* @example
*
* ```ts
* import {
* Aes128Gcm,
* CipherSuite,
* DhkemP384HkdfSha384,
* HkdfSha384,
* } from "@hpke/core";
*
* const suite = new CipherSuite({
* kem: new DhkemP384HkdfSha384(),
* kdf: new HkdfSha384(),
* aead: new Aes128Gcm(),
* });
* ```
*/
class DhkemP384HkdfSha384 extends dhkemNative_js_1.DhkemP384HkdfSha384Native {
}
exports.DhkemP384HkdfSha384 = DhkemP384HkdfSha384;
/**
* The DHKEM(P-521, HKDF-SHA512) for HPKE KEM implementing {@link KemInterface}.
*
* When using `@hpke/core`, the instance of this class must be specified
* to the `kem` parameter of {@link CipherSuiteParams} instead of `KemId.DhkemP521HkdfSha512`
* as follows:
*
* @example
*
* ```ts
* import {
* Aes256Gcm,
* CipherSuite,
* DhkemP521HkdfSha512,
* HkdfSha512,
* } from "@hpke/core";
*
* const suite = new CipherSuite({
* kem: new DhkemP521HkdfSha512(),
* kdf: new HkdfSha512(),
* aead: new Aes256Gcm(),
* });
* ```
*/
class DhkemP521HkdfSha512 extends dhkemNative_js_1.DhkemP521HkdfSha512Native {
}
exports.DhkemP521HkdfSha512 = DhkemP521HkdfSha512;
/**
* The HKDF-SHA256 for HPKE KDF implementing {@link KdfInterface}.
*
* When using `@hpke/core`, the instance of this class must be specified
* to the `kem` parameter of {@link CipherSuiteParams} instead of `KdfId.HkdfSha256`.
*
* The KDF class can only derive keys of the same length as the `hashSize`.
* If you want to derive keys longer than the `hashSize`,
* please use {@link https://jsr.io/@hpke/hpke-js/doc/~/CipherSuite | hpke-js#CipherSuite}.
*
* @example
*
* ```ts
* import {
* Aes128Gcm,
* CipherSuite,
* DhkemP256HkdfSha256,
* HkdfSha256,
* } from "@hpke/core";
*
* const suite = new CipherSuite({
* kem: new DhkemP256HkdfSha256(),
* kdf: new HkdfSha256(),
* aead: new Aes128Gcm(),
* });
* ```
*/
class HkdfSha256 extends common_1.HkdfSha256Native {
}
exports.HkdfSha256 = HkdfSha256;
/**
* The HKDF-SHA384 for HPKE KDF implementing {@link KdfInterface}.
*
* When using `@hpke/core`, the instance of this class must be specified
* to the `kem` parameter of {@link CipherSuiteParams} instead of `KdfId.HkdfSha384`.
*
* The KDF class can only derive keys of the same length as the `hashSize`.
* If you want to derive keys longer than the `hashSize`,
* please use {@link https://jsr.io/@hpke/hpke-js/doc/~/CipherSuite | hpke-js#CipherSuite}.
*
* @example
*
* ```ts
* import {
* Aes128Gcm,
* CipherSuite,
* DhkemP384HkdfSha384,
* HkdfSha384,
* } from "@hpke/core";
*
* const suite = new CipherSuite({
* kem: new DhkemP384HkdfSha384(),
* kdf: new HkdfSha384(),
* aead: new Aes128Gcm(),
* });
* ```
*/
class HkdfSha384 extends common_1.HkdfSha384Native {
}
exports.HkdfSha384 = HkdfSha384;
/**
* The HKDF-SHA512 for HPKE KDF implementing {@link KdfInterface}.
*
* When using `@hpke/core`, the instance of this class must be specified
* to the `kem` parameter of {@link CipherSuiteParams} instead of `KdfId.HkdfSha512`.
*
* The KDF class can only derive keys of the same length as the `hashSize`.
* If you want to derive keys longer than the `hashSize`,
* please use {@link https://jsr.io/@hpke/hpke-js/doc/~/CipherSuite | hpke-js#CipherSuite}.
*
* @example
*
* ```ts
* import {
* Aes256Gcm,
* CipherSuite,
* DhkemP521HkdfSha512,
* HkdfSha512,
* } from "@hpke/core";
*
* const suite = new CipherSuite({
* kem: new DhkemP521HkdfSha512(),
* kdf: new HkdfSha512(),
* aead: new Aes256Gcm(),
* });
* ```
*/
class HkdfSha512 extends common_1.HkdfSha512Native {
}
exports.HkdfSha512 = HkdfSha512;
});