ext/gmp: add test for uses of gmp_pow with number sizes commonly used in cryptography#16896
ext/gmp: add test for uses of gmp_pow with number sizes commonly used in cryptography#16896brainpower wants to merge 2 commits intophp:masterfrom
Conversation
|
Thank you for the PR! Regarding the test name: it's okay as is, but might also be called gmp_pow_crypto.phpt or so. |
|
I don't care about the name, so if you really like the descriptive one, I'll simply rename it. |
|
@brainpower, I think we need to fix the actual issue first (very important wrt |
|
Hi, thanks you two for tackling this! I can help here add some unit cases of "real" crypto if this is still useful after the newest patch (and its tests) landed. Common operations would include additions and multiplications on the curves. Using a more applied perspective, one could add examples of signatures, committments and zero-knowledge proofs. |
|
@famoser, more test cases (especially if they are about real world usage) are certainly welcome! Not only to serve as regression tests, but also to explain/show-case some of the algorithms typically used for cryptographic purposes. |
|
A proposal for a test, which I would place in Can be tested by executing |
|
I've updated the PR to include the posted test, with the small change of splitting the long description into a And decided to keep my test, too, since it had still failed on the master I had before rebasing (c84b7ed), |
|
Thank you for the cleanup with the
Yes you are right, I do not actually use It would therefore make sense to also either add elliptic curve operations, or try to test the different type of executed operations in such code (... which are not already tested in my testcase). For example, another function I never use is Another thing we might tackle is testing the overload operators: While |
|
To make some progress here, I propose:
Then, I see two future PRs:
Reasoning:
|
|
Makes sense. |
|
LGTM. So I guess you may now remove the draft status of the PR, so that @Girgias can take a look? |
Girgias
left a comment
There was a problem hiding this comment.
I think it would be good to add a similar test for the overloaded operators.
Would you do this now, and if so, for what operators? Or what do you think about the proposed approach here: #16896 (comment) |
That approach makes sense, adding more tests that cover most operators is best. |
So you would be OK with doing this in a future PR (by the reasoning of #16896 (comment)), and merge this PR in the state as it is now? |
Sure, does not need to all be in the same one. |
|
@brainpower if you also agree, could you please unset the draft / WIP state of the PR? |
Girgias
left a comment
There was a problem hiding this comment.
One question, but otherwise LGTM
ext/gmp/tests/gmp_cryptography.phpt
Outdated
| var_dump((string) gmp_pow($big_128, 2)); | ||
| var_dump((string) gmp_pow($big_128, 3)); | ||
| #var_dump((string) gmp_pow($big_128, 65537)); | ||
|
|
||
| var_dump((string) gmp_pow($big_256, 2)); | ||
| var_dump((string) gmp_pow($big_256, 3)); | ||
| #var_dump((string) gmp_pow($big_256, 65537)); | ||
|
|
||
| var_dump((string) gmp_pow($big_384, 2)); | ||
| var_dump((string) gmp_pow($big_384, 3)); | ||
| #var_dump((string) gmp_pow($big_384, 65537)); | ||
|
|
||
| var_dump((string) gmp_pow($big_521, 2)); | ||
| var_dump((string) gmp_pow($big_521, 3)); | ||
| #var_dump((string) gmp_pow($big_521, 65537)); |
There was a problem hiding this comment.
Normal that the 3rd call in each block is commented out?
There was a problem hiding this comment.
That was some experiment by me, that was not meant to be committed. Thought I had that stashed, but seems like I hadn't.
I've removed them.
with common number sizes used there
|
So GitHub is just being crap today, it somehow merged it as 47942be but does not close the PR.... |
… in cryptography (php#16896) With common number sizes used there --------- Co-authored-by: Florian Moser <git@famoser.ch>
In #16870 I suggested testing common operations performed by crypto implementations,
since those are one of the primary use cases of "big numbers", thus probably GMP.
During my troubleshooting the issue I found that when doing Elyptic Curve calculations,
it seems squaring and cubing Keys or Points on the Curve is a common operation.
So test squaring and cubing numbers which are of typical ECC key sizes.
I'm no crypto expert, so I don't really know much which other common crypto operations could be added,
but this should be a start.
This test succeeds on versions without the new checks introduced with #16384 ,
but currently fails on master.
It succeeds when applying the proposed fix in #16884.