Closed sijohans closed 2 years ago
Interesting.
I've used golang as a way to "verify" if it worked:
https://github.com/DavyLandman/compact25519/blob/master/test/algamize-test.go
But I didn't port the reference values.
I don't have time this week to take a look. Can you try recalculating the Public key from the private key if that works as expected?
And I'm assuming you ruled out typo's in the key arrays?
At least i think so, always good to have another pair of eyes looking at it. I also tried reverting the order of the input if it was wrong endinaness or so, but i didn't get any better result.
Should the seed from the RFCs give the same keys if using this library?
The above mentioned test vectors are for X25519, not Ed25519. Nice post that describes the difference: X25519 vs Ed25519
@iotanbo thanks for taking the time to check them out. I kept on forgetting to validate them.
@sijohans I'm closing this issue, feel free to open if I've misunderstood your issue.
Actually, it turned out that @sijohans was right.
The reason why the test vector given in RFC7748 section 5 doesn't work is because the provided secret keys are raw, i.e. BEFORE clamping applied to them.
Adding
c25519_prepare(alice_sec);
c25519_prepare(bob_sec);
before calling compact_x25519_shared
in his code fixes the issue.
At the same time, the tests provided by this library work fine because clamping is applied to secret keys immediately after their creation.
In order to fix this issue, I suggest to call c25519_prepare
inside
compact_x25519_shared
function as well.
c25519_prepare
can be safely applied multiple times to the secret key, and it is very short
so no extra performance penalty will occur.
P.S. Please, check if I am correct this time :)
Okay, reopening until I have time to take a look.
Also, note that my goals is not compliance with a single RFC. There exists multiple RFCs that use Curve25619 operations.
We maybe we could develop some specific wrappers that make it compatible with specific RFCs?
As I understand, the library is already compatible with that RFC. This issue is a minor bug which can be fixed with a single line of code. If you want, I can can do it and create a pull request.
This page already contains description of two different constrains between RFCs: https://www.dlbeer.co.nz/oss/c25519.html
I'm fine with reviewing a PR, however, the test should still work. I would like to remain compatible with the go library.
Okay, we can close the issue, primarily due to the help of @iotanbo who took the time to figure out what went wrong.
In essence, the API assumption was that you would always use keys calculated bye the compact_x25519_keygen
function. (if you would have run the private key through that first it would have worked). We're now taking a more safe API approach, to always re-clamp the key (at the cost of an extra memory copy, but compared to the rest of the code, that's negligible).
There's a new release out: https://github.com/DavyLandman/compact25519/releases/tag/v1.1.0
Hello,
I looked into RFC7748 and found some test vectors:
Using these values i get different result for the shared secret between bob and alice. Also, none of the calculated shared secrets will match the shared secret from test vectors.
Am i missing something here? Endianess?