Background: I have tried to follow this tutorial on secret sharing: https://medium.com/@apogiatzis/shamirs-secret-sharing-a-numeric-example-walkthrough-a59b288c34c4. I have managed to use Shamir's secret sharing successfully and by hand I am able to work very simple problems out. I'm trying to convert this into code (using javascript and as few dependencies as possible). However I didn't understand why the author of the post used a finite field ? In Shamir's paper he used normal polynomial interpolation as an example.
Issue: I'm trying to use a large prime number value for L(0) and I had made the conscious decision of avoiding finite fields (as I don't really understand why they are being used, or how to use them properly). The issue is that when I select random points to generate the polynomial I end up with large decimal values and likewise when I generate the secret shards (each shard is one of the l(i)*y_i of the lagrange polynomial interpolation) to distribute they are actually large numbers with many decimal values. Unfortunately I'm failing to successfully decrypt the end result and I believe this is due to the accuracy of big numbers and the limitation of decimals in Javascript (or any language for that matter).
Question: How did the author of the above post generate such clean numbers (no decimals, just really large integer numbers)? Is this related to the use of a finite field ? How can I do this same thing efficiently ?
Detailed Step By Step:
- Generate large prime
- Pick k-1 random points
- Use the large prime and the k-1 random points to generate the coefficients for the polynomial
- Randomly select k number of x values between 1 to phi (where phi=(p-1)(p-q), where p & q are 2 large primes such that pq=n and n is a key size X bytes long)
- Evaluate k number of x values on the polynomial for the y value
- use the X,Y values to create the lagrange polynomial interpolation.
Thanks for this one !!!!!!!
Roundoff error is likely to be bad news if you're trying to do one of these computations with floating-point numbers. It means that floating-point arithmetic doesn't obey the standard laws of algebra: e.g. in general $(a+b)+c$ is not the same as $a + (b+c)$ when roundoff is involved. For any of these computations to work reliably you'll want to use exact integer arithmetic, either with a "bignum" package or with a language that has support for that built-in.