<commit_before># Constant time memcmp() function

``` C
int cst_time_memcmp(const void *m1, const void *m2, size_t n)
```

The `cst_time_memcmp()` function return the result of a lexicographical 
comparison of the byte array `m1` and `m2`. The processing time is independed
of the byte values of `m1` and `m2`. It varies only with `n`. 

The `cst_time_memcmp()` function returns `0` when the `n` first bytes of `m1` and 
`m2` are equal. When the first different byte is found at index `k`, the function
returns `-1` when `m1[k] < m2[k]`, and `+1` when `m1[k] > m2[k]`. Appart from the 
comparision result, this function reveals nothing of thebyte arrays `m1` and `m2`.

The function returns also 0 when at least one of the following conditions is true.

- `n` is zero ;
- `m1` and `m2` are the same memory area ;
- `m1` is NULL ;
- `m2` is NULL.

## Table of content

  * [Algorithm](#algorithm)
  * [Alternate instructions](#alternate-instructions)
  * [The code](#the-code)
    * [Fastest implementation using subscipt](#fastest-implementation-using-subscipt)
    * [Fastest implementation using pointers](#fastest-implementation-using-pointers)
    * [Safest implementation using subscript](#safest-implementation-using-subscript)
    * [Safest implementation using pointers](#safest-implementation-using-pointers)
    * [Reference code from NetBSD](#reference-code-from-netbsd)
  * [Verification](#verification)
    * [Discussion](#discussion)
    * [Output of the program](#output-of-the-program)

## Algorithm

The following code illustrate the none constant time memcmp() algoritm's logic. 

``` C
int memcmp(const unsigned char *m1, const unsigned char *m1, size_t n) {
    size_t i;
    for (i = 0; i < n; ++i ) {<commit_msg>fix typo & formatting in introductory description<commit_after># Constant time memcmp() function

``` C
int cst_time_memcmp(const void *m1, const void *m2, size_t n)
```

The `cst_time_memcmp()` function return the result of a lexicographical 
comparison of the byte array `m1` and `m2`. The processing time is independed
of the byte values of `m1` and `m2`. It varies only with `n`. 

The `cst_time_memcmp()` function returns `0` when the `n` first bytes of `m1` and 
`m2` are equal. When the first different byte is found at index `k`, with `k < 0`, 
the function returns `-1` when `m1[k] < m2[k]`, and `+1` when `m1[k] > m2[k]`. 
Appart from the comparision result, this function reveals nothing of the byte 
arrays `m1` and `m2`.

The function returns also `0` when at least one of the following conditions is true.

- `n` is zero ;
- `m1` and `m2` are the same memory area ;
- `m1` is NULL ;
- `m2` is NULL.

## Table of content

  * [Algorithm](#algorithm)
  * [Alternate instructions](#alternate-instructions)
  * [The code](#the-code)
    * [Fastest implementation using subscipt](#fastest-implementation-using-subscipt)
    * [Fastest implementation using pointers](#fastest-implementation-using-pointers)
    * [Safest implementation using subscript](#safest-implementation-using-subscript)
    * [Safest implementation using pointers](#safest-implementation-using-pointers)
    * [Reference code from NetBSD](#reference-code-from-netbsd)
  * [Verification](#verification)
    * [Discussion](#discussion)
    * [Output of the program](#output-of-the-program)

## Algorithm

The following code illustrate the none constant time memcmp() algoritm's logic. 

``` C
int memcmp(const unsigned char *m1, const unsigned char *m1, size_t n) {
    size_t i;
    for (i = 0; i < n; ++i ) {
{'fraction_non_alphanumeric': 0.12233891569684928, 'fraction_numerical': 0.014476298609139937, 'mean_word_length': 4.33939393939394, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1479134', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1123, 'n_words': 411}