SpinResearch / RustySecrets

🔑 Threshold Shamir's secret sharing in Rust
BSD 3-Clause "New" or "Revised" License
258 stars 33 forks source link

Implement {Add, Div, Mul, Sub}Assign for Gf256 #47

Closed psivesely closed 6 years ago

psivesely commented 6 years ago

I implemented the {Add, Div, Mul, Sub}Assign because I believe they make the code cleaner and easier to follow. I didn't write any tests because the implementations are very simply piggy-backing on the code you've already written, but am happy to add some if you'd like.

I want to note that the assignment operators are not identical to the non-assignment counterparts because I didn't find any documentation on this. When using the assignment operators first the right-hand side of the <op>= symbol is calculated and then <op> operates on that and the left-hand side. So one needs to be careful order of operations are respected:

fn main() {
    let mut x = 4;
    x *= 2 + 5;
    println!("{:?}", x);

    let mut x = 4;
    x = x * 2 + 5;
    println!("{:?}", x);
}
28
13

This is relevant in https://github.com/SpinResearch/RustySecrets/compare/SpinResearch:3de1689...nvesely:f3f16dc#diff-6dad4b2a3f944968075fe32bae709406R40

romac commented 6 years ago

Looks good! Thanks!