arcis 0.6.0-alpha

A standard library of types and functions for writing MPC circuits with the Arcis framework.
Documentation
use crate::*;
use arcis_interpreter_proc_macros::encrypted_library;
#[encrypted_library]
mod arcis_library {

    struct ArcisRNGUtils;
    impl ArcisRNGUtils {
        #[arcis_circuit = "bitwise_and"]
        fn bitwise_and(a: u128, b: u128) -> u128 {}
        #[arcis_circuit = "lowest_bigger_power_of_two_minus_one"]
        fn lowest_bigger_power_of_two_minus_one(a: u128) -> u128 {}
    }
    impl ArcisRNG {
        fn gen_and_reject(max: u128) -> (u128, bool) {
            let lbpotmo = ArcisRNGUtils::lowest_bigger_power_of_two_minus_one(max);
            let rand = Self::gen_integer_from_width(128);
            let rand = ArcisRNGUtils::bitwise_and(rand, lbpotmo);
            if rand <= max {
                (rand, true)
            } else {
                (0, false)
            }
        }
        /// Generates an integer above `min` and below `max`, both included.
        /// It tries `n_attempts` times, with each attempt having > 1/2 chance of success.
        /// If `min > max`, calling this function is UB.
        /// Returns `(min, false)` in case of failure, `(result, true)` in case of success.
        /// Note that `n_attempts` must be known at compile time.
        pub fn gen_integer_in_range(min: u128, max: u128, n_attempts: usize) -> (u128, bool) {
            let range = max - min;
            let mut res = 0;
            let mut success = false;
            for _ in 0..n_attempts {
                let (r, s) = Self::gen_and_reject(range);
                if !success {
                    res = r;
                    success = s;
                }
            }
            (res + min, success)
        }
    }
}