[][src]Function sodiumoxide::utils::memcmp

pub fn memcmp(x: &[u8], y: &[u8]) -> bool

memcmp() returns true if x[0], x[1], ..., x[len-1] are the same as y[0], y[1], ..., y[len-1]. Otherwise it returns false.

This function is safe to use for secrets x[0], x[1], ..., x[len-1], y[0], y[1], ..., y[len-1]. The time taken by memcmp is independent of the contents of x[0], x[1], ..., x[len-1], y[0], y[1], ..., y[len-1]. In contrast, the standard C comparison function memcmp(x,y,len) takes time that depends on the longest matching prefix of x and y, often allowing easy timing attacks.