lav-vrf 0.0.1

Pure Rust implementation of LaV, an experimental lattice-based verifiable random function (VRF)
Documentation
#[cfg(target_arch = "aarch64")]
pub use ::core::arch::aarch64::int64x2_t as __m128i;
#[cfg(target_arch = "x86")]
pub use ::core::arch::x86::__m128i;
#[cfg(target_arch = "x86_64")]
pub use ::core::arch::x86_64::__m128i;
unsafe extern "C" {
    fn lanes_rqhat_mul(
        out: *mut LANES_Rqhat,
        a: *const LANES_Rqhat,
        b: *const LANES_Rqhat,
    );
    fn lanes_rqhat_add_nomodqhat(
        out: *mut LANES_Rqhat,
        a: *const LANES_Rqhat,
        b: *const LANES_Rqhat,
    );
    fn lanes_rqhat_modqhat(a: *mut LANES_Rqhat);
    fn lanes_rqhat_add(
        out: *mut LANES_Rqhat,
        a: *const LANES_Rqhat,
        b: *const LANES_Rqhat,
    );
    fn lanes_rqhat_sub(
        out: *mut LANES_Rqhat,
        a: *const LANES_Rqhat,
        b: *const LANES_Rqhat,
    );
    fn lanes_rqhat_inner_product_nomodqhat_b(
        out: *mut LANES_Rqhat,
        bvec: *const LANES_Rqhat,
        x: *const LANES_Rqhat,
        index: size_t,
    );
    fn lanes_sampler_rqhat_1d(
        out: *mut LANES_Rqhat,
        len: size_t,
        ctx: *mut aes256ctr_ctx,
    );
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct LANES_Rqhat {
    pub poly: [int64_t; 128],
}
pub type int64_t = i64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct LANES_MP_PROOF {
    pub tN: *mut LANES_Rqhat,
    pub alpha: *mut LANES_Rqhat,
    pub v: *mut LANES_Rqhat,
}
pub type size_t = usize;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct LANES_MP_PROVE_IN {
    pub m: *const int64_t,
    pub m_alpha1: size_t,
    pub m_alpha2: size_t,
    pub b: *const [LANES_Rqhat; 22],
    pub r_ntt: *const LANES_Rqhat,
    pub ctx: *mut aes256ctr_ctx,
    pub y_ntt: *const LANES_Rqhat,
    pub b_y: *const LANES_Rqhat,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct aes256ctr_ctx {
    pub rkeys: [__m128i; 16],
    pub n: __m128i,
}
pub type uint64_t = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct LANES_MP_VER {
    pub t: *const LANES_Rqhat,
    pub tN: *const LANES_Rqhat,
    pub alpha: *const LANES_Rqhat,
    pub v: *const LANES_Rqhat,
    pub m_alpha1: size_t,
    pub m_alpha2: size_t,
    pub c_ntt: *const LANES_Rqhat,
    pub z_ntt: *const LANES_Rqhat,
    pub b: *const [LANES_Rqhat; 22],
    pub b_z: *const LANES_Rqhat,
}
static mut lanes_qhat: uint64_t = 67112897 as uint64_t;
#[inline]
unsafe extern "C" fn check_rqhat_equal(
    mut a: *const LANES_Rqhat,
    mut b: *const LANES_Rqhat,
) -> ::core::ffi::c_int {
    let mut i: size_t = 0;
    i = 0 as size_t;
    while i < 128 as size_t {
        if (*a).poly[i as usize] != (*b).poly[i as usize] {
            return 0 as ::core::ffi::c_int;
        }
        i = i.wrapping_add(1);
    }
    return 1 as ::core::ffi::c_int;
}
#[inline]
unsafe extern "C" fn lanes_plantard(
    a: uint64_t,
    b: uint64_t,
    r: uint64_t,
    q: uint64_t,
) -> uint64_t {
    let mut c: uint64_t = a.wrapping_mul(b).wrapping_mul(r);
    return (c >> 32 as ::core::ffi::c_int).wrapping_add(1 as uint64_t).wrapping_mul(q)
        >> 32 as ::core::ffi::c_int;
}
#[inline]
unsafe extern "C" fn lanes_plantard_const(
    a: uint64_t,
    b: uint64_t,
    q: uint64_t,
) -> uint64_t {
    return lanes_plantard(a, b, 1 as uint64_t, q);
}
#[inline]
unsafe extern "C" fn lanes_modqhat_plantard_const(a: uint64_t, b: uint64_t) -> uint64_t {
    return lanes_plantard_const(a, b, lanes_qhat);
}
#[inline]
unsafe extern "C" fn lanes_modqhat(a: uint64_t) -> uint64_t {
    return lanes_modqhat_plantard_const(a, 274861388769 as uint64_t);
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lanes_mp_prove(
    mut mp_out: *mut ::core::ffi::c_void,
    mut mp_in: *const ::core::ffi::c_void,
) {
    let mut in_0: *mut LANES_MP_PROVE_IN = mp_in as *mut LANES_MP_PROVE_IN;
    let mut out: *mut LANES_MP_PROOF = mp_out as *mut LANES_MP_PROOF;
    let mut alpha_b_y: [LANES_Rqhat; 6] = [LANES_Rqhat { poly: [0; 128] }; 6];
    let mut alpha_b_y_2: [LANES_Rqhat; 6] = [LANES_Rqhat { poly: [0; 128] }; 6];
    let mut buf: LANES_Rqhat = LANES_Rqhat { poly: [0; 128] };
    let mut i: size_t = 0;
    let mut j: size_t = 0;
    let mut k: size_t = 0;
    lanes_sampler_rqhat_1d(
        (*out).alpha,
        (*in_0).m_alpha2.wrapping_sub((*in_0).m_alpha1),
        (*in_0).ctx,
    );
    lanes_rqhat_inner_product_nomodqhat_b(
        (*out).tN,
        &raw const *(*in_0)
            .b
            .offset((6 as ::core::ffi::c_int + 1 as ::core::ffi::c_int) as isize)
            as *const LANES_Rqhat,
        (*in_0).r_ntt,
        (6 as ::core::ffi::c_int + 1 as ::core::ffi::c_int) as size_t,
    );
    i = (*in_0).m_alpha1;
    while i < (*in_0).m_alpha2 {
        lanes_rqhat_mul(
            (&raw mut alpha_b_y as *mut LANES_Rqhat).offset(i as isize),
            (*out).alpha.offset(i as isize).offset(-((*in_0).m_alpha1 as isize)),
            (*in_0).b_y.offset(i as isize),
        );
        lanes_rqhat_mul(
            (&raw mut alpha_b_y_2 as *mut LANES_Rqhat).offset(i as isize),
            (&raw mut alpha_b_y as *mut LANES_Rqhat).offset(i as isize),
            (*in_0).b_y.offset(i as isize),
        );
        j = 0 as size_t;
        while j < 32 as size_t {
            let mut x: int64_t = 3 as int64_t
                * *(*in_0)
                    .m
                    .offset(i.wrapping_mul(32 as size_t).wrapping_add(j) as isize);
            k = 0 as size_t;
            while k < (128 as ::core::ffi::c_int / 32 as ::core::ffi::c_int) as size_t {
                let ref mut fresh0 = (*(*out)
                    .tN
                    .offset(0 as ::core::ffi::c_int as isize))
                    .poly[j
                    .wrapping_mul(
                        (128 as ::core::ffi::c_int / 32 as ::core::ffi::c_int) as size_t,
                    )
                    .wrapping_add(k) as usize];
                *fresh0 = (*fresh0 as uint64_t)
                    .wrapping_add(
                        (3 as uint64_t)
                            .wrapping_mul(lanes_qhat)
                            .wrapping_sub(
                                (x
                                    * alpha_b_y_2[i as usize]
                                        .poly[j
                                        .wrapping_mul(
                                            (128 as ::core::ffi::c_int / 32 as ::core::ffi::c_int)
                                                as size_t,
                                        )
                                        .wrapping_add(k) as usize]) as uint64_t,
                            ),
                    ) as int64_t as int64_t;
                k = k.wrapping_add(1);
            }
            j = j.wrapping_add(1);
        }
        i = i.wrapping_add(1);
    }
    lanes_rqhat_inner_product_nomodqhat_b(
        &raw mut buf,
        &raw const *(*in_0)
            .b
            .offset((6 as ::core::ffi::c_int + 2 as ::core::ffi::c_int) as isize)
            as *const LANES_Rqhat,
        (*in_0).y_ntt,
        (6 as ::core::ffi::c_int + 2 as ::core::ffi::c_int) as size_t,
    );
    lanes_rqhat_add((*out).tN, (*out).tN, &raw mut buf);
    lanes_rqhat_inner_product_nomodqhat_b(
        (*out).tN.offset(1 as ::core::ffi::c_int as isize),
        &raw const *(*in_0)
            .b
            .offset((6 as ::core::ffi::c_int + 2 as ::core::ffi::c_int) as isize)
            as *const LANES_Rqhat,
        (*in_0).r_ntt,
        (6 as ::core::ffi::c_int + 2 as ::core::ffi::c_int) as size_t,
    );
    i = (*in_0).m_alpha1;
    while i < (*in_0).m_alpha2 {
        j = 0 as size_t;
        while j < 32 as size_t {
            let mut x_0: int64_t = 3 as int64_t
                * *(*in_0)
                    .m
                    .offset(i.wrapping_mul(32 as size_t).wrapping_add(j) as isize)
                * *(*in_0)
                    .m
                    .offset(i.wrapping_mul(32 as size_t).wrapping_add(j) as isize)
                - 1 as int64_t;
            k = 0 as size_t;
            while k < (128 as ::core::ffi::c_int / 32 as ::core::ffi::c_int) as size_t {
                let ref mut fresh1 = (*(*out)
                    .tN
                    .offset(1 as ::core::ffi::c_int as isize))
                    .poly[j
                    .wrapping_mul(
                        (128 as ::core::ffi::c_int / 32 as ::core::ffi::c_int) as size_t,
                    )
                    .wrapping_add(k) as usize];
                *fresh1 = (*fresh1 as uint64_t)
                    .wrapping_add(
                        lanes_qhat
                            .wrapping_add(
                                (x_0
                                    * alpha_b_y[i as usize]
                                        .poly[j
                                        .wrapping_mul(
                                            (128 as ::core::ffi::c_int / 32 as ::core::ffi::c_int)
                                                as size_t,
                                        )
                                        .wrapping_add(k) as usize]) as uint64_t,
                            ),
                    ) as int64_t as int64_t;
                k = k.wrapping_add(1);
            }
            j = j.wrapping_add(1);
        }
        i = i.wrapping_add(1);
    }
    lanes_rqhat_modqhat((*out).tN.offset(1 as ::core::ffi::c_int as isize));
    lanes_rqhat_inner_product_nomodqhat_b(
        (*out).v,
        &raw const *(*in_0)
            .b
            .offset((6 as ::core::ffi::c_int + 1 as ::core::ffi::c_int) as isize)
            as *const LANES_Rqhat,
        (*in_0).y_ntt,
        (6 as ::core::ffi::c_int + 1 as ::core::ffi::c_int) as size_t,
    );
    i = (*in_0).m_alpha1;
    while i < (*in_0).m_alpha2 {
        lanes_rqhat_mul(
            &raw mut buf,
            (&raw mut alpha_b_y_2 as *mut LANES_Rqhat).offset(i as isize),
            (*in_0).b_y.offset(i as isize),
        );
        lanes_rqhat_add_nomodqhat((*out).v, (*out).v, &raw mut buf);
        i = i.wrapping_add(1);
    }
    lanes_rqhat_modqhat((*out).v);
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lanes_mp_ver(
    mut mp: *const ::core::ffi::c_void,
) -> ::core::ffi::c_int {
    let mut in_0: *mut LANES_MP_VER = mp as *mut LANES_MP_VER;
    let mut f: LANES_Rqhat = LANES_Rqhat { poly: [0; 128] };
    let mut fc: LANES_Rqhat = LANES_Rqhat { poly: [0; 128] };
    let mut f_sum: LANES_Rqhat = LANES_Rqhat { poly: [0; 128] };
    let mut buf: LANES_Rqhat = LANES_Rqhat { poly: [0; 128] };
    let mut i: size_t = 0;
    lanes_rqhat_inner_product_nomodqhat_b(
        &raw mut f,
        &raw const *(*in_0)
            .b
            .offset((6 as ::core::ffi::c_int + 2 as ::core::ffi::c_int) as isize)
            as *const LANES_Rqhat,
        (*in_0).z_ntt,
        (6 as ::core::ffi::c_int + 2 as ::core::ffi::c_int) as size_t,
    );
    lanes_rqhat_mul(
        &raw mut buf,
        (*in_0).c_ntt,
        (*in_0).tN.offset(1 as ::core::ffi::c_int as isize),
    );
    lanes_rqhat_sub(&raw mut f, &raw mut f, &raw mut buf);
    lanes_rqhat_mul(&raw mut f_sum, (*in_0).c_ntt, &raw mut f);
    i = (*in_0).m_alpha1;
    while i < (*in_0).m_alpha2 {
        lanes_rqhat_mul(&raw mut buf, (*in_0).c_ntt, (*in_0).t.offset(i as isize));
        lanes_rqhat_sub(&raw mut f, (*in_0).b_z.offset(i as isize), &raw mut buf);
        lanes_rqhat_add(&raw mut fc, &raw mut f, (*in_0).c_ntt);
        lanes_rqhat_mul(&raw mut buf, &raw mut f, &raw mut fc);
        lanes_rqhat_sub(&raw mut fc, &raw mut f, (*in_0).c_ntt);
        lanes_rqhat_mul(&raw mut buf, &raw mut buf, &raw mut fc);
        lanes_rqhat_mul(
            &raw mut buf,
            (*in_0).alpha.offset(i as isize).offset(-((*in_0).m_alpha1 as isize)),
            &raw mut buf,
        );
        lanes_rqhat_add_nomodqhat(&raw mut f_sum, &raw mut buf, &raw mut f_sum);
        i = i.wrapping_add(1);
    }
    lanes_rqhat_inner_product_nomodqhat_b(
        &raw mut f,
        &raw const *(*in_0)
            .b
            .offset((6 as ::core::ffi::c_int + 1 as ::core::ffi::c_int) as isize)
            as *const LANES_Rqhat,
        (*in_0).z_ntt,
        (6 as ::core::ffi::c_int + 1 as ::core::ffi::c_int) as size_t,
    );
    lanes_rqhat_mul(&raw mut buf, (*in_0).c_ntt, (*in_0).tN);
    i = 0 as size_t;
    while i < 128 as size_t {
        f_sum.poly[i as usize] = lanes_modqhat(
            ((f_sum.poly[i as usize] + f.poly[i as usize]) as uint64_t)
                .wrapping_add(lanes_qhat)
                .wrapping_sub(buf.poly[i as usize] as uint64_t),
        ) as int64_t;
        i = i.wrapping_add(1);
    }
    if check_rqhat_equal(&raw mut f_sum, (*in_0).v) == 0 {
        return 0 as ::core::ffi::c_int;
    }
    return 1 as ::core::ffi::c_int;
}