dedis / kyber

Advanced crypto library for the Go language
Other
643 stars 168 forks source link

Method SetIntString in the Scalar interface to create arbitrary large scalars from strings #534

Open pmcampones opened 3 months ago

pmcampones commented 3 months ago

Hello all,

I added the method SetIntString(v string) (Scalar, error) in the Scalar interface and implemented it on the structs that satisfy Scalar.

My reasoning was that I needed to use a Secret Sharing protocol and was having a fair bit of trouble creating a scalar with the value of the secret. In the vss_test.go tests, the secret is a random value, and there is a method just to create a random Scalar; however, to create a deterministic value, I either had to use SetInt64 or SetBytes. With SetInt64, the number I set could have at most 64 bits. With SetBytes, to generate a number I would have to pass its representation as a byte array. I found this hard to accomplish.

To make SetIntString I simply used big.Int's method to convert the string into a big.Int and then used what was already available to convert the big.Int into a Scalar.

I tested the changes in vss_test.go, function TestDeterministicStringSecret. It repeats tests that were already done but with an hardcoded secret instead of a random value. I had to refactor the code a little to avoid repeating code, but nothing major. All tests are still running fine.

Thanks

CLAassistant commented 3 months ago

CLA assistant check
All committers have signed the CLA.

github-actions[bot] commented 3 months ago

🔒 Could not start CI tests due to missing safe PR label. Please contact a DEDIS maintainer.

sonarcloud[bot] commented 3 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

sonarcloud[bot] commented 3 months ago

Please retry analysis of this Pull-Request directly on SonarCloud