forked from openpgpjs/openpgpjs
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move lower-level code away from entry crypto module
- Loading branch information
Showing
12 changed files
with
124 additions
and
97 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
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,5 @@ | ||
import * as kem from './kem/index'; | ||
|
||
export { | ||
kem | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { generate, encrypt, decrypt } from './kem'; |
35 changes: 28 additions & 7 deletions
35
src/crypto/public_key/pqc/index.js → ...crypto/public_key/post_quantum/kem/kem.js
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
16 changes: 11 additions & 5 deletions
16
src/crypto/public_key/pqc/kem_ml.js → ...pto/public_key/post_quantum/kem/ml_kem.js
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,37 +1,43 @@ | ||
import enums from '../../../enums'; | ||
import enums from '../../../../enums'; | ||
|
||
export async function generate(algo) { | ||
switch (algo) { | ||
case enums.publicKey.kem_x25519: { | ||
case enums.publicKey.pqc_mlkem_x25519: { | ||
const { Kyber768 } = await import('crystals-kyber-js'); | ||
const kyberInstance = new Kyber768(); | ||
const [encapsulationKey, decapsulationKey] = await kyberInstance.generateKeyPair(); | ||
|
||
return { encapsulationKey, decapsulationKey }; | ||
return { mlkemPublicKey: encapsulationKey, mlkemSecretKey: decapsulationKey }; | ||
} | ||
default: | ||
throw new Error('Unsupported KEM algorithm'); | ||
} | ||
} | ||
|
||
export async function encaps(algo, mlkemRecipientPublicKey) { | ||
switch (algo) { | ||
case enums.publicKey.kem_x25519: { | ||
case enums.publicKey.pqc_mlkem_x25519: { | ||
const { Kyber768 } = await import('crystals-kyber-js'); | ||
const kyberInstance = new Kyber768(); | ||
const [mlkemCipherText, mlkemKeyShare] = await kyberInstance.encap(mlkemRecipientPublicKey); | ||
|
||
return { mlkemCipherText, mlkemKeyShare }; | ||
} | ||
default: | ||
throw new Error('Unsupported KEM algorithm'); | ||
} | ||
} | ||
|
||
export async function decaps(algo, mlkemCipherText, mlkemSecretKey) { | ||
switch (algo) { | ||
case enums.publicKey.kem_x25519: { | ||
case enums.publicKey.pqc_mlkem_x25519: { | ||
const { Kyber768 } = await import('crystals-kyber-js'); | ||
const kyberInstance = new Kyber768(); | ||
const mlkemKeyShare = await kyberInstance.decap(mlkemCipherText, mlkemSecretKey); | ||
|
||
return mlkemKeyShare; | ||
} | ||
default: | ||
throw new Error('Unsupported KEM algorithm'); | ||
} | ||
} |
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
Oops, something went wrong.