(value: Value, t: Type)
| 1428 | } |
| 1429 | |
| 1430 | fn prepare_private_value(value: Value, t: Type) -> Result<Vec<Value>> { |
| 1431 | // private shares of value are generated as |
| 1432 | // value = (value + 2, -1, -1) |
| 1433 | if let Type::Scalar(st) | Type::Array(_, st) = t.clone() { |
| 1434 | let mut res = vec![]; |
| 1435 | let zero = Value::zero_of_type(t.clone()); |
| 1436 | let one = Value::from_scalar(1, st)?; |
| 1437 | let two = Value::from_scalar(2, st)?; |
| 1438 | for i in 0..PARTIES { |
| 1439 | let (add_sub, l_value, r_value) = match i { |
| 1440 | 0 => (Operation::Add, value.clone(), two.clone()), |
| 1441 | 1 => (Operation::Subtract, zero.clone(), one.clone()), |
| 1442 | 2 => (Operation::Subtract, zero.clone(), one.clone()), |
| 1443 | _ => panic!("More than 3 parties are not supported"), |
| 1444 | }; |
| 1445 | let share = evaluate_add_subtract_multiply( |
| 1446 | t.clone(), |
| 1447 | l_value, |
| 1448 | scalar_type(st), |
| 1449 | r_value, |
| 1450 | add_sub, |
| 1451 | t.clone(), |
| 1452 | )?; |
| 1453 | res.push(share); |
| 1454 | } |
| 1455 | return Ok(res); |
| 1456 | } |
| 1457 | |
| 1458 | let vector_types = get_types_vector(t.clone())?; |
| 1459 | let mut shares = vec![vec![]; PARTIES]; |
| 1460 | value.access_vector(|vector_values| { |
| 1461 | for i in 0..vector_values.len() { |
| 1462 | let tuple_i = |
| 1463 | prepare_private_value(vector_values[i].clone(), (*vector_types[i]).clone())?; |
| 1464 | for j in 0..PARTIES { |
| 1465 | shares[j].push(tuple_i[j].clone()) |
| 1466 | } |
| 1467 | } |
| 1468 | Ok(()) |
| 1469 | })?; |
| 1470 | let mut res = vec![]; |
| 1471 | for share in shares { |
| 1472 | res.push(Value::from_vector(share)); |
| 1473 | } |
| 1474 | Ok(res) |
| 1475 | } |
| 1476 | |
| 1477 | fn prepare_value(value: Value, t: Type, is_input_private: bool) -> Result<Value> { |
| 1478 | if is_input_private { |
no test coverage detected