rind 0.1.2

Pure-Rust cryptography for MoQ, forked from graviola
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Written for Graviola by Joe Birr-Pixton, 2024.
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT-0

use crate::low::ct_compare_bytes;

pub(crate) fn ct_equal(a: &[u8], b: &[u8]) -> bool {
    if a.len() != b.len() {
        return false;
    }

    // SAFETY: prior code guarantees a.len() == b.len()
    let diff = unsafe { ct_compare_bytes(a.as_ptr(), b.as_ptr(), a.len()) };
    // The result stays secret: a caller that accepts or rejects on it
    // declassifies it, but ML-KEM's implicit rejection must not.
    diff == 0
}