Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename KemPrimitives to DhkemPrimitives. #252

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const LABEL_DKP_PRK = new Uint8Array([100, 107, 112, 95, 112, 114, 107]);
// b"sk"
export const LABEL_SK = new Uint8Array([115, 107]);

export interface KemPrimitives {
export interface DhkemPrimitives {
serializePublicKey(key: CryptoKey): Promise<ArrayBuffer>;

deserializePublicKey(key: ArrayBuffer): Promise<CryptoKey>;
Expand All @@ -22,11 +22,13 @@ export interface KemPrimitives {
isPublic: boolean,
): Promise<CryptoKey>;

derivePublicKey(key: CryptoKey): Promise<CryptoKey>;

generateKeyPair(): Promise<CryptoKeyPair>;

deriveKeyPair(ikm: ArrayBuffer): Promise<CryptoKeyPair>;

// DHKEM-specific function.
derivePublicKey(key: CryptoKey): Promise<CryptoKey>;

// DHKEM-specific function.
dh(sk: CryptoKey, pk: CryptoKey): Promise<ArrayBuffer>;
}
6 changes: 3 additions & 3 deletions src/kems/dhkem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { KdfInterface } from "../interfaces/kdfInterface.ts";
import type { KemInterface } from "../interfaces/kemInterface.ts";
import type { KemPrimitives } from "../interfaces/kemPrimitives.ts";
import type { DhkemPrimitives } from "../interfaces/dhkemPrimitives.ts";
import type { SenderContextParams } from "../interfaces/senderContextParams.ts";
import type { RecipientContextParams } from "../interfaces/recipientContextParams.ts";

Expand All @@ -27,10 +27,10 @@ export class Dhkem implements KemInterface {
public readonly encSize: number = 0;
public readonly publicKeySize: number = 0;
public readonly privateKeySize: number = 0;
protected _prim: KemPrimitives;
protected _prim: DhkemPrimitives;
protected _kdf: KdfInterface;

constructor(id: KemId, prim: KemPrimitives, kdf: KdfInterface) {
constructor(id: KemId, prim: DhkemPrimitives, kdf: KdfInterface) {
this.id = id;
this._prim = prim;
this._kdf = kdf;
Expand Down
6 changes: 3 additions & 3 deletions src/kems/dhkemPrimitives/ec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { KemPrimitives } from "../../interfaces/kemPrimitives.ts";
import type { DhkemPrimitives } from "../../interfaces/dhkemPrimitives.ts";
import type { KdfInterface } from "../../interfaces/kdfInterface.ts";

import { NativeAlgorithm } from "../../algorithm.ts";
import { EMPTY } from "../../consts.ts";
import * as errors from "../../errors.ts";
import { KemId } from "../../identifiers.ts";
import { KEM_USAGES, LABEL_DKP_PRK } from "../../interfaces/kemPrimitives.ts";
import { KEM_USAGES, LABEL_DKP_PRK } from "../../interfaces/dhkemPrimitives.ts";
import { Bignum } from "../../utils/bignum.ts";
import { base64UrlToBytes, i2Osp } from "../../utils/misc.ts";

Expand Down Expand Up @@ -71,7 +71,7 @@ const PKCS8_ALG_ID_P_521 = new Uint8Array([
4, 66,
]);

export class Ec extends NativeAlgorithm implements KemPrimitives {
export class Ec extends NativeAlgorithm implements DhkemPrimitives {
private _hkdf: KdfInterface;
private _alg: EcKeyGenParams;
private _nPk: number;
Expand Down
6 changes: 3 additions & 3 deletions src/kems/dhkemPrimitives/secp256k1.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore: for "npm:"
import { secp256k1 } from "npm:@noble/[email protected]/secp256k1";

import type { KemPrimitives } from "../../interfaces/kemPrimitives.ts";
import type { DhkemPrimitives } from "../../interfaces/dhkemPrimitives.ts";
import type { KdfInterface } from "../../interfaces/kdfInterface.ts";

import { EMPTY } from "../../consts.ts";
Expand All @@ -10,12 +10,12 @@ import {
KEM_USAGES,
LABEL_DKP_PRK,
LABEL_SK,
} from "../../interfaces/kemPrimitives.ts";
} from "../../interfaces/dhkemPrimitives.ts";
import { XCryptoKey } from "../../xCryptoKey.ts";

const ALG_NAME = "ECDH";

export class Secp256k1 implements KemPrimitives {
export class Secp256k1 implements DhkemPrimitives {
private _hkdf: KdfInterface;
private _nPk: number;
private _nSk: number;
Expand Down
6 changes: 3 additions & 3 deletions src/kems/dhkemPrimitives/x25519.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore: for "npm:"
import { ed25519, x25519 } from "npm:@noble/[email protected]/ed25519";

import type { KemPrimitives } from "../../interfaces/kemPrimitives.ts";
import type { DhkemPrimitives } from "../../interfaces/dhkemPrimitives.ts";
import type { KdfInterface } from "../../interfaces/kdfInterface.ts";

import * as consts from "../../consts.ts";
Expand All @@ -10,13 +10,13 @@ import {
KEM_USAGES,
LABEL_DKP_PRK,
LABEL_SK,
} from "../../interfaces/kemPrimitives.ts";
} from "../../interfaces/dhkemPrimitives.ts";
import { base64UrlToBytes } from "../../utils/misc.ts";
import { XCryptoKey } from "../../xCryptoKey.ts";

const ALG_NAME = "X25519";

export class X25519 implements KemPrimitives {
export class X25519 implements DhkemPrimitives {
private _hkdf: KdfInterface;
private _nPk: number;
private _nSk: number;
Expand Down
6 changes: 3 additions & 3 deletions src/kems/dhkemPrimitives/x448.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore: for "npm:"
import { ed448, x448 } from "npm:@noble/[email protected]/ed448";

import type { KemPrimitives } from "../../interfaces/kemPrimitives.ts";
import type { DhkemPrimitives } from "../../interfaces/dhkemPrimitives.ts";
import type { KdfInterface } from "../../interfaces/kdfInterface.ts";

import * as consts from "../../consts.ts";
Expand All @@ -10,13 +10,13 @@ import {
KEM_USAGES,
LABEL_DKP_PRK,
LABEL_SK,
} from "../../interfaces/kemPrimitives.ts";
} from "../../interfaces/dhkemPrimitives.ts";
import { base64UrlToBytes } from "../../utils/misc.ts";
import { XCryptoKey } from "../../xCryptoKey.ts";

const ALG_NAME = "X448";

export class X448 implements KemPrimitives {
export class X448 implements DhkemPrimitives {
private _hkdf: KdfInterface;
private _nPk: number;
private _nSk: number;
Expand Down
Loading