-
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
9 changed files
with
67 additions
and
41 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
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 |
---|---|---|
|
@@ -4,19 +4,33 @@ import { x25519 } from "npm:@noble/[email protected]/ed25519"; | |
import type { DhkemPrimitives, KdfInterface } from "@hpke/core"; | ||
|
||
import { | ||
base64UrlToBytes, | ||
DeriveKeyPairError, | ||
DeserializeError, | ||
KEM_USAGES, | ||
LABEL_DKP_PRK, | ||
LABEL_SK, | ||
NotSupportedError, | ||
SerializeError, | ||
XCryptoKey, | ||
} from "@hpke/core"; | ||
|
||
const ALG_NAME = "X25519"; | ||
const EMPTY = new Uint8Array(); | ||
// The key usages for KEM. | ||
const KEM_USAGES: KeyUsage[] = ["deriveBits"]; | ||
// b"dkp_prk" deno-fmt-ignore | ||
const LABEL_DKP_PRK: Uint8Array = new Uint8Array([ | ||
100, 107, 112, 95, 112, 114, 107, | ||
]); | ||
// b"sk" | ||
const LABEL_SK: Uint8Array = new Uint8Array([115, 107]); | ||
|
||
function base64UrlToBytes(v: string): Uint8Array { | ||
const base64 = v.replace(/-/g, "+").replace(/_/g, "/"); | ||
const byteString = atob(base64); | ||
const ret = new Uint8Array(byteString.length); | ||
for (let i = 0; i < byteString.length; i++) { | ||
ret[i] = byteString.charCodeAt(i); | ||
} | ||
return ret; | ||
} | ||
|
||
export class X25519 implements DhkemPrimitives { | ||
private _hkdf: KdfInterface; | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ import { hmac } from "npm:@noble/[email protected]/hmac"; | |
// @ts-ignore: for "npm:" | ||
import { sha512 } from "npm:@noble/[email protected]/sha512"; | ||
|
||
import { HkdfSha512Native } from "@hpke/core"; | ||
import { HkdfSha512 as HkdfSha512Native } from "@hpke/core"; | ||
|
||
export class HkdfSha512 extends HkdfSha512Native { | ||
public override async extract( | ||
|
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 |
---|---|---|
|
@@ -4,19 +4,33 @@ import { x448 } from "npm:@noble/[email protected]/ed448"; | |
import type { DhkemPrimitives, KdfInterface } from "@hpke/core"; | ||
|
||
import { | ||
base64UrlToBytes, | ||
DeriveKeyPairError, | ||
DeserializeError, | ||
KEM_USAGES, | ||
LABEL_DKP_PRK, | ||
LABEL_SK, | ||
NotSupportedError, | ||
SerializeError, | ||
XCryptoKey, | ||
} from "@hpke/core"; | ||
|
||
const ALG_NAME = "X448"; | ||
const EMPTY = new Uint8Array(); | ||
// The key usages for KEM. | ||
const KEM_USAGES: KeyUsage[] = ["deriveBits"]; | ||
// b"dkp_prk" deno-fmt-ignore | ||
const LABEL_DKP_PRK: Uint8Array = new Uint8Array([ | ||
100, 107, 112, 95, 112, 114, 107, | ||
]); | ||
// b"sk" | ||
const LABEL_SK: Uint8Array = new Uint8Array([115, 107]); | ||
|
||
function base64UrlToBytes(v: string): Uint8Array { | ||
const base64 = v.replace(/-/g, "+").replace(/_/g, "/"); | ||
const byteString = atob(base64); | ||
const ret = new Uint8Array(byteString.length); | ||
for (let i = 0; i < byteString.length; i++) { | ||
ret[i] = byteString.charCodeAt(i); | ||
} | ||
return ret; | ||
} | ||
|
||
export class X448 implements DhkemPrimitives { | ||
private _hkdf: KdfInterface; | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ import { hmac } from "npm:@noble/[email protected]/hmac"; | |
// @ts-ignore: for "npm:" | ||
import { sha384 } from "npm:@noble/[email protected]/sha512"; | ||
|
||
import { HkdfSha384Native } from "@hpke/core"; | ||
import { HkdfSha384 as HkdfSha384Native } from "@hpke/core"; | ||
|
||
export class HkdfSha384 extends HkdfSha384Native { | ||
public override async extract( | ||
|
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
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