cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Returns the eight `u64` limbs in big-endian order.
use super::U512;

impl U512 {
    /// Returns the eight `u64` limbs in big-endian order.
    ///
    /// The returned array is `[w0, w1, w2, w3, w4, w5, w6, w7]` where `w0`
    /// is the most significant limb and `w7` is the least significant limb.
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u512::U512;
    ///
    /// let v = U512::from_be_limbs([1, 2, 3, 4, 5, 6, 7, 8]);
    /// assert_eq!(v.to_be_limbs(), [1, 2, 3, 4, 5, 6, 7, 8]);
    /// ```
    #[inline]
    pub const fn to_be_limbs(&self) -> [u64; 8] {
        [self.0[7], self.0[6], self.0[5], self.0[4], self.0[3], self.0[2], self.0[1], self.0[0]]
    }
}

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

    /// Round-trip: from_be_limbs then to_be_limbs returns the original array.
    #[test]
    fn round_trip() {
        let arr = [0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11];
        assert_eq!(U512::from_be_limbs(arr).to_be_limbs(), arr);
    }

    /// Zero round-trip.
    #[test]
    fn zero_round_trip() {
        assert_eq!(U512::from_be_limbs([0; 8]).to_be_limbs(), [0; 8]);
    }
}