Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] Add ML-KEM (FIPS 203). #470

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

[DNM] Add ML-KEM (FIPS 203). #470

wants to merge 2 commits into from

Conversation

bwesterb
Copy link
Member

@bwesterb bwesterb commented Jan 4, 2024

ML-KEM is not final yet, so this implementation isn't final either.

We keep Kyber around (for now) as it's currently widely deployed. Code differences between them are minimal anyway.

ML-KEM is not final yet, so this implementation isn't final either.

We keep Kyber around (for now) as it's currently widely deployed.
Code differences between them are minimal anyway.
@bwesterb bwesterb marked this pull request as draft January 4, 2024 21:45
@bwesterb bwesterb changed the title [WIP] Add ML-KEM (FIPS 203). [DNM] Add ML-KEM (FIPS 203). Feb 15, 2024
Copy link
Contributor

@Lekensteyn Lekensteyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of nits, the only really "wrong" thing is a documentation comment.

LGTM otherwise!

kem/kyber/templates/pkg.templ.go Outdated Show resolved Hide resolved
kem/kyber/templates/pkg.templ.go Outdated Show resolved Hide resolved
kem/kyber/templates/pkg.templ.go Outdated Show resolved Hide resolved
kem/kyber/templates/pkg.templ.go Outdated Show resolved Hide resolved
@@ -143,6 +151,9 @@ func (pk *PublicKey) EncapsulateTo(ct, ss []byte, seed []byte) {
// c = Kyber.CPAPKE.Enc(pk, m, r)
pk.pk.EncryptTo(ct, m[:], kr[32:])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at it, maybe we can use a name for this constant. This matches the type of K in the Algorithm 16 from FIPS 203 ("derive shared secret K and randomness r") and is consistent with your other use of kr[:SharedKeySize] below.

Suggested change
pk.pk.EncryptTo(ct, m[:], kr[32:])
pk.pk.EncryptTo(ct, m[:], kr[SharedKeySize:])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is accidental, and that 32 is not the shared key size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not following.

My understanding is that the first part of kr is the shared secret key. So kr[SharedKeySize:] would skip the shared secret key, and refer to the remaining part, r.

Output: shared key K ∈ B32
(K, r) ← G(m ∥ H(ek))           ▷ derive shared secret key K and randomness r
c ← K-PKE.Encrypt(ek, m, r)     ▷ encrypt m using K-PKE with randomness r

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Kyber the first 32 bytes does not contain the returned shared secret, but an intermediate key that happens to be 32 bytes as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, what about replacing kr[:SharedKeySize] by kr[:32] to avoid that implication?

kem/kyber/templates/pkg.templ.go Outdated Show resolved Hide resolved
@bwesterb
Copy link
Member Author

Lots of nits, the only really "wrong" thing is a documentation comment.

Thanks. Addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants