package digestif

  1. Overview
  2. Docs

Source file digestif_eq.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 1 "default/lib/digestif/digestif_eq.ml"
module Make (D : sig val digest_size : int end) = struct

  (* XXX(dinosaure): these functions are implemented (instead to use common
     functions) to avoid timing attacks. So if you want to update this code, you
     need to take care about some assumptions. *)

  let eq a b =
    let ret = ref 0 in
    for i = 0 to D.digest_size - 1
    do ret := !ret lor ((Char.code (String.get a i)) lxor (Char.code (String.get b i))) done;
    !ret <> 0

  let neq a b = not (eq a b)

  let unsafe_compare a b = String.compare a b
  external int_compare : int -> int -> int = "caml_int_compare"
  let compare a b = int_compare (Hashtbl.hash a) (Hashtbl.hash b)
end
OCaml

Innovation. Community. Security.