cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Construction of a [`U512`] from eight little-endian `u64` limbs.
use super::U512;

impl U512 {
    /// Creates a new [`U512`] from an eight-element array of `u64` limbs in
    /// little-endian order: `[w0, w1, w2, w3, w4, w5, w6, w7]` where `w0`
    /// is the least significant and `w7` is the most significant.
    ///
    /// Since the internal layout is already little-endian, the array is
    /// stored directly without reversal. This is the inverse of
    /// [`U512::to_le_limbs`].
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u512::U512;
    ///
    /// let value = U512::from_le_limbs([42, 0, 0, 0, 0, 0, 0, 0]);
    /// assert_eq!(value, U512::from_be_limbs([0, 0, 0, 0, 0, 0, 0, 42]));
    /// ```
    #[inline]
    pub const fn from_le_limbs(value: [u64; 8]) -> Self {
        Self(value)
    }
}

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

    /// Constructing from eight zeros yields a zero value.
    #[test]
    fn zero() {
        assert_eq!(U512::from_le_limbs([0; 8]), U512::ZERO);
    }

    /// LE limb order is the reverse of BE limb order.
    #[test]
    fn reverse_of_be() {
        let le = U512::from_le_limbs([8, 7, 6, 5, 4, 3, 2, 1]);
        let be = U512::from_be_limbs([1, 2, 3, 4, 5, 6, 7, 8]);
        assert_eq!(le, be);
    }

    /// Maximum value fills all eight limbs.
    #[test]
    fn max_value() {
        assert_eq!(U512::from_le_limbs([u64::MAX; 8]), U512::MAX);
    }

    /// Round-trip with to_le_limbs.
    #[test]
    fn round_trip() {
        let limbs = [0xDEAD, 0xBEEF, 0xCAFE, 0xBABE, 0x42, 0xFF, 0x99, 0x11];
        assert_eq!(U512::from_le_limbs(limbs).to_le_limbs(), limbs);
    }
}