Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

content of hybrid public key #572

Closed
petrovr opened this issue Nov 19, 2024 · 13 comments
Closed

content of hybrid public key #572

petrovr opened this issue Nov 19, 2024 · 13 comments
Labels
question No code change required

Comments

@petrovr
Copy link

petrovr commented Nov 19, 2024

Function EVP_PKEY_get_octet_string_param with arguments OSSL_PKEY_PARAM_PUB_KEY returns some data.
For key X25519MLKEM768 I expect to see output that contains concatenation of respective public parts.

Current output is with length 1220=4(?)+1184+32.

Why output contain (starts) with length of x25519 key?

@petrovr petrovr added the bug Something isn't working label Nov 19, 2024
@baentsch
Copy link
Member

The reason for this is that some classic algs may have a length less than the maximum length and the logic in oqs-provider is generic in that sense (handling also that case, thus encoding the actual length in 4 bytes). If you could point to a specific specification that mandates this to be different (and how) please provide a pointer so we can properly treat this as a bug and solicit PRs to change this behaviour.

@baentsch baentsch added question No code change required and removed bug Something isn't working labels Nov 22, 2024
@petrovr
Copy link
Author

petrovr commented Nov 22, 2024

Now I have draft implementation of mlkem768x25519-sha256, see
https://datatracker.ietf.org/doc/html/draft-kampanakis-curdle-ssh-pq-ke-04 .
It uses EVP and PKEY API with activated oqs-provider.

For protocol dump shows that OSSL_PKEY_PARAM_PUB_KEY for X25519MLKEM768 return data that starts with 32 (four bytes) + 1184 bytes + 32 bytes.


Project openssh is out of scope as it uses archaic OpenSSL API.

Soon I will publish PKIX-SSH draft implementation as new branch. Implementation pass interoperable tests with asyncssh (uses dynamically loaded oqs library).

@baentsch
Copy link
Member

Soon I will publish PKIX-SSH draft implementation as new branch.

Thanks for letting us know (also thanks for the spec pointer) @petrovr ! It would be helpful if you could post a pointer here as and when (and where!) you have published this when you're done -- and particularly if you think some code changes in oqsprovider are required: Thanks in advance.

@baentsch
Copy link
Member

Issues doesn't seem to require attention, so closing. Feel free to re-open as needed.

@petrovr
Copy link
Author

petrovr commented Nov 30, 2024

More than one month a have prototype of "PQ/T Hybrid Key Exchange in SSH" (draft-kampanakis-curdle-ssh-pq-ke-NN) that uses OpenSSL PKEY with key generation, encapsulation, and decapsulation. Prototype "dumps" a lot of "internal information".

Defect is inspired from prototype.

Let review just published hybrid_demo commits. "HYBRID-DEMO: public part hack" in required.

So which standard defines that public key must start with length of classical key?

Note this is first issue about "content". It seems to me this is common case.


@petrovr
Copy link
Author

petrovr commented Nov 30, 2024

@baentsch I think that issue should be reopened.

@baentsch
Copy link
Member

baentsch commented Dec 1, 2024

@baentsch I think that issue should be reopened.

No problem doing that.

I'm still a bit confused, though: How can the format of the hybrid public key be incorrect, given that this code seems to be able to successfully complete hybrid TLS1.3 KEM handshakes (where the public key is exchanged, right?) as per

echo -e "GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n" | "${OPENSSL_APP}" s_client ${USE_PROXY} -connect google.com:443 -groups X25519MLKEM768 -servername google.com >/dev/null 2>/dev/null

@baentsch baentsch reopened this Dec 1, 2024
@petrovr
Copy link
Author

petrovr commented Dec 1, 2024

Hi @baentsch ,

I do not know SSL/TLS .
When I run s_client utility with group X25519MLKEM768 in trace mode I note following:

...
Sent TLS Record
...
        extension_type=key_share(51), length=1222
            NamedGroup: UNKNOWN (4588)
            key_exchange:  (len=1216): B4F64D913435 ... ... ...
...
Received TLS Record
        extension_type=key_share(51), length=1124
            NamedGroup: UNKNOWN (4588)
            key_exchange:  (len=1120): B55CDCE59A ... ... ...
...

If I read properly exchanged data 1216(=1184+32) is public part.
Hexidecimal sequence starts B4F6. This does not lock like length of classical key.

In test/demo code extract of public is with length 1220 and sequence like 00 00 00 20 8C 68 60 D2 76.

No idea what is difference in code path between s_client and as test/demo code.
Demo uses "EVP_PKEY_get_octet_string_param(..., OSSL_PKEY_PARAM_PUB_KEY, ...".

@baentsch
Copy link
Member

baentsch commented Dec 2, 2024

Well in that case, the logic seems to be correct for TLS encoded public keys (leaving away the classic key length). Begs the question what happens (edit/add: is expected) in SSH case (for which no specific code has ever been written or tests devised). The latter point actually now is my proposal to get to the bottom of this:

Would it be possible for you to provide a (SSH-based) test case that currently fails and that should require a code update to pass, @petrovr ? This might serve as a blueprint (edit/add: suggestion what needs changing to support both use cases).

@baentsch
Copy link
Member

baentsch commented Dec 2, 2024

Demo uses "EVP_PKEY_get_octet_string_param(..., OSSL_PKEY_PARAM_PUB_KEY, ...".

That then is the explanation: The encoded format omits the length field while the raw form above contains it. Question then is: What parameter does SSH use? And: Would there be any client code complaining if the contents of OSSL_PKEY_PARAM_PUB_KEY were changing?

@petrovr
Copy link
Author

petrovr commented Dec 2, 2024 via email

@petrovr
Copy link
Author

petrovr commented Dec 2, 2024 via email

@baentsch
Copy link
Member

baentsch commented Dec 3, 2024

P.S. It is quite interesting to me how TLS get "correct" value.

Also for me: A "history lesson" with an implementation following different "hybrid" proposals over time -- very clearly making the case again for redoing this properly as per #375.

@open-quantum-safe open-quantum-safe locked and limited conversation to collaborators Dec 12, 2024
@baentsch baentsch converted this issue into discussion #591 Dec 12, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question No code change required
Projects
None yet
Development

No branches or pull requests

2 participants