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.
- Loading branch information
Showing
12 changed files
with
292 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,48 @@ | ||
import util from '../../../util'; | ||
import * as ecdhX from './kem_ecdh_x'; | ||
import * as ml from './kem_ml'; | ||
|
||
const kem = { ecdhX, ml, multiKeyCombine }; | ||
export { | ||
kem | ||
}; | ||
|
||
async function multiKeyCombine(eccKeyShare, eccCipherText, mlkemKeyShare, mlkemCipherText, fixedInfo, outputBits) { | ||
// multiKeyCombine(eccKeyShare, eccCipherText, | ||
// mlkemKeyShare, mlkemCipherText, | ||
// fixedInfo, oBits) | ||
// | ||
// Input: | ||
// eccKeyShare - the ECC key share encoded as an octet string | ||
// eccCipherText - the ECC ciphertext encoded as an octet string | ||
// mlkemKeyShare - the ML-KEM key share encoded as an octet string | ||
// mlkemCipherText - the ML-KEM ciphertext encoded as an octet string | ||
// fixedInfo - the fixed information octet string | ||
// oBits - the size of the output keying material in bits | ||
// | ||
// Constants: | ||
// domSeparation - the UTF-8 encoding of the string | ||
// "OpenPGPCompositeKeyDerivationFunction" | ||
// counter - the fixed 4 byte value 0x00000001 | ||
// customizationString - the UTF-8 encoding of the string "KDF" | ||
const { kmac256 } = await import('@openpgp/noble-hashes/sha3-addons'); | ||
// const { eccKeyShare, eccCiphertext } = await publicKey.pqc.kem.ecdhX(keyAlgo, publicParams.A); | ||
// const { keyShare: mlkemKeyShare, cipherText: mlkemCipherText } = await publicKey.pqc.kem.ml(keyAlgo, publicParams.publicKey); | ||
const eccData = util.concatUint8Array([eccKeyShare, eccCipherText]); // eccKeyShare || eccCipherText | ||
const mlkemData = util.concatUint8Array([mlkemKeyShare, mlkemCipherText]); //mlkemKeyShare || mlkemCipherText | ||
// const fixedInfo = new Uint8Array([keyAlgo]); | ||
const encData = util.concatUint8Array([ | ||
new Uint8Array([1, 0, 0, 0]), | ||
eccData, | ||
mlkemData, | ||
fixedInfo | ||
]); // counter || eccData || mlkemData || fixedInfo | ||
|
||
const mb = kmac256( | ||
util.encodeUTF8('OpenPGPCompositeKeyDerivationFunction'), | ||
encData, | ||
{ personalization: util.encodeUTF8('KDF') } | ||
); | ||
|
||
return mb; | ||
} |
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,40 @@ | ||
import * as ecdhX from '../elliptic/ecdh_x'; | ||
import hash from '../../hash'; | ||
import util from '../../../util'; | ||
import enums from '../../../enums'; | ||
|
||
export async function encaps(eccAlgo, eccRecipientPublicKey) { | ||
switch (eccAlgo) { | ||
case enums.publicKey.kem_x25519: { | ||
const { ephemeralPublicKey: eccCipherText, ephemeralSecretKey } = await ecdhX.generateEphemeralKeyPair(enums.publicKey.x25519); | ||
const X = await ecdhX.getSharedSecret(enums.publicKey.x25519, ephemeralSecretKey, eccRecipientPublicKey); | ||
const eccKeyShare = await hash.sha3_256(util.concatUint8Array([ | ||
X, | ||
eccCipherText, | ||
eccRecipientPublicKey | ||
])); | ||
return { | ||
eccCipherText, | ||
eccKeyShare | ||
}; | ||
} | ||
default: | ||
throw new Error('Unsupported KEM algorithm'); | ||
} | ||
} | ||
|
||
export async function decaps(eccAlgo, eccCipherText, eccSecretKey, eccPublicKey) { | ||
switch (eccAlgo) { | ||
case enums.publicKey.kem_x25519: { | ||
const X = await ecdhX.getSharedSecret(enums.publicKey.x25519, eccSecretKey, eccCipherText); | ||
const eccKeyShare = await hash.sha3_256(util.concatUint8Array([ | ||
X, | ||
eccCipherText, | ||
eccPublicKey | ||
])); | ||
return eccKeyShare; | ||
} | ||
default: | ||
throw new Error('Unsupported KEM algorithm'); | ||
} | ||
} |
Oops, something went wrong.