Skip to content

Commit 350b9c3

Browse files
SalomeAlisya78isislovecruft
authored andcommitted
Better documentation for arrays_equal_ct.
1 parent 2224e09 commit 350b9c3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/subtle.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,37 @@ pub fn byte_is_nonzero(b: u8) -> u8 {
9696

9797
/// Check equality of two 32-byte arrays in constant time.
9898
///
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+
///
99130
/// # Return
100131
///
101132
/// Returns `1u8` if `a == b` and `0u8` otherwise.

0 commit comments

Comments
 (0)