mirage / mirage-crypto

Cryptographic primitives for OCaml, in OCaml (also used in MirageOS)
ISC License
77 stars 43 forks source link

[dkml] mirage-crypto-ec issues #201

Open hannesm opened 9 months ago

hannesm commented 9 months ago

On DKML windows, the mirage-crypto-ec bits and pieces may build, but do not succeed the test cases.

They use the 32bit fiat-crypto implementations due to unavailability of 128bit integers on windows (see https://github.com/mirage/mirage-crypto/pull/137#issue-980006821, patch merged at https://github.com/mirage/mirage-crypto/commit/839558eb2757ed4bdf8e86d4722ee538c14ae5ad#diff-9616d1c991b5ef59f4bdb173cb3e439bdaf24a6088fb4e91b6a66ea0e29e5bf9).

Now, there's a patch https://github.com/hannesm/mirage-crypto/commit/5c46f2cedcf067940e78de888014e8246e22a4ef to also use the 32bit tables (otherwise compilation fails with "Cannot use 32-bit tables on a 64-bit architecture".

Even with that patch included, the tests fail:

File "tests/dune", line 60, characters 7-25:
60 |  (name test_ec_wycheproof)
            ^^^^^^^^^^^^^^^^^^
(cd _build/default/tests && ./test_ec_wycheproof.exe)
Fatal error: exception File "tests/test_ec_wycheproof.ml", line 418, characters 4-10: Assertion failed

It is not entirely clear to me, why, though. The assetion in question:

let to_ed25519_keys (key : eddsa_key) =
  let priv_cs = Cstruct.of_string key.sk
  and pub_cs = Cstruct.of_string key.pk
  in
  match Ed25519.priv_of_cstruct priv_cs, Ed25519.pub_of_cstruct pub_cs with
  | Ok priv, Ok pub ->
    assert (Cstruct.equal Ed25519.(pub_to_cstruct (pub_of_priv priv)) pub_cs); (* that's the failing one *)
    priv, pub
  | _ -> assert false

It may be useful to do some printf debugging here. The OCaml side for a DKML-windows-64bit assumes word_size being 64 bit, the C side assumes 32 - this may be an issue!?

Once address, in ci/build-test.sh the mirage-crypto-ec package can be added to the packages_TOPOLOGICALSORT.