Skip to content

Replace ct_find_uint8 by Eqaf_cstruct.find_uint8 #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2020

Conversation

dinosaure
Copy link
Member

A fix of #23

@dinosaure dinosaure requested review from hannesm and cfcs April 17, 2020 10:35
@hannesm
Copy link
Member

hannesm commented Apr 17, 2020

this is fine, though:

  • CI fails (would you mind to look into this and fix it?)
  • can we remove the ct_find funcion from Uncommon, and have it in pk/common.ml or pk/rsa.ml (the only use-side)? <- I'm not keen to introduce dependencies in the main library

@hannesm
Copy link
Member

hannesm commented Apr 17, 2020

ah, the test failure (from https://pipelines.actions.githubusercontent.com/qoofUrGaI3vjbXV0l1nsaHtqOWUOy1R9qZ8Weal5PXKQiJlyok/_apis/pipelines/1/runs/28/signedlogcontent/11?urlExpires=2020-04-17T11%3A04%3A42.5829588Z&urlSigningMethod=HMACV1&urlSignature=yynvhHhYHHE%2Bp0YvoUktZOIeTSsKr2EZL95Ynsr2r%2B8%3D):

2020-04-17T10:40:09.1333537Z The following dependencies couldn't be met:
2020-04-17T10:40:09.1334251Z   - mirage-crypto -> eqaf >= 0.7
2020-04-17T10:40:09.1334503Z       no matching version

so, this will eventually solve itself (once the windows runner has a fresher opam repository!?)

@dinosaure
Copy link
Member Author

can we remove the ct_find funcion from Uncommon, and have it in pk/common.ml or pk/rsa.ml (the only use-side)? <- I'm not keen to introduce dependencies in the main library

It's done 👍.

@hannesm
Copy link
Member

hannesm commented Apr 17, 2020

thanks again, sorry for being picky, but I'd appreciate a function definition (a la let ct_find_uint8 ..) and avoid repeating the two lines multiple times :)

@hannesm
Copy link
Member

hannesm commented Apr 17, 2020

hmm, or not - I'm not sure anymore. why should select_int be used instead of Option.get?

@dinosaure
Copy link
Member Author

dinosaure commented Apr 17, 2020

hmm, or not - I'm not sure anymore. why should select_int be used instead of Option.get?

select_int is checked as a constant-time way to simulate a branch (like if a then b else c). I use it to replace Option.get which needs an allocation (and may be delay the computation). Finally, we an assert that:

let res = Eqaf.find_uint8 ... in
let v = Eqaf.select_int (res - 1) default res in

Is constant-time where:

let res = Eqaf.find_uint8 ... in
let res = if res = (-1) then None else Some res in
let v = Option.get ~def res in

is not. Instead, we can implement a ct_find_uint8 : default:int -> ?off:int -> f:(int -> bool) -> Cstruct.t -> int which uses select_int - then, it will be a one-liner where find_uint8 is used.

@hannesm
Copy link
Member

hannesm commented Apr 17, 2020

@dinosaure thanks for your answer. yes, I'd appreciate a find_uint8 that takes a default: argument instead of returning -1 (which is slightly surprising in a typed OCaml world). maybe worth to do and cut a 0.7.1 or 0.8.0 release of eqaf?

@hannesm
Copy link
Member

hannesm commented Apr 17, 2020

oh, another way to move here is: develop such a find_uint8 ~default: locally in rsa and use this at the three locations. :)

@dinosaure
Copy link
Member Author

returning -1 (which is slightly surprising in a typed OCaml world)

Yes, it's mostly due to the limitation to avoid any call to the GC in your eqaf's codebase.

maybe worth to do and cut a 0.7.1 or 0.8.0 release of eqaf?

Sure, may be today, or this week 👍.

@dinosaure
Copy link
Member Author

oh, another way to move here is: develop such a find_uint8 ~default: locally in rsa and use this at the three locations. :)

Done in this way 👍 into my last commit. Should I rebase?

Copy link
Member

@hannesm hannesm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine to me, can be squashed and merged into a single commit when CI passes

mirage-crypto-pk depends on >= eqaf.0.7
@hannesm hannesm merged commit 3a8bd5d into mirage:master Apr 17, 2020
@hannesm
Copy link
Member

hannesm commented Apr 17, 2020

thanks, merged. the CI failures (on windows) are lacking the eqaf 0.7 release in opam-repository-mingw (that will eventually appear at some point) ;the OCaml-CI has an update cycle of "around a week" (there's discussion on ocurrent/ocaml-ci#26 about ways out -- no, embedding submodules into this repository won't happen, sorry).

since we use a variety of CI systems, we still have some that test this PR successfully :)

@hannesm hannesm mentioned this pull request Apr 17, 2020
hannesm added a commit to hannesm/opam-repository that referenced this pull request May 18, 2020
…0.7.0)

CHANGES:

* CPU feature detection (AESNI, SSE3, PCLMULQ) at runtime instead of compile
  time (mirage/mirage-crypto#53 @Julow, fixed MirageOS support mirage/mirage-crypto#61, review by @hannesm)
  performance hit up to 5%
* Revise entropy collection (mirage/mirage-crypto#64 @hannesm review by @dinosaure @cfcs)
  mirage-crypto-entropy has been folded into mirage-crypto-rng.{unix,lwt,mirage}
  - the RNG is no longer fork() safe, if you use fork in your code, be sure to
    reseed the RNG in the child process
  - on Unix and Lwt, the used RNG is Fortuna, seeded by getrandom(),
    rdrand/rdseed, and whirlwind
  - Mirage_crypto_rng_lwt does entropy collection for Lwt applications
  - entropy collection is now similar to FreeBSD:
    - rdrand/rdseed is executed in a separate task (by default every second)
    - on Unix, getrandom() is executed in another separate task (by default
      every 10 seconds)
    - on every enter of the Lwt event loop, some bits of rdtsc are collected
      (rdrand/rdseed is not on each even loop enter anymore)
  - Fortuna only uses entropy pools if the given period is exhausted (defaults
    to 1s), and the pool size exceeds 64 bytes
  - The unseeded generator exception prints instructions how to seed the RNG
* 32 bit support (for ghash), requested by @TImada in mirage/mirage-crypto#60, mirage/mirage-crypto#65 @hannesm
* use Eqaf_cstruct.find_uint8 instead of Cs.ct_find_uint8 (mirage/mirage-crypto#52 @dinosaure)
* add (:standard) in C flags to allow cross-compilation mirage/mirage-crypto#47 @samoht
* Mirage_crypto.Uncommon: remove several functions (Cs.create, Option),
  requires OCaml 4.08 (mirage/mirage-crypto#49 mirage/mirage-crypto#51 @hannesm)
* remove ocplib-endian dependency, use Bytes directly (since 4.07) mirage/mirage-crypto#51 @hannesm
* bitfn.h cleanup (mirage/mirage-crypto#56 mirage/mirage-crypto#58 @hannesm)
* fix build if opam is not available (mirage/mirage-crypto#66 @hannesm)
* update test.yml GitHub actions (mirage/mirage-crypto#44 mirage/mirage-crypto#57 @imbsky)
* Travis CI for arm64 (mirage/mirage-crypto#55 @hannesm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants