pub fn inputs<Idx: GateIdx>(inputs: usize) -> Vec<Secret<BooleanGmw, Idx>>
Examples found in repository?
crates/seec/examples/privmail.rs (line 177)
170 171 172 173 174 175 176 177 178 179 180 181 182
fn base64_string_to_input(
input: &str,
duplication_factor: usize,
) -> (BitVec<usize>, Vec<[Secret; 8]>) {
let decoded = BASE64_STANDARD.decode(input).expect("Decode base64 input");
let duplicated = decoded.repeat(duplication_factor);
let shares = (0..duplicated.len())
.map(|_| inputs(8).try_into().unwrap())
.collect();
let input = BitVec::from_vec(duplicated);
let input = BitVec::from_iter(input);
(input, shares)
}
More examples
crates/seec/examples/privmail_sc.rs (line 178)
171 172 173 174 175 176 177 178 179 180 181 182 183
fn base64_string_to_input(
input: &str,
duplication_factor: usize,
) -> (BitVec<usize>, Vec<[Secret; 8]>) {
let decoded = BASE64_STANDARD.decode(input).expect("Decode base64 input");
let duplicated = decoded.repeat(duplication_factor);
let shares = (0..duplicated.len())
.map(|_| inputs(8).try_into().unwrap())
.collect();
let input = BitVec::from_vec(duplicated);
let input = BitVec::from_iter(input);
(input, shares)
}
crates/seec/examples/aes_cbc.rs (line 393)
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
fn build_enc_circuit(
data_size_bits: usize,
use_sc: bool,
) -> Result<ExecutableCircuit<bool, BooleanGate, usize>> {
assert_eq!(
data_size_bits % 128,
0,
"data_size must be multiple of 128 bits"
);
let key_size = 128;
let iv_size = 128;
let key = inputs(key_size);
let iv = inputs(iv_size);
let data = inputs(data_size_bits);
let mut chaining_state = iv;
data.chunks_exact(128)
.for_each(|chunk| aes_cbc_chunk(&key, chunk, &mut chaining_state, use_sc));
Ok(ExecutableCircuit::DynLayers(CircuitBuilder::<
bool,
BooleanGate,
usize,
>::global_into_circuit()))
}
crates/seec/examples/sub_circuits.rs (line 26)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
let input_shares = inputs(8);
let and_outputs = input_shares
.chunks_exact(4)
.fold(vec![], |mut acc, input_chunk| {
let output = and_sc(input_chunk);
acc.push(output);
acc
});
let or_out = or_sc(&and_outputs);
(or_out ^ false).output();
let circuit: Circuit<bool, BooleanGate, DefaultIdx> = CircuitBuilder::global_into_circuit();
let layer_iter = CircuitLayerIter::new(&circuit);
for layer in layer_iter {
dbg!(layer);
}
// let circuit = circuit.into_base_circuit();
// eprintln!("into base");
// circuit.save_dot("sub_circuits.dot").unwrap();
}
crates/seec/examples/simple.rs (line 28)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
fn build_circuit() {
// The `inputs` method is a convenience method to create n input gates for the circuit.
// It returns a Vec<Secret>. In the following, we use try_into() to convert it into
// an array to destructure it
let [a, b, c, d]: [_; 4] = inputs::<DefaultIdx>(4).try_into().unwrap();
// a,b,c,d are `Secret`s representing the output share of a gate. They support
// the standard std::ops traits like BitAnd and BitXor (and their Assign variants) which
// are used to implicitly build the circuit.
// Creates a new Xor gate with the input of a and b. The output is a new Secret
// representing the output of the new gate.
let xor = a ^ b;
// To use a Secret multiple times (connect to gate represented by it to multiple
// different ones), simply use a reference to it (only possibile on the rhs).
let and = c & &d;
// we can still use d but not c
let mut tmp = and ^ d;
// BitAnd and BitXor are also supported, as is Not. See the Secret documentation for
// all operations.
tmp &= !xor;
// `output()` consumes the Secret and creates a new Output gate with its output.
// It returns the gate_id of the Output gate (this is usually not needed).
let _out_gate_id = tmp.output();
}
crates/seec/examples/bristol.rs (line 121)
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
fn compile(compile_args: CompileArgs) -> Result<()> {
let load = match compile_args.simd {
Some(_) => Load::SubCircuit,
None => Load::Circuit,
};
let mut bc: BaseCircuit = BaseCircuit::load_bristol(&compile_args.circuit, load)
.expect("failed to load bristol circuit");
let mut circ = match compile_args.simd {
Some(size) => {
bc.set_simd_size(size);
let circ_input_size = bc.sub_circuit_input_count();
let inputs = inputs::<u32>(circ_input_size);
let bc = bc.into_shared();
let (output, circ_id) = CircuitBuilder::with_global(|builder| {
builder.get_main_circuit().lock().set_simd_size(size);
let circ_id = builder.push_circuit(bc);
let output = builder.connect_sub_circuit(&inputs, circ_id);
(output, circ_id)
});
let main = output.connect_to_main(circ_id);
main.iter().for_each(|s| {
s.output();
});
let circ = CircuitBuilder::global_into_circuit();
ExecutableCircuit::DynLayers(circ)
}
None => ExecutableCircuit::DynLayers(bc.into()),
};
if !compile_args.dyn_layers {
circ = circ.precompute_layers();
}
let out =
BufWriter::new(File::create(&compile_args.output).context("failed to create output file")?);
bincode::serialize_into(out, &circ).context("failed to serialize circuit")?;
Ok(())
}