@@ -96,6 +96,37 @@ pub fn byte_is_nonzero(b: u8) -> u8 {
96
96
97
97
/// Check equality of two 32-byte arrays in constant time.
98
98
///
99
+ /// If the contents of the arrays do *not* match,
100
+ /// `0u8` will be returned:
101
+ ///
102
+ /// ```
103
+ /// # extern crate curve25519_dalek;
104
+ /// # use curve25519_dalek::subtle::arrays_equal_ct;
105
+ /// # fn main() {
106
+ /// let a: [u8; 3] = [0, 1, 2];
107
+ /// let b: [u8; 3] = [1, 2, 3];
108
+ ///
109
+ /// assert!(arrays_equal_ct(&a, &b) == 0);
110
+ /// # }
111
+ /// ```
112
+ ///
113
+ /// If the contents *do* match, `1u8` is returned:
114
+ ///
115
+ /// ```
116
+ /// # extern crate curve25519_dalek;
117
+ /// # use curve25519_dalek::subtle::arrays_equal_ct;
118
+ /// # fn main() {
119
+ /// let a: [u8; 3] = [0, 1, 2];
120
+ /// let b: [u8; 3] = [0, 1, 2];
121
+ ///
122
+ /// assert!(arrays_equal_ct(&a, &b) == 1);
123
+ /// # }
124
+ /// ```
125
+ ///
126
+ /// This function is commonly used in various cryptographic applications, such
127
+ /// as [signature verification](https://github.com/isislovecruft/ed25519-dalek/blob/0.3.2/src/ed25519.rs#L280),
128
+ /// among many other applications.
129
+ ///
99
130
/// # Return
100
131
///
101
132
/// Returns `1u8` if `a == b` and `0u8` otherwise.
0 commit comments