-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
54 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
// @ts-ignore: for "npm:" | ||
import { secp256k1 } from "npm:@noble/[email protected]/secp256k1"; | ||
|
||
import type { KemPrimitives } from "../../../src/interfaces/kemPrimitives.ts"; | ||
import type { KdfInterface } from "../../../src/interfaces/kdfInterface.ts"; | ||
import type { KemInterface } from "../../../src/interfaces/kemInterface.ts"; | ||
import type { KemPrimitives } from "../../interfaces/kemPrimitives.ts"; | ||
import type { KdfInterface } from "../../interfaces/kdfInterface.ts"; | ||
|
||
import { Algorithm } from "../../../src/algorithm.ts"; | ||
import { KemId } from "../../../src/identifiers.ts"; | ||
import { Algorithm } from "../../algorithm.ts"; | ||
import { | ||
KEM_USAGES, | ||
LABEL_DKP_PRK, | ||
LABEL_SK, | ||
} from "../../../src/interfaces/kemPrimitives.ts"; | ||
import { XCryptoKey } from "../../../src/xCryptoKey.ts"; | ||
import { HkdfSha256 } from "../../../src/kdfs/hkdfSha256.ts"; | ||
import { Dhkem } from "../../../src/kems/dhkem.ts"; | ||
} from "../../interfaces/kemPrimitives.ts"; | ||
import { XCryptoKey } from "../../xCryptoKey.ts"; | ||
|
||
import { EMPTY } from "../../../src/consts.ts"; | ||
import { EMPTY } from "../../consts.ts"; | ||
|
||
const ALG_NAME = "ECDH"; | ||
|
||
class Secp256k1 extends Algorithm implements KemPrimitives { | ||
export class Secp256k1 extends Algorithm implements KemPrimitives { | ||
private _hkdf: KdfInterface; | ||
private _nPk: number; | ||
private _nSk: number; | ||
|
@@ -142,41 +138,3 @@ class Secp256k1 extends Algorithm implements KemPrimitives { | |
}); | ||
} | ||
} | ||
|
||
/** | ||
* The DHKEM(secp256k1, HKDF-SHA256). | ||
* | ||
* This class is implemented using | ||
* {@link https://github.com/paulmillr/noble-curves | @noble/curves}. | ||
* | ||
* The public keys are assumed to be compressed. | ||
* | ||
* The instance of this class can be specified to the | ||
* {@link https://deno.land/x/hpke/core/mod.ts?s=CipherSuiteParams | CipherSuiteParams} as follows: | ||
* | ||
* @example | ||
* ```ts | ||
* import { KdfId, AeadId, CipherSuite } from "http://deno.land/x/hpke/core/mod.ts"; | ||
* import { DhkemSecp256k1HkdfSha256} from "https://deno.land/x/hpke/x/dhkem-secp256k1/mod.ts"; | ||
* const suite = new CipherSuite({ | ||
* kem: new DhkemSecp256k1HkdfSha256(), | ||
* kdf: KdfId.HkdfSha256, | ||
* aead: AeadId.Aes128Gcm, | ||
* }); | ||
* ``` | ||
* | ||
* @experimental Note that it is experimental and not standardized. | ||
*/ | ||
export class DhkemSecp256k1HkdfSha256 extends Dhkem implements KemInterface { | ||
public readonly id: KemId = KemId.DhkemSecp256k1HkdfSha256; | ||
public readonly secretSize: number = 32; | ||
public readonly encSize: number = 33; | ||
public readonly publicKeySize: number = 33; | ||
public readonly privateKeySize: number = 32; | ||
|
||
constructor() { | ||
const kdf = new HkdfSha256(); | ||
const prim = new Secp256k1(kdf); | ||
super(prim, kdf); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { KemId } from "../identifiers.ts"; | ||
import { HkdfSha256 } from "../kdfs/hkdfSha256.ts"; | ||
import { Dhkem } from "./dhkem.ts"; | ||
import { Secp256k1 } from "./dhkemPrimitives/secp256k1.ts"; | ||
|
||
/** | ||
* The DHKEM(secp256k1, HKDF-SHA256). | ||
* | ||
* This class is implemented using | ||
* {@link https://github.com/paulmillr/noble-curves | @noble/curves}. | ||
* | ||
* The public keys are assumed to be compressed. | ||
* | ||
* The instance of this class can be specified to the | ||
* {@link https://deno.land/x/hpke/core/mod.ts?s=CipherSuiteParams | CipherSuiteParams} as follows: | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* import { KdfId, AeadId, CipherSuite } from "http://deno.land/x/hpke/core/mod.ts"; | ||
* import { DhkemSecp256k1HkdfSha256} from "https://deno.land/x/hpke/x/dhkem-secp256k1/mod.ts"; | ||
* const suite = new CipherSuite({ | ||
* kem: new DhkemSecp256k1HkdfSha256(), | ||
* kdf: KdfId.HkdfSha256, | ||
* aead: AeadId.Aes128Gcm, | ||
* }); | ||
* ``` | ||
* | ||
* @experimental Note that it is experimental and not standardized. | ||
*/ | ||
export class DhkemSecp256k1HkdfSha256 extends Dhkem { | ||
public readonly id: KemId = KemId.DhkemSecp256k1HkdfSha256; | ||
public readonly secretSize: number = 32; | ||
public readonly encSize: number = 33; | ||
public readonly publicKeySize: number = 33; | ||
public readonly privateKeySize: number = 32; | ||
|
||
constructor() { | ||
const kdf = new HkdfSha256(); | ||
const prim = new Secp256k1(kdf); | ||
super(prim, kdf); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { DhkemSecp256k1HkdfSha256 } from "./src/dhkem-secp256k1.ts"; | ||
export { DhkemSecp256k1HkdfSha256 } from "../../src/kems/dhkemSecp256k1.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ | |
}, | ||
"include": [ | ||
"mod.ts", | ||
"src/**/*" | ||
"../../src/kems/dhkemSecp256k1.ts" | ||
] | ||
} |