Adds 3 bit strings contained in nodes a, b and c of a graph g. This function calls 2 graphs: - adder_g that is the full adder graph for 2 bit strings, - shift_g that performs the left shift of a bit string by 1 position.
(
g: Graph,
adder_g: Graph,
shift_g: Graph,
a: Node,
b: Node,
c: Node,
prf_for_mul_keys: Node,
)
| 379 | /// - adder_g that is the full adder graph for 2 bit strings, |
| 380 | /// - shift_g that performs the left shift of a bit string by 1 position. |
| 381 | fn add_3_bitstrings( |
| 382 | g: Graph, |
| 383 | adder_g: Graph, |
| 384 | shift_g: Graph, |
| 385 | a: Node, |
| 386 | b: Node, |
| 387 | c: Node, |
| 388 | prf_for_mul_keys: Node, |
| 389 | ) -> Result<Node> { |
| 390 | // Reduce addition of three values to two values via the full adder circuit. |
| 391 | // Given 3 bitstrings a, b and c, Add(a,b,c) = Add(carry << 1, xor_123), |
| 392 | // where carry = a AND b XOR c AND (a XOR b), xor_123 = a XOR b XOR c |
| 393 | // and Add is the binary adder. |
| 394 | // a XOR b |
| 395 | let xor_12 = add_mpc(a.clone(), b.clone())?; |
| 396 | // a AND b, don't reshare the result |
| 397 | let and_12 = multiply_mpc(a, b, prf_for_mul_keys.clone(), false)?; |
| 398 | // (a XOR b) AND c, don't reshare the result |
| 399 | let xor_12_and_3 = multiply_mpc(xor_12.clone(), c.clone(), prf_for_mul_keys.clone(), false)?; |
| 400 | // a XOR b XOR c |
| 401 | let xor_123 = add_mpc(xor_12, c)?; |
| 402 | // (a AND b) XOR (a XOR b) AND c and reshare the result |
| 403 | let carry = add_mpc(and_12, xor_12_and_3)?; |
| 404 | |
| 405 | // carry << 1 |
| 406 | let shifted_carry = reshare(&g.call(shift_g, vec![carry])?, &prf_for_mul_keys)?; |
| 407 | |
| 408 | // xor_123 + (carry << 1) = Add(a,b,c) |
| 409 | g.call(adder_g, vec![prf_for_mul_keys, xor_123, shifted_carry]) |
| 410 | } |
| 411 | |
| 412 | #[cfg(test)] |
| 413 | mod tests { |
no test coverage detected