mldsa-native-rs 0.0.1-alpha.6

FFI bindings and optional wrapper for the mldsa-native ML-DSA implementation
Documentation
pub use generic_array::typenum::*;

/// Turn a sequence of bits into a typenum Unsigned.
///
/// Note that the macro argument is sequenced LSB -> MSB
///
/// # Usage
///
/// ```rustdoc_cannot_access_non-pub
/// // 13 (0b1101)
/// type U13 = u_from_bits!(1 0 1 1);
/// assert_eq!(U13::USIZE, 13);
/// ```
macro_rules! u_from_bits {
    () => { UTerm };
    (0 $($rest:tt)*) => { UInt<u_from_bits!($($rest)*), B0> };
    (1 $($rest:tt)*) => { UInt<u_from_bits!($($rest)*), B1> };
}

// 1312 (0b10100100000)
pub type U1312 = u_from_bits!(0 0 0 0 0 1 0 0 1 0 1);
// 1952 (0b11110100000)
pub type U1952 = u_from_bits!(0 0 0 0 0 1 0 1 1 1 1);
// 2420 (0b100101110100)
pub type U2420 = u_from_bits!(0 0 1 0 1 1 1 0 1 0 0 1);
// 2560 (0b101000000000)
pub type U2560 = u_from_bits!(0 0 0 0 0 0 0 0 0 1 0 1);
// 2592 (0b101000100000)
pub type U2592 = u_from_bits!(0 0 0 0 0 1 0 0 0 1 0 1);
// 3309 (0b110011101101)
pub type U3309 = u_from_bits!(1 0 1 1 0 1 1 1 0 0 1 1);
// 4032 (0b111111000000)
pub type U4032 = u_from_bits!(0 0 0 0 0 0 1 1 1 1 1 1);
// 4627 (0b1001000010011)
pub type U4627 = u_from_bits!(1 1 0 0 1 0 0 0 0 1 0 0 1);
// 4896 (0b1001100100000)
pub type U4896 = u_from_bits!(0 0 0 0 0 1 0 0 1 1 0 0 1);

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_custom_typenums() {
        assert_eq!(U1312::USIZE, 1312);
        assert_eq!(U1952::USIZE, 1952);
        assert_eq!(U2420::USIZE, 2420);
        assert_eq!(U2560::USIZE, 2560);
        assert_eq!(U2592::USIZE, 2592);
        assert_eq!(U3309::USIZE, 3309);
        assert_eq!(U4032::USIZE, 4032);
        assert_eq!(U4627::USIZE, 4627);
        assert_eq!(U4896::USIZE, 4896);
    }
}