MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / add_3_bitstrings

Function add_3_bitstrings

ciphercore-base/src/mpc/mpc_conversion.rs:381–410  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
381fn 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)]
413mod tests {

Callers 1

instantiateMethod · 0.85

Calls 5

add_mpcFunction · 0.85
multiply_mpcFunction · 0.85
reshareFunction · 0.85
cloneMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected