Function crypto::shamir::poly_random

source ·
fn poly_random(rng: &mut Rand32, secret: gf256, degree: usize) -> Vec<gf256>
Expand description

This function generates a random polynomial for Shamir’s secret sharing. It takes a secret and degree of polynomial to create (the amount of shares) It sets the y-intercept to the secret passed in and then generates as many points as there are shares, and returns the polynomial, with the secret as the first item. Imagine you’re trying to create a polynomial with a degree of 2: In math notation that would look like this: ax2+bx+c ax^2 + bx + c Since the y-intercept will be the secret, we can set the secret to cc. Then, we generate two values, aa and bb, which define the x2x^2 portion of the polynomial and the xx. Imagine our aa is 7, our bb is 5 and our secret is 8. The polynomial would look like this: 7x2+5x+87x^2 + 5x + 8. In code, since we populate the values in reverse, that would be: vec![8, 5, 7].