Skip to content

Commit 29ebf07

Browse files
authored
Merge pull request #332 from dajiaji/make-dhkem-x25519-be-ready-for-jsr
Move dhkem-x25519 impl to x/dhkem-x25519.
2 parents 7beac6d + 2c42735 commit 29ebf07

23 files changed

+122
-72
lines changed

core/mod.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export type { AeadEncryptionContext } from "./src/interfaces/aeadEncryptionContext.ts";
22
export type { AeadInterface } from "./src/interfaces/aeadInterface.ts";
33
export type { CipherSuiteParams } from "./src/interfaces/cipherSuiteParams.ts";
4+
export type { DhkemPrimitives } from "./src/interfaces/dhkemPrimitives.ts";
5+
export type { DhkemInterface } from "./src/interfaces/dhkemInterface.ts";
46
export type {
57
EncryptionContext,
68
RecipientContext,
@@ -13,11 +15,31 @@ export type { RecipientContextParams } from "./src/interfaces/recipientContextPa
1315
export type { CipherSuiteSealResponse } from "./src/interfaces/responses.ts";
1416
export type { SenderContextParams } from "./src/interfaces/senderContextParams.ts";
1517

18+
// export {
19+
// KEM_USAGES,
20+
// LABEL_DKP_PRK,
21+
// LABEL_SK,
22+
// } from "./src/interfaces/dhkemPrimitives.ts";
23+
// export { SUITE_ID_HEADER_KEM } from "./src/interfaces/kemInterface.ts";
24+
1625
export { Aes128Gcm, Aes256Gcm } from "./src/aeads/aesGcm.ts";
1726
export { ExportOnly } from "./src/aeads/exportOnly.ts";
27+
export {
28+
HkdfSha256Native,
29+
HkdfSha384Native,
30+
HkdfSha512Native,
31+
} from "./src/kdfs/hkdf.ts";
32+
export { Dhkem } from "./src/kems/dhkem.ts";
33+
export {
34+
base64UrlToBytes,
35+
concat,
36+
i2Osp,
37+
isCryptoKeyPair,
38+
} from "./src/utils/misc.ts";
39+
40+
export { INPUT_LENGTH_LIMIT } from "./src/consts.ts";
1841
export * from "./src/errors.ts";
1942
export { AeadId, KdfId, KemId } from "./src/identifiers.ts";
20-
2143
export {
2244
CipherSuite,
2345
DhkemP256HkdfSha256,
@@ -27,3 +49,4 @@ export {
2749
HkdfSha384,
2850
HkdfSha512,
2951
} from "./src/native.ts";
52+
export { XCryptoKey } from "./src/xCryptoKey.ts";
File renamed without changes.

mod_core.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
export type { AeadEncryptionContext } from "./core/src/interfaces/aeadEncryptionContext.ts";
44
export type { AeadInterface } from "./core/src/interfaces/aeadInterface.ts";
55
export type { CipherSuiteParams } from "./core/src/interfaces/cipherSuiteParams.ts";
6+
export type { DhkemInterface } from "./core/src/interfaces/dhkemInterface.ts";
7+
export type { DhkemPrimitives } from "./core/src/interfaces/dhkemPrimitives.ts";
68
export type {
79
EncryptionContext,
810
RecipientContext,
@@ -15,11 +17,31 @@ export type { RecipientContextParams } from "./core/src/interfaces/recipientCont
1517
export type { CipherSuiteSealResponse } from "./core/src/interfaces/responses.ts";
1618
export type { SenderContextParams } from "./core/src/interfaces/senderContextParams.ts";
1719

20+
export {
21+
KEM_USAGES,
22+
LABEL_DKP_PRK,
23+
LABEL_SK,
24+
} from "./core/src/interfaces/dhkemPrimitives.ts";
25+
export { SUITE_ID_HEADER_KEM } from "./core/src/interfaces/kemInterface.ts";
26+
1827
export { Aes128Gcm, Aes256Gcm } from "./core/src/aeads/aesGcm.ts";
1928
export { ExportOnly } from "./core/src/aeads/exportOnly.ts";
29+
export {
30+
HkdfSha256Native,
31+
HkdfSha384Native,
32+
HkdfSha512Native,
33+
} from "./core/src/kdfs/hkdf.ts";
34+
export { Dhkem } from "./core/src/kems/dhkem.ts";
35+
export {
36+
base64UrlToBytes,
37+
concat,
38+
i2Osp,
39+
isCryptoKeyPair,
40+
} from "./core/src/utils/misc.ts";
41+
42+
export { INPUT_LENGTH_LIMIT } from "./core/src/consts.ts";
2043
export * from "./core/src/errors.ts";
2144
export { AeadId, KdfId, KemId } from "./core/src/identifiers.ts";
22-
2345
export {
2446
CipherSuite,
2547
DhkemP256HkdfSha256,
@@ -29,3 +51,4 @@ export {
2951
HkdfSha384,
3052
HkdfSha512,
3153
} from "./core/src/native.ts";
54+
export { XCryptoKey } from "./core/src/xCryptoKey.ts";

src/cipherSuite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { Aes128Gcm, Aes256Gcm } from "../core/src/aeads/aesGcm.ts";
55
import { ExportOnly } from "../core/src/aeads/exportOnly.ts";
66
import { Chacha20Poly1305 } from "../x/chacha20poly1305/src/chacha20Poly1305.ts";
77
import { InvalidParamError } from "../core/src/errors.ts";
8-
import { HkdfSha256 } from "./kdfs/hkdfSha256.ts";
8+
import { HkdfSha256 } from "../x/dhkem-x25519/src/hkdfSha256.ts";
99
import { HkdfSha384 } from "./kdfs/hkdfSha384.ts";
1010
import { HkdfSha512 } from "./kdfs/hkdfSha512.ts";
1111
import { DhkemP256HkdfSha256 } from "./kems/dhkemP256.ts";
1212
import { DhkemP384HkdfSha384 } from "./kems/dhkemP384.ts";
1313
import { DhkemP521HkdfSha512 } from "./kems/dhkemP521.ts";
14-
import { DhkemX25519HkdfSha256 } from "./kems/dhkemX25519.ts";
14+
import { DhkemX25519HkdfSha256 } from "../x/dhkem-x25519/src/dhkemX25519.ts";
1515
import { DhkemX448HkdfSha512 } from "./kems/dhkemX448.ts";
1616
import { AeadId, KdfId, KemId } from "../core/src/identifiers.ts";
1717
import { CipherSuiteNative } from "../core/src/cipherSuiteNative.ts";

src/kems/dhkemP256.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { KemId } from "../../core/src/identifiers.ts";
2-
import { HkdfSha256 } from "../kdfs/hkdfSha256.ts";
2+
import { HkdfSha256 } from "../../x/dhkem-x25519/src/hkdfSha256.ts";
33
import { Dhkem } from "../../core/src/kems/dhkem.ts";
44
import { Ec } from "../../core/src/kems/dhkemPrimitives/ec.ts";
55

src/kems/dhkemPrimitives/secp256k1.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
// @ts-ignore: for "npm:"
22
import { secp256k1 } from "npm:@noble/[email protected]/secp256k1";
33

4-
import type { DhkemPrimitives } from "../../../core/src/interfaces/dhkemPrimitives.ts";
5-
import type { KdfInterface } from "../../../core/src/interfaces/kdfInterface.ts";
4+
import type { DhkemPrimitives, KdfInterface } from "../../../mod_core.ts";
65

7-
import { EMPTY } from "../../../core/src/consts.ts";
86
import {
97
DeriveKeyPairError,
108
DeserializeError,
11-
NotSupportedError,
12-
SerializeError,
13-
} from "../../../core/src/errors.ts";
14-
import {
159
KEM_USAGES,
1610
LABEL_DKP_PRK,
1711
LABEL_SK,
18-
} from "../../../core/src/interfaces/dhkemPrimitives.ts";
19-
import { XCryptoKey } from "../../xCryptoKey.ts";
12+
NotSupportedError,
13+
SerializeError,
14+
XCryptoKey,
15+
} from "../../../mod_core.ts";
2016

2117
const ALG_NAME = "ECDH";
18+
const EMPTY = new Uint8Array();
2219

2320
export class Secp256k1 implements DhkemPrimitives {
2421
private _hkdf: KdfInterface;

src/kems/dhkemPrimitives/x448.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
LABEL_SK,
1818
} from "../../../core/src/interfaces/dhkemPrimitives.ts";
1919
import { base64UrlToBytes } from "../../../core/src/utils/misc.ts";
20-
import { XCryptoKey } from "../../xCryptoKey.ts";
20+
import { XCryptoKey } from "../../../core/src/xCryptoKey.ts";
2121

2222
const ALG_NAME = "X448";
2323

src/kems/dhkemSecp256k1.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { KemId } from "../../core/src/identifiers.ts";
2-
import { HkdfSha256 } from "../kdfs/hkdfSha256.ts";
3-
import { Dhkem } from "../../core/src/kems/dhkem.ts";
1+
import { Dhkem, KemId } from "../../mod_core.ts";
2+
import { HkdfSha256 } from "../../x/dhkem-x25519/mod.ts";
3+
44
import { Secp256k1 } from "./dhkemPrimitives/secp256k1.ts";
55

66
/**

src/kems/hybridkem.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
import type { DhkemInterface } from "../../core/src/interfaces/dhkemInterface.ts";
2-
import type { KdfInterface } from "../../core/src/interfaces/kdfInterface.ts";
3-
import type { KemInterface } from "../../core/src/interfaces/kemInterface.ts";
4-
import type { RecipientContextParams } from "../../core/src/interfaces/recipientContextParams.ts";
5-
import type { SenderContextParams } from "../../core/src/interfaces/senderContextParams.ts";
1+
import type {
2+
DhkemInterface,
3+
KdfInterface,
4+
KemInterface,
5+
RecipientContextParams,
6+
SenderContextParams,
7+
} from "../../mod_core.ts";
68

7-
import { EMPTY } from "../../core/src/consts.ts";
89
import {
10+
concat,
911
DeserializeError,
12+
i2Osp,
1013
InvalidParamError,
11-
NotSupportedError,
12-
SerializeError,
13-
} from "../../core/src/errors.ts";
14-
import { KemId } from "../../core/src/identifiers.ts";
15-
import {
14+
isCryptoKeyPair,
15+
KemId,
1616
LABEL_DKP_PRK,
1717
LABEL_SK,
18-
} from "../../core/src/interfaces/dhkemPrimitives.ts";
19-
import { SUITE_ID_HEADER_KEM } from "../../core/src/interfaces/kemInterface.ts";
20-
import { concat, i2Osp, isCryptoKeyPair } from "../../core/src/utils/misc.ts";
21-
import { XCryptoKey } from "../xCryptoKey.ts";
18+
NotSupportedError,
19+
SerializeError,
20+
SUITE_ID_HEADER_KEM,
21+
XCryptoKey,
22+
} from "../../mod_core.ts";
23+
24+
const EMPTY = new Uint8Array();
2225

2326
export class Hybridkem implements KemInterface {
2427
public readonly id: KemId = KemId.NotAssigned;

src/kems/hybridkemX25519Kyber768.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type { DhkemInterface } from "../../core/src/interfaces/dhkemInterface.ts";
1+
import type { DhkemInterface } from "../../mod_core.ts";
22

3-
import { KemId } from "../../core/src/identifiers.ts";
4-
import { HkdfSha256 } from "../kdfs/hkdfSha256.ts";
3+
import { Dhkem, KemId } from "../../mod_core.ts";
4+
import { HkdfSha256 } from "../../x/dhkem-x25519/src/hkdfSha256.ts";
5+
import { X25519 } from "../../x/dhkem-x25519/src/x25519.ts";
56

6-
import { Dhkem } from "../../core/src/kems/dhkem.ts";
7-
import { X25519 } from "./dhkemPrimitives/x25519.ts";
87
import { Hybridkem } from "./hybridkem.ts";
98
import { KemKyber768 } from "./kemKyber768.ts";
109

0 commit comments

Comments
 (0)